|
@@ -2023,6 +2023,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private ServerAuthenticationEntryPoint entryPoint;
|
|
|
|
|
|
+ private ServerAuthenticationFailureHandler authenticationFailureHandler;
|
|
|
+
|
|
|
private HttpBasicSpec() {
|
|
|
List<DelegateEntry> entryPoints = new ArrayList<>();
|
|
|
entryPoints
|
|
@@ -2071,6 +2073,13 @@ public class ServerHttpSecurity {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public HttpBasicSpec authenticationFailureHandler(
|
|
|
+ ServerAuthenticationFailureHandler authenticationFailureHandler) {
|
|
|
+ Assert.notNull(authenticationFailureHandler, "authenticationFailureHandler cannot be null");
|
|
|
+ this.authenticationFailureHandler = authenticationFailureHandler;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Allows method chaining to continue configuring the {@link ServerHttpSecurity}
|
|
|
* @return the {@link ServerHttpSecurity} to continue configuring
|
|
@@ -2102,13 +2111,19 @@ public class ServerHttpSecurity {
|
|
|
Arrays.asList(this.xhrMatcher, restNotHtmlMatcher));
|
|
|
ServerHttpSecurity.this.defaultEntryPoints.add(new DelegateEntry(preferredMatcher, this.entryPoint));
|
|
|
AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(this.authenticationManager);
|
|
|
- authenticationFilter
|
|
|
- .setAuthenticationFailureHandler(new ServerAuthenticationEntryPointFailureHandler(this.entryPoint));
|
|
|
+ authenticationFilter.setAuthenticationFailureHandler(authenticationFailureHandler());
|
|
|
authenticationFilter.setAuthenticationConverter(new ServerHttpBasicAuthenticationConverter());
|
|
|
authenticationFilter.setSecurityContextRepository(this.securityContextRepository);
|
|
|
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.HTTP_BASIC);
|
|
|
}
|
|
|
|
|
|
+ private ServerAuthenticationFailureHandler authenticationFailureHandler() {
|
|
|
+ if (this.authenticationFailureHandler != null) {
|
|
|
+ return this.authenticationFailureHandler;
|
|
|
+ }
|
|
|
+ return new ServerAuthenticationEntryPointFailureHandler(this.entryPoint);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -3996,6 +4011,8 @@ public class ServerHttpSecurity {
|
|
|
|
|
|
private ServerAuthenticationEntryPoint entryPoint = new BearerTokenServerAuthenticationEntryPoint();
|
|
|
|
|
|
+ private ServerAuthenticationFailureHandler authenticationFailureHandler;
|
|
|
+
|
|
|
private ServerAccessDeniedHandler accessDeniedHandler = new BearerTokenServerAccessDeniedHandler();
|
|
|
|
|
|
private ServerAuthenticationConverter bearerTokenConverter = new ServerBearerTokenAuthenticationConverter();
|
|
@@ -4038,6 +4055,12 @@ public class ServerHttpSecurity {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public OAuth2ResourceServerSpec authenticationFailureHandler(
|
|
|
+ ServerAuthenticationFailureHandler authenticationFailureHandler) {
|
|
|
+ this.authenticationFailureHandler = authenticationFailureHandler;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Configures the {@link ServerAuthenticationConverter} to use for requests
|
|
|
* authenticating with
|
|
@@ -4127,8 +4150,7 @@ public class ServerHttpSecurity {
|
|
|
if (this.authenticationManagerResolver != null) {
|
|
|
AuthenticationWebFilter oauth2 = new AuthenticationWebFilter(this.authenticationManagerResolver);
|
|
|
oauth2.setServerAuthenticationConverter(this.bearerTokenConverter);
|
|
|
- oauth2.setAuthenticationFailureHandler(
|
|
|
- new ServerAuthenticationEntryPointFailureHandler(this.entryPoint));
|
|
|
+ oauth2.setAuthenticationFailureHandler(authenticationFailureHandler());
|
|
|
http.addFilterAt(oauth2, SecurityWebFiltersOrder.AUTHENTICATION);
|
|
|
}
|
|
|
else if (this.jwt != null) {
|
|
@@ -4181,6 +4203,13 @@ public class ServerHttpSecurity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private ServerAuthenticationFailureHandler authenticationFailureHandler() {
|
|
|
+ if (this.authenticationFailureHandler != null) {
|
|
|
+ return this.authenticationFailureHandler;
|
|
|
+ }
|
|
|
+ return new ServerAuthenticationEntryPointFailureHandler(this.entryPoint);
|
|
|
+ }
|
|
|
+
|
|
|
public ServerHttpSecurity and() {
|
|
|
return ServerHttpSecurity.this;
|
|
|
}
|
|
@@ -4262,8 +4291,7 @@ public class ServerHttpSecurity {
|
|
|
ReactiveAuthenticationManager authenticationManager = getAuthenticationManager();
|
|
|
AuthenticationWebFilter oauth2 = new AuthenticationWebFilter(authenticationManager);
|
|
|
oauth2.setServerAuthenticationConverter(OAuth2ResourceServerSpec.this.bearerTokenConverter);
|
|
|
- oauth2.setAuthenticationFailureHandler(
|
|
|
- new ServerAuthenticationEntryPointFailureHandler(OAuth2ResourceServerSpec.this.entryPoint));
|
|
|
+ oauth2.setAuthenticationFailureHandler(authenticationFailureHandler());
|
|
|
http.addFilterAt(oauth2, SecurityWebFiltersOrder.AUTHENTICATION);
|
|
|
}
|
|
|
|
|
@@ -4398,8 +4426,7 @@ public class ServerHttpSecurity {
|
|
|
ReactiveAuthenticationManager authenticationManager = getAuthenticationManager();
|
|
|
AuthenticationWebFilter oauth2 = new AuthenticationWebFilter(authenticationManager);
|
|
|
oauth2.setServerAuthenticationConverter(OAuth2ResourceServerSpec.this.bearerTokenConverter);
|
|
|
- oauth2.setAuthenticationFailureHandler(
|
|
|
- new ServerAuthenticationEntryPointFailureHandler(OAuth2ResourceServerSpec.this.entryPoint));
|
|
|
+ oauth2.setAuthenticationFailureHandler(authenticationFailureHandler());
|
|
|
http.addFilterAt(oauth2, SecurityWebFiltersOrder.AUTHENTICATION);
|
|
|
}
|
|
|
|