AuthenticationEntryPoint->ServerAuthenticationEntryPoint

Issue gh-4615
This commit is contained in:
Rob Winch 2017-10-10 13:32:51 -05:00
parent 8d4a73cf3f
commit cfc5572b7a
15 changed files with 83 additions and 81 deletions

View File

@ -24,8 +24,8 @@ import org.springframework.security.authorization.AuthenticatedReactiveAuthoriza
import org.springframework.security.authorization.AuthorityReactiveAuthorizationManager;
import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.authorization.ReactiveAuthorizationManager;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.DelegatingAuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint;
import org.springframework.security.web.server.ServerFormLoginAuthenticationConverter;
import org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter;
import org.springframework.security.web.server.MatcherSecurityWebFilterChain;
@ -33,12 +33,12 @@ import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.authentication.AuthenticationEntryPointFailureHandler;
import org.springframework.security.web.server.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import org.springframework.security.web.server.authentication.RedirectAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.RedirectAuthenticationSuccessHandler;
import org.springframework.security.web.server.authentication.logout.LogoutHandler;
import org.springframework.security.web.server.authentication.logout.LogoutWebFilter;
import org.springframework.security.web.server.authentication.logout.SecurityContextRepositoryLogoutHandler;
import org.springframework.security.web.server.authentication.www.HttpBasicAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.www.HttpBasicServerAuthenticationEntryPoint;
import org.springframework.security.web.server.authorization.AuthorizationContext;
import org.springframework.security.web.server.authorization.AuthorizationWebFilter;
import org.springframework.security.web.server.authorization.DelegatingReactiveAuthorizationManager;
@ -73,7 +73,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.springframework.security.web.server.DelegatingAuthenticationEntryPoint.DelegateEntry;
import static org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint.DelegateEntry;
/**
* @author Rob Winch
@ -96,7 +96,7 @@ public class HttpSecurity {
private SecurityContextRepository securityContextRepository;
private AuthenticationEntryPoint authenticationEntryPoint;
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
private List<DelegateEntry> defaultEntryPoints = new ArrayList<>();
@ -193,7 +193,7 @@ public class HttpSecurity {
if(this.securityContextRepository != null) {
this.formLogin.securityContextRepository(this.securityContextRepository);
}
if(this.formLogin.authenticationEntryPoint == null) {
if(this.formLogin.serverAuthenticationEntryPoint == null) {
this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder()));
}
this.formLogin.configure(this);
@ -203,10 +203,11 @@ public class HttpSecurity {
}
this.addFilterAt(new AuthenticationReactorContextFilter(), SecurityWebFiltersOrder.AUTHENTICATION_CONTEXT);
if(this.authorizeExchangeBuilder != null) {
AuthenticationEntryPoint authenticationEntryPoint = getAuthenticationEntryPoint();
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = getServerAuthenticationEntryPoint();
ExceptionTranslationWebFilter exceptionTranslationWebFilter = new ExceptionTranslationWebFilter();
if(authenticationEntryPoint != null) {
exceptionTranslationWebFilter.setAuthenticationEntryPoint(authenticationEntryPoint);
if(serverAuthenticationEntryPoint != null) {
exceptionTranslationWebFilter.setServerAuthenticationEntryPoint(
serverAuthenticationEntryPoint);
}
this.addFilterAt(exceptionTranslationWebFilter, SecurityWebFiltersOrder.EXCEPTION_TRANSLATION);
this.authorizeExchangeBuilder.configure(this);
@ -215,14 +216,14 @@ public class HttpSecurity {
return new MatcherSecurityWebFilterChain(getSecurityMatcher(), this.webFilters);
}
private AuthenticationEntryPoint getAuthenticationEntryPoint() {
if(this.authenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) {
return this.authenticationEntryPoint;
private ServerAuthenticationEntryPoint getServerAuthenticationEntryPoint() {
if(this.serverAuthenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) {
return this.serverAuthenticationEntryPoint;
}
if(this.defaultEntryPoints.size() == 1) {
return this.defaultEntryPoints.get(0).getEntryPoint();
}
DelegatingAuthenticationEntryPoint result = new DelegatingAuthenticationEntryPoint(this.defaultEntryPoints);
DelegatingServerAuthenticationEntryPoint result = new DelegatingServerAuthenticationEntryPoint(this.defaultEntryPoints);
result.setDefaultEntryPoint(this.defaultEntryPoints.get(this.defaultEntryPoints.size() - 1).getEntryPoint());
return result;
}
@ -323,7 +324,7 @@ public class HttpSecurity {
private SecurityContextRepository securityContextRepository = new ServerWebExchangeAttributeSecurityContextRepository();
private AuthenticationEntryPoint entryPoint = new HttpBasicAuthenticationEntryPoint();
private ServerAuthenticationEntryPoint entryPoint = new HttpBasicServerAuthenticationEntryPoint();
public HttpBasicBuilder authenticationManager(ReactiveAuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
@ -374,7 +375,7 @@ public class HttpSecurity {
private SecurityContextRepository securityContextRepository = new WebSessionSecurityContextRepository();
private AuthenticationEntryPoint authenticationEntryPoint;
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
private ServerWebExchangeMatcher requiresAuthenticationMatcher;
@ -386,14 +387,14 @@ public class HttpSecurity {
}
public FormLoginBuilder loginPage(String loginPage) {
this.authenticationEntryPoint = new RedirectAuthenticationEntryPoint(loginPage);
this.serverAuthenticationEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage);
this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage);
this.authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new RedirectAuthenticationEntryPoint(loginPage + "?error"));
this.authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new RedirectServerAuthenticationEntryPoint(loginPage + "?error"));
return this;
}
public FormLoginBuilder authenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint) {
this.authenticationEntryPoint = authenticationEntryPoint;
public FormLoginBuilder authenticationEntryPoint(ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
return this;
}
@ -422,13 +423,13 @@ public class HttpSecurity {
}
protected void configure(HttpSecurity http) {
if(this.authenticationEntryPoint == null) {
if(this.serverAuthenticationEntryPoint == null) {
loginPage("/login");
}
MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher(
MediaType.TEXT_HTML);
htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
HttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.authenticationEntryPoint));
HttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.serverAuthenticationEntryPoint));
AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter(
this.authenticationManager);
authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher);

View File

@ -31,20 +31,21 @@ import java.util.List;
* @author Rob Winch
* @since 5.0
*/
public class DelegatingAuthenticationEntryPoint implements AuthenticationEntryPoint {
public class DelegatingServerAuthenticationEntryPoint
implements ServerAuthenticationEntryPoint {
private final Flux<DelegateEntry> entryPoints;
private AuthenticationEntryPoint defaultEntryPoint = (exchange, e) -> {
private ServerAuthenticationEntryPoint defaultEntryPoint = (exchange, e) -> {
exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
return exchange.getResponse().setComplete();
};
public DelegatingAuthenticationEntryPoint(
public DelegatingServerAuthenticationEntryPoint(
DelegateEntry... entryPoints) {
this(Arrays.asList(entryPoints));
}
public DelegatingAuthenticationEntryPoint(
public DelegatingServerAuthenticationEntryPoint(
List<DelegateEntry> entryPoints) {
this.entryPoints = Flux.fromIterable(entryPoints);
}
@ -68,16 +69,16 @@ public class DelegatingAuthenticationEntryPoint implements AuthenticationEntryPo
* EntryPoint which is used when no RequestMatcher returned true
*/
public void setDefaultEntryPoint(
AuthenticationEntryPoint defaultEntryPoint) {
ServerAuthenticationEntryPoint defaultEntryPoint) {
this.defaultEntryPoint = defaultEntryPoint;
}
public static class DelegateEntry {
private final ServerWebExchangeMatcher matcher;
private final AuthenticationEntryPoint entryPoint;
private final ServerAuthenticationEntryPoint entryPoint;
public DelegateEntry(ServerWebExchangeMatcher matcher,
AuthenticationEntryPoint entryPoint) {
ServerAuthenticationEntryPoint entryPoint) {
this.matcher = matcher;
this.entryPoint = entryPoint;
}
@ -86,7 +87,7 @@ public class DelegatingAuthenticationEntryPoint implements AuthenticationEntryPo
return this.matcher;
}
public AuthenticationEntryPoint getEntryPoint() {
public ServerAuthenticationEntryPoint getEntryPoint() {
return this.entryPoint;
}
}

View File

@ -25,7 +25,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Rob Winch
* @since 5.0
*/
public interface AuthenticationEntryPoint {
public interface ServerAuthenticationEntryPoint {
Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e);
}

View File

@ -17,7 +17,7 @@
package org.springframework.security.web.server.authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.util.Assert;
import reactor.core.publisher.Mono;
@ -27,17 +27,18 @@ import reactor.core.publisher.Mono;
* @since 5.0
*/
public class AuthenticationEntryPointFailureHandler implements AuthenticationFailureHandler {
private final AuthenticationEntryPoint authenticationEntryPoint;
private final ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
public AuthenticationEntryPointFailureHandler(
AuthenticationEntryPoint authenticationEntryPoint) {
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null");
this.authenticationEntryPoint = authenticationEntryPoint;
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null");
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
}
@Override
public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange,
AuthenticationException exception) {
return this.authenticationEntryPoint.commence(webFilterExchange.getExchange(), exception);
return this.serverAuthenticationEntryPoint
.commence(webFilterExchange.getExchange(), exception);
}
}

View File

@ -25,7 +25,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.security.web.server.ServerHttpBasicAuthenticationConverter;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.security.web.server.authentication.www.HttpBasicAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.www.HttpBasicServerAuthenticationEntryPoint;
import org.springframework.security.web.server.context.SecurityContextRepository;
import org.springframework.security.web.server.context.SecurityContextRepositoryServerWebExchange;
import org.springframework.security.web.server.context.ServerWebExchangeAttributeSecurityContextRepository;
@ -49,7 +49,7 @@ public class AuthenticationWebFilter implements WebFilter {
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter = new ServerHttpBasicAuthenticationConverter();
private AuthenticationFailureHandler authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new HttpBasicAuthenticationEntryPoint());
private AuthenticationFailureHandler authenticationFailureHandler = new AuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
private SecurityContextRepository securityContextRepository = new ServerWebExchangeAttributeSecurityContextRepository();

View File

@ -23,7 +23,7 @@ import org.springframework.security.web.server.ServerRedirectStrategy;
import reactor.core.publisher.Mono;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
@ -33,12 +33,13 @@ import org.springframework.web.server.ServerWebExchange;
* @author Rob Winch
* @since 5.0
*/
public class RedirectAuthenticationEntryPoint implements AuthenticationEntryPoint {
public class RedirectServerAuthenticationEntryPoint
implements ServerAuthenticationEntryPoint {
private final URI location;
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy();
public RedirectAuthenticationEntryPoint(String location) {
public RedirectServerAuthenticationEntryPoint(String location) {
Assert.notNull(location, "location cannot be null");
this.location = URI.create(location);
}

View File

@ -18,7 +18,7 @@ package org.springframework.security.web.server.authentication.www;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
@ -29,7 +29,8 @@ import reactor.core.publisher.Mono;
* @author Rob Winch
* @since 5.0
*/
public class HttpBasicAuthenticationEntryPoint implements AuthenticationEntryPoint {
public class HttpBasicServerAuthenticationEntryPoint
implements ServerAuthenticationEntryPoint {
private static final String WWW_AUTHENTICATE = "WWW-Authenticate";
private static final String DEFAULT_REALM = "Realm";
private static String WWW_AUTHENTICATE_FORMAT = "Basic realm=\"%s\"";

View File

@ -17,9 +17,6 @@ package org.springframework.security.web.server.authorization;
import org.springframework.security.authorization.ReactiveAuthorizationManager;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.www.HttpBasicAuthenticationEntryPoint;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;

View File

@ -20,8 +20,8 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.www.HttpBasicAuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.www.HttpBasicServerAuthenticationEntryPoint;
import org.springframework.util.Assert;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
@ -33,7 +33,7 @@ import org.springframework.web.server.WebFilterChain;
* @since 5.0
*/
public class ExceptionTranslationWebFilter implements WebFilter {
private AuthenticationEntryPoint authenticationEntryPoint = new HttpBasicAuthenticationEntryPoint();
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint();
private AccessDeniedHandler accessDeniedHandler = new HttpStatusAccessDeniedHandler(HttpStatus.FORBIDDEN);
@ -58,17 +58,17 @@ public class ExceptionTranslationWebFilter implements WebFilter {
/**
* Sets the authentication entry point used when authentication is required
* @param authenticationEntryPoint the authentication entry point to use. Default is
* {@link HttpBasicAuthenticationEntryPoint}
* @param serverAuthenticationEntryPoint the authentication entry point to use. Default is
* {@link HttpBasicServerAuthenticationEntryPoint}
*/
public void setAuthenticationEntryPoint(
AuthenticationEntryPoint authenticationEntryPoint) {
Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null");
this.authenticationEntryPoint = authenticationEntryPoint;
public void setServerAuthenticationEntryPoint(
ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) {
Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null");
this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint;
}
private <T> Mono<T> commenceAuthentication(ServerWebExchange exchange, AccessDeniedException denied) {
return this.authenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied))
return this.serverAuthenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied))
.then(Mono.empty());
}
}

View File

@ -32,14 +32,14 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.springframework.security.web.server.DelegatingAuthenticationEntryPoint.*;
import static org.springframework.security.web.server.DelegatingServerAuthenticationEntryPoint.*;
/**
* @author Rob Winch
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class DelegatingAuthenticationEntryPointTests {
public class DelegatingServerAuthenticationEntryPointTests {
private ServerWebExchange exchange = MockServerHttpRequest.get("/").toExchange();
@Mock
@ -47,12 +47,12 @@ public class DelegatingAuthenticationEntryPointTests {
@Mock
private ServerWebExchangeMatcher matcher2;
@Mock
private AuthenticationEntryPoint delegate1;
private ServerAuthenticationEntryPoint delegate1;
@Mock
private AuthenticationEntryPoint delegate2;
private ServerAuthenticationEntryPoint delegate2;
private AuthenticationException e = new AuthenticationCredentialsNotFoundException("Log In");
private DelegatingAuthenticationEntryPoint entryPoint;
private DelegatingServerAuthenticationEntryPoint entryPoint;
@Test
public void commenceWhenNotMatchThenMatchThenOnlySecondDelegateInvoked() {
@ -62,7 +62,7 @@ public class DelegatingAuthenticationEntryPointTests {
when(this.matcher2.matches(this.exchange)).thenReturn(
ServerWebExchangeMatcher.MatchResult.match());
when(this.delegate2.commence(this.exchange, this.e)).thenReturn(expectedResult);
this.entryPoint = new DelegatingAuthenticationEntryPoint(
this.entryPoint = new DelegatingServerAuthenticationEntryPoint(
new DelegateEntry(this.matcher1, this.delegate1),
new DelegateEntry(this.matcher2, this.delegate2));
@ -78,7 +78,7 @@ public class DelegatingAuthenticationEntryPointTests {
public void commenceWhenNotMatchThenDefault() {
when(this.matcher1.matches(this.exchange)).thenReturn(
ServerWebExchangeMatcher.MatchResult.notMatch());
this.entryPoint = new DelegatingAuthenticationEntryPoint(
this.entryPoint = new DelegatingServerAuthenticationEntryPoint(
new DelegateEntry(this.matcher1, this.delegate1));
this.entryPoint.commence(this.exchange, this.e).block();

View File

@ -61,7 +61,7 @@ public class RedirectAuthenticationSuccessHandlerTests {
@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint((String) null);
}
@Test

View File

@ -39,7 +39,7 @@ import static org.mockito.Mockito.when;
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class RedirectAuthenticationEntryPointTests {
public class RedirectServerAuthenticationEntryPointTests {
@Mock
private ServerWebExchange exchange;
@ -48,15 +48,15 @@ public class RedirectAuthenticationEntryPointTests {
private String location = "/login";
private RedirectAuthenticationEntryPoint entryPoint =
new RedirectAuthenticationEntryPoint("/login");
private RedirectServerAuthenticationEntryPoint entryPoint =
new RedirectServerAuthenticationEntryPoint("/login");
private AuthenticationException exception = new AuthenticationCredentialsNotFoundException("Authentication Required");
@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {
new RedirectAuthenticationEntryPoint((String) null);
new RedirectServerAuthenticationEntryPoint((String) null);
}
@Test

View File

@ -24,7 +24,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import reactor.core.publisher.Mono;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
@ -37,9 +37,9 @@ import static org.mockito.Mockito.when;
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class AuthenticationEntryPointFailureHandlerTests {
public class ServerAuthenticationEntryPointFailureHandlerTests {
@Mock
private AuthenticationEntryPoint authenticationEntryPoint;
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
@Mock
private ServerWebExchange exchange;
@Mock
@ -53,15 +53,15 @@ public class AuthenticationEntryPointFailureHandlerTests {
@Test(expected = IllegalArgumentException.class)
public void constructorWhenNullEntryPointThenException() {
this.authenticationEntryPoint = null;
new AuthenticationEntryPointFailureHandler(this.authenticationEntryPoint);
this.serverAuthenticationEntryPoint = null;
new AuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint);
}
@Test
public void onAuthenticationFailureWhenInvokedThenDelegatesToEntryPoint() {
Mono<Void> result = Mono.empty();
BadCredentialsException e = new BadCredentialsException("Failed");
when(this.authenticationEntryPoint.commence(this.exchange, e)).thenReturn(result);
when(this.serverAuthenticationEntryPoint.commence(this.exchange, e)).thenReturn(result);
assertThat(this.handler.onAuthenticationFailure(this.filterExchange, e)).isEqualTo(result);
}

View File

@ -35,10 +35,10 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class HttpBasicAuthenticationEntryPointTests {
public class HttpBasicServerAuthenticationEntryPointTests {
@Mock
private ServerWebExchange exchange;
private HttpBasicAuthenticationEntryPoint entryPoint = new HttpBasicAuthenticationEntryPoint();
private HttpBasicServerAuthenticationEntryPoint entryPoint = new HttpBasicServerAuthenticationEntryPoint();
private AuthenticationException exception = new AuthenticationCredentialsNotFoundException("Authenticate");

View File

@ -30,7 +30,7 @@ import reactor.test.publisher.PublisherProbe;
import org.springframework.http.HttpStatus;
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.server.AuthenticationEntryPoint;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
@ -53,7 +53,7 @@ public class ExceptionTranslationWebFilterTests {
@Mock
private AccessDeniedHandler deniedHandler;
@Mock
private AuthenticationEntryPoint entryPoint;
private ServerAuthenticationEntryPoint entryPoint;
private PublisherProbe<Void> deniedPublisher = PublisherProbe.empty();
private PublisherProbe<Void> entryPointPublisher = PublisherProbe.empty();
@ -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.setAuthenticationEntryPoint(this.entryPoint);
this.filter.setServerAuthenticationEntryPoint(this.entryPoint);
this.filter.setAccessDeniedHandler(this.deniedHandler);
}
@ -155,6 +155,6 @@ public class ExceptionTranslationWebFilterTests {
@Test(expected = IllegalArgumentException.class)
public void setAuthenticationEntryPointWhenNullThenException() {
this.filter.setAuthenticationEntryPoint(null);
this.filter.setServerAuthenticationEntryPoint(null);
}
}