AuthenticationSuccessHandler->ServerAuthenticationSuccessHandler

Issue gh-4615
This commit is contained in:
Rob Winch 2017-10-10 14:47:21 -05:00
parent b858985b0e
commit 2982b82b2d
7 changed files with 19 additions and 17 deletions

View File

@ -34,7 +34,7 @@ import org.springframework.security.web.server.authentication.AuthenticationEntr
import org.springframework.security.web.server.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationEntryPoint;
import org.springframework.security.web.server.authentication.RedirectAuthenticationSuccessHandler;
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;
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;
@ -435,7 +435,7 @@ public class HttpSecurity {
authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher);
authenticationFilter.setAuthenticationFailureHandler(this.authenticationFailureHandler);
authenticationFilter.setAuthenticationConverter(new ServerFormLoginAuthenticationConverter());
authenticationFilter.setAuthenticationSuccessHandler(new RedirectAuthenticationSuccessHandler("/"));
authenticationFilter.setServerAuthenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler("/"));
authenticationFilter.setSecurityContextServerRepository(this.securityContextServerRepository);
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.FORM_LOGIN);
}

View File

@ -45,7 +45,7 @@ public class AuthenticationWebFilter implements WebFilter {
private final ReactiveAuthenticationManager authenticationManager;
private AuthenticationSuccessHandler authenticationSuccessHandler = new WebFilterChainAuthenticationSuccessHandler();
private ServerAuthenticationSuccessHandler serverAuthenticationSuccessHandler = new WebFilterChainServerAuthenticationSuccessHandler();
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter = new ServerHttpBasicAuthenticationConverter();
@ -87,7 +87,8 @@ public class AuthenticationWebFilter implements WebFilter {
SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(authentication);
return this.securityContextServerRepository.save(exchange, securityContext)
.then(this.authenticationSuccessHandler.success(authentication, webFilterExchange));
.then(this.serverAuthenticationSuccessHandler
.success(authentication, webFilterExchange));
}
public void setSecurityContextServerRepository(
@ -96,8 +97,8 @@ public class AuthenticationWebFilter implements WebFilter {
this.securityContextServerRepository = securityContextServerRepository;
}
public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler authenticationSuccessHandler) {
this.authenticationSuccessHandler = authenticationSuccessHandler;
public void setServerAuthenticationSuccessHandler(ServerAuthenticationSuccessHandler serverAuthenticationSuccessHandler) {
this.serverAuthenticationSuccessHandler = serverAuthenticationSuccessHandler;
}
public void setAuthenticationConverter(Function<ServerWebExchange,Mono<Authentication>> authenticationConverter) {

View File

@ -30,14 +30,15 @@ import java.net.URI;
* @author Rob Winch
* @since 5.0
*/
public class RedirectAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
public class RedirectServerAuthenticationSuccessHandler
implements ServerAuthenticationSuccessHandler {
private URI location = URI.create("/");
private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy();
public RedirectAuthenticationSuccessHandler() {}
public RedirectServerAuthenticationSuccessHandler() {}
public RedirectAuthenticationSuccessHandler(String location) {
public RedirectServerAuthenticationSuccessHandler(String location) {
this.location = URI.create(location);
}

View File

@ -24,6 +24,6 @@ import reactor.core.publisher.Mono;
* @author Rob Winch
* @since 5.0
*/
public interface AuthenticationSuccessHandler {
public interface ServerAuthenticationSuccessHandler {
Mono<Void> success(Authentication authentication, WebFilterExchange webFilterExchange);
}

View File

@ -19,14 +19,14 @@ package org.springframework.security.web.server.authentication;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.server.WebFilterExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
/**
* @author Rob Winch
* @since 5.0
*/
public class WebFilterChainAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
public class WebFilterChainServerAuthenticationSuccessHandler
implements ServerAuthenticationSuccessHandler {
@Override
public Mono<Void> success(Authentication authentication, WebFilterExchange webFilterExchange) {
ServerWebExchange exchange = webFilterExchange.getExchange();

View File

@ -54,7 +54,7 @@ import static org.springframework.web.reactive.function.client.ExchangeFilterFun
@RunWith(MockitoJUnitRunner.class)
public class AuthenticationWebFilterTests {
@Mock
private AuthenticationSuccessHandler successHandler;
private ServerAuthenticationSuccessHandler successHandler;
@Mock
private Function<ServerWebExchange,Mono<Authentication>> authenticationConverter;
@Mock
@ -69,7 +69,7 @@ public class AuthenticationWebFilterTests {
@Before
public void setup() {
this.filter = new AuthenticationWebFilter(this.authenticationManager);
this.filter.setAuthenticationSuccessHandler(this.successHandler);
this.filter.setServerAuthenticationSuccessHandler(this.successHandler);
this.filter.setAuthenticationConverter(this.authenticationConverter);
this.filter.setSecurityContextServerRepository(this.securityContextServerRepository);
this.filter.setAuthenticationFailureHandler(this.failureHandler);

View File

@ -43,7 +43,7 @@ import static org.mockito.Mockito.when;
* @since 5.0
*/
@RunWith(MockitoJUnitRunner.class)
public class RedirectAuthenticationSuccessHandlerTests {
public class RedirectServerAuthenticationSuccessHandlerTests {
@Mock
private ServerWebExchange exchange;
@ -56,8 +56,8 @@ public class RedirectAuthenticationSuccessHandlerTests {
private URI location = URI.create("/");
private RedirectAuthenticationSuccessHandler handler =
new RedirectAuthenticationSuccessHandler();
private RedirectServerAuthenticationSuccessHandler handler =
new RedirectServerAuthenticationSuccessHandler();
@Test(expected = IllegalArgumentException.class)
public void constructorStringWhenNullLocationThenException() {