|
1 | 1 | package com.retailsvc.http.internal; |
2 | 2 |
|
| 3 | +import static java.net.HttpURLConnection.HTTP_FORBIDDEN; |
| 4 | +import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; |
| 5 | + |
3 | 6 | import com.retailsvc.http.Request; |
4 | 7 | import com.retailsvc.http.SchemeValidator; |
5 | 8 | import com.retailsvc.http.spec.Operation; |
@@ -109,7 +112,7 @@ private GroupOutcome tryGroup(SecurityRequirement group, HttpExchange exchange, |
109 | 112 | private void renderRejection(HttpExchange exchange, List<GroupOutcome.Failed> failures) |
110 | 113 | throws IOException { |
111 | 114 | boolean anyDenied = failures.stream().anyMatch(f -> f.kind() == FailureKind.DENIED); |
112 | | - int status = anyDenied ? 403 : 401; |
| 115 | + int status = anyDenied ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED; |
113 | 116 | String title = anyDenied ? "Forbidden" : "Unauthorized"; |
114 | 117 |
|
115 | 118 | GroupOutcome.Failed pick = |
@@ -146,12 +149,8 @@ private String challengeFor(String schemeName) { |
146 | 149 | return switch (scheme) { |
147 | 150 | case SecurityScheme.HttpBearer _ -> "Bearer realm=\"api\""; |
148 | 151 | case SecurityScheme.HttpBasic _ -> "Basic realm=\"api\""; |
149 | | - case SecurityScheme.ApiKey ak -> |
150 | | - "ApiKey location=" |
151 | | - + ak.location().name().toLowerCase(Locale.ROOT) |
152 | | - + ", name=\"" |
153 | | - + ak.name() |
154 | | - + "\""; |
| 152 | + case SecurityScheme.ApiKey(String name, SecurityScheme.ApiKey.Location location) -> |
| 153 | + "ApiKey location=" + location.name().toLowerCase(Locale.ROOT) + ", name=\"" + name + "\""; |
155 | 154 | case SecurityScheme.Unsupported _ -> |
156 | 155 | throw new IllegalStateException( |
157 | 156 | "Unsupported scheme reached challenge rendering for '" + schemeName + "'"); |
|
0 commit comments