mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-02-25 08:58:57 +00:00
serverAuthenticationEntryPoint->authenticationEntryPoint
Issue: gh-4822
This commit is contained in:
parent
9cf0dc6b38
commit
9e82fc0b83
@ -115,7 +115,7 @@ public class ServerHttpSecurity {
|
||||
|
||||
private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
|
||||
|
||||
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
|
||||
private ServerAuthenticationEntryPoint authenticationEntryPoint;
|
||||
|
||||
private List<DelegateEntry> defaultEntryPoints = new ArrayList<>();
|
||||
|
||||
@ -239,7 +239,7 @@ public class ServerHttpSecurity {
|
||||
if(this.securityContextRepository != null) {
|
||||
this.formLogin.securityContextRepository(this.securityContextRepository);
|
||||
}
|
||||
if(this.formLogin.serverAuthenticationEntryPoint == null) {
|
||||
if(this.formLogin.authenticationEntryPoint == null) {
|
||||
this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder()));
|
||||
this.webFilters.add(new OrderedWebFilter(new LogoutPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGOUT_PAGE_GENERATING.getOrder()));
|
||||
}
|
||||
@ -251,11 +251,11 @@ public class ServerHttpSecurity {
|
||||
this.requestCache.configure(this);
|
||||
this.addFilterAt(new SecurityContextServerWebExchangeWebFilter(), SecurityWebFiltersOrder.SECURITY_CONTEXT_SERVER_WEB_EXCHANGE);
|
||||
if(this.authorizeExchange != null) {
|
||||
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = getServerAuthenticationEntryPoint();
|
||||
ServerAuthenticationEntryPoint authenticationEntryPoint = getAuthenticationEntryPoint();
|
||||
ExceptionTranslationWebFilter exceptionTranslationWebFilter = new ExceptionTranslationWebFilter();
|
||||
if(serverAuthenticationEntryPoint != null) {
|
||||
exceptionTranslationWebFilter.setServerAuthenticationEntryPoint(
|
||||
serverAuthenticationEntryPoint);
|
||||
if(authenticationEntryPoint != null) {
|
||||
exceptionTranslationWebFilter.setAuthenticationEntryPoint(
|
||||
authenticationEntryPoint);
|
||||
}
|
||||
this.addFilterAt(exceptionTranslationWebFilter, SecurityWebFiltersOrder.EXCEPTION_TRANSLATION);
|
||||
this.authorizeExchange.configure(this);
|
||||
@ -286,9 +286,9 @@ public class ServerHttpSecurity {
|
||||
}
|
||||
}
|
||||
|
||||
private ServerAuthenticationEntryPoint getServerAuthenticationEntryPoint() {
|
||||
if(this.serverAuthenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) {
|
||||
return this.serverAuthenticationEntryPoint;
|
||||
private ServerAuthenticationEntryPoint getAuthenticationEntryPoint() {
|
||||
if(this.authenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) {
|
||||
return this.authenticationEntryPoint;
|
||||
}
|
||||
if(this.defaultEntryPoints.size() == 1) {
|
||||
return this.defaultEntryPoints.get(0).getEntryPoint();
|
||||
@ -432,8 +432,9 @@ public class ServerHttpSecurity {
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ExceptionHandlingSpec {
|
||||
public ExceptionHandlingSpec serverAuthenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) {
|
||||
ServerHttpSecurity.this.serverAuthenticationEntryPoint = authenticationEntryPoint;
|
||||
|
||||
public ExceptionHandlingSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) {
|
||||
ServerHttpSecurity.this.authenticationEntryPoint = authenticationEntryPoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -537,7 +538,7 @@ public class ServerHttpSecurity {
|
||||
|
||||
private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
|
||||
|
||||
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
|
||||
private ServerAuthenticationEntryPoint authenticationEntryPoint;
|
||||
|
||||
private ServerWebExchangeMatcher requiresAuthenticationMatcher;
|
||||
|
||||
@ -559,14 +560,14 @@ public class ServerHttpSecurity {
|
||||
|
||||
public FormLoginSpec loginPage(String loginPage) {
|
||||
this.defaultEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage);
|
||||
this.serverAuthenticationEntryPoint = this.defaultEntryPoint;
|
||||
this.authenticationEntryPoint = this.defaultEntryPoint;
|
||||
this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage);
|
||||
this.authenticationFailureHandler = new RedirectServerAuthenticationFailureHandler(loginPage + "?error");
|
||||
return this;
|
||||
}
|
||||
|
||||
public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
|
||||
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
|
||||
public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) {
|
||||
this.authenticationEntryPoint = authenticationEntryPoint;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -595,7 +596,7 @@ public class ServerHttpSecurity {
|
||||
}
|
||||
|
||||
protected void configure(ServerHttpSecurity http) {
|
||||
if(this.serverAuthenticationEntryPoint == null) {
|
||||
if(this.authenticationEntryPoint == null) {
|
||||
loginPage("/login");
|
||||
}
|
||||
if(http.requestCache != null) {
|
||||
@ -608,7 +609,7 @@ public class ServerHttpSecurity {
|
||||
MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher(
|
||||
MediaType.TEXT_HTML);
|
||||
htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
|
||||
ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.serverAuthenticationEntryPoint));
|
||||
ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.authenticationEntryPoint));
|
||||
AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(
|
||||
this.authenticationManager);
|
||||
authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher);
|
||||
|
@ -28,18 +28,18 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public class ServerAuthenticationEntryPointFailureHandler
|
||||
implements ServerAuthenticationFailureHandler {
|
||||
private final ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
|
||||
private final ServerAuthenticationEntryPoint authenticationEntryPoint;
|
||||
|
||||
public ServerAuthenticationEntryPointFailureHandler(
|
||||
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
|
||||
Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null");
|
||||
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
|
||||
ServerAuthenticationEntryPoint authenticationEntryPoint) {
|
||||
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null");
|
||||
this.authenticationEntryPoint = authenticationEntryPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange,
|
||||
AuthenticationException exception) {
|
||||
return this.serverAuthenticationEntryPoint
|
||||
return this.authenticationEntryPoint
|
||||
.commence(webFilterExchange.getExchange(), exception);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import org.springframework.web.server.WebFilterChain;
|
||||
* @since 5.0
|
||||
*/
|
||||
public class ExceptionTranslationWebFilter implements WebFilter {
|
||||
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint();
|
||||
private ServerAuthenticationEntryPoint authenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint();
|
||||
|
||||
private ServerAccessDeniedHandler serverAccessDeniedHandler = new HttpStatusServerAccessDeniedHandler(HttpStatus.FORBIDDEN);
|
||||
|
||||
@ -59,17 +59,17 @@ public class ExceptionTranslationWebFilter implements WebFilter {
|
||||
|
||||
/**
|
||||
* Sets the authentication entry point used when authentication is required
|
||||
* @param serverAuthenticationEntryPoint the authentication entry point to use. Default is
|
||||
* @param authenticationEntryPoint the authentication entry point to use. Default is
|
||||
* {@link HttpBasicServerAuthenticationEntryPoint}
|
||||
*/
|
||||
public void setServerAuthenticationEntryPoint(
|
||||
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
|
||||
Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null");
|
||||
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
|
||||
public void setAuthenticationEntryPoint(
|
||||
ServerAuthenticationEntryPoint authenticationEntryPoint) {
|
||||
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null");
|
||||
this.authenticationEntryPoint = authenticationEntryPoint;
|
||||
}
|
||||
|
||||
private <T> Mono<T> commenceAuthentication(ServerWebExchange exchange, AccessDeniedException denied) {
|
||||
return this.serverAuthenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied))
|
||||
return this.authenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied))
|
||||
.then(Mono.empty());
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ServerAuthenticationEntryPointFailureHandlerTests {
|
||||
@Mock
|
||||
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
|
||||
private ServerAuthenticationEntryPoint authenticationEntryPoint;
|
||||
@Mock
|
||||
private ServerWebExchange exchange;
|
||||
@Mock
|
||||
@ -53,15 +53,15 @@ public class ServerAuthenticationEntryPointFailureHandlerTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructorWhenNullEntryPointThenException() {
|
||||
this.serverAuthenticationEntryPoint = null;
|
||||
new ServerAuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint);
|
||||
this.authenticationEntryPoint = null;
|
||||
new ServerAuthenticationEntryPointFailureHandler(this.authenticationEntryPoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAuthenticationFailureWhenInvokedThenDelegatesToEntryPoint() {
|
||||
Mono<Void> result = Mono.empty();
|
||||
BadCredentialsException e = new BadCredentialsException("Failed");
|
||||
when(this.serverAuthenticationEntryPoint.commence(this.exchange, e)).thenReturn(result);
|
||||
when(this.authenticationEntryPoint.commence(this.exchange, e)).thenReturn(result);
|
||||
|
||||
assertThat(this.handler.onAuthenticationFailure(this.filterExchange, e)).isEqualTo(result);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class ExceptionTranslationWebFilterTests {
|
||||
when(this.deniedHandler.handle(any(), any())).thenReturn(this.deniedPublisher.mono());
|
||||
when(this.entryPoint.commence(any(), any())).thenReturn(this.entryPointPublisher.mono());
|
||||
|
||||
this.filter.setServerAuthenticationEntryPoint(this.entryPoint);
|
||||
this.filter.setAuthenticationEntryPoint(this.entryPoint);
|
||||
this.filter.setServerAccessDeniedHandler(this.deniedHandler);
|
||||
}
|
||||
|
||||
@ -155,6 +155,6 @@ public class ExceptionTranslationWebFilterTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void setAuthenticationEntryPointWhenNullThenException() {
|
||||
this.filter.setServerAuthenticationEntryPoint(null);
|
||||
this.filter.setAuthenticationEntryPoint(null);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user