|
27 | 27 | import org.springframework.context.event.GenericApplicationListenerAdapter;
|
28 | 28 | import org.springframework.context.event.SmartApplicationListener;
|
29 | 29 | import org.springframework.http.HttpMethod;
|
30 |
| -import org.springframework.http.HttpStatus; |
31 | 30 | import org.springframework.security.config.Customizer;
|
32 | 31 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
33 | 32 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
|
48 | 47 | import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
|
49 | 48 | import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenGenerator;
|
50 | 49 | import org.springframework.security.oauth2.server.authorization.web.NimbusJwkSetEndpointFilter;
|
51 |
| -import org.springframework.security.web.authentication.HttpStatusEntryPoint; |
52 | 50 | import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
|
| 51 | +import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; |
53 | 52 | import org.springframework.security.web.context.SecurityContextHolderFilter;
|
54 | 53 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
55 | 54 | import org.springframework.security.web.util.matcher.OrRequestMatcher;
|
@@ -87,6 +86,8 @@ public final class OAuth2AuthorizationServerConfigurer
|
87 | 86 |
|
88 | 87 | private RequestMatcher endpointsMatcher;
|
89 | 88 |
|
| 89 | + private String realm = "oauth2/client"; |
| 90 | + |
90 | 91 | /**
|
91 | 92 | * Returns a new instance of {@link OAuth2AuthorizationServerConfigurer} for
|
92 | 93 | * configuring.
|
@@ -277,6 +278,16 @@ public OAuth2AuthorizationServerConfigurer oidc(Customizer<OidcConfigurer> oidcC
|
277 | 278 | return this;
|
278 | 279 | }
|
279 | 280 |
|
| 281 | + /** |
| 282 | + * Configures the default realm value to be return in the WWW-Authenticate header |
| 283 | + * @param realm the authentication realm for this server |
| 284 | + * @return the {@link OAuth2AuthorizationServerConfigurer} for further configuration |
| 285 | + */ |
| 286 | + public OAuth2AuthorizationServerConfigurer realm(String realm) { |
| 287 | + this.realm = realm; |
| 288 | + return this; |
| 289 | + } |
| 290 | + |
280 | 291 | /**
|
281 | 292 | * Returns a {@link RequestMatcher} for the authorization server endpoints.
|
282 | 293 | * @return a {@link RequestMatcher} for the authorization server endpoints
|
@@ -344,7 +355,9 @@ public void init(HttpSecurity httpSecurity) throws Exception {
|
344 | 355 | ExceptionHandlingConfigurer<HttpSecurity> exceptionHandling = httpSecurity
|
345 | 356 | .getConfigurer(ExceptionHandlingConfigurer.class);
|
346 | 357 | if (exceptionHandling != null) {
|
347 |
| - exceptionHandling.defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED), |
| 358 | + var entryPoint = new BasicAuthenticationEntryPoint(); |
| 359 | + entryPoint.setRealmName(this.realm); |
| 360 | + exceptionHandling.defaultAuthenticationEntryPointFor(entryPoint, |
348 | 361 | new OrRequestMatcher(getRequestMatcher(OAuth2TokenEndpointConfigurer.class),
|
349 | 362 | getRequestMatcher(OAuth2TokenIntrospectionEndpointConfigurer.class),
|
350 | 363 | getRequestMatcher(OAuth2TokenRevocationEndpointConfigurer.class),
|
|
0 commit comments