LogoutHandler->ServerLogoutHandler

Issue gh-4615
This commit is contained in:
Rob Winch 2017-10-10 16:06:05 -05:00
parent c9ce528206
commit 185d3032f5
4 changed files with 16 additions and 15 deletions

View File

@ -35,9 +35,9 @@ import org.springframework.security.web.server.authentication.ServerAuthenticati
import org.springframework.security.web.server.authentication.AuthenticationWebFilter;
import org.springframework.security.web.server.authentication.RedirectServerAuthenticationEntryPoint;
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.ServerLogoutHandler;
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.logout.SecurityContextServerLogoutHandler;
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;
@ -555,21 +555,21 @@ public class HttpSecurity {
*/
public final class LogoutBuilder {
private LogoutHandler logoutHandler = new SecurityContextRepositoryLogoutHandler();
private ServerLogoutHandler serverLogoutHandler = new SecurityContextServerLogoutHandler();
private String logoutUrl = "/logout";
private ServerWebExchangeMatcher requiresLogout = ServerWebExchangeMatchers
.pathMatchers(this.logoutUrl);
public LogoutBuilder logoutHandler(LogoutHandler logoutHandler) {
Assert.notNull(logoutHandler, "logoutHandler must not be null");
this.logoutHandler = logoutHandler;
public LogoutBuilder logoutHandler(ServerLogoutHandler serverLogoutHandler) {
Assert.notNull(serverLogoutHandler, "logoutHandler must not be null");
this.serverLogoutHandler = serverLogoutHandler;
return this;
}
public LogoutBuilder logoutUrl(String logoutUrl) {
Assert.notNull(this.logoutHandler, "logoutUrl must not be null");
Assert.notNull(this.serverLogoutHandler, "logoutUrl must not be null");
this.logoutUrl = logoutUrl;
this.requiresLogout = ServerWebExchangeMatchers.pathMatchers(logoutUrl);
return this;
@ -591,7 +591,7 @@ public class HttpSecurity {
private LogoutWebFilter createLogoutWebFilter(HttpSecurity http) {
LogoutWebFilter logoutWebFilter = new LogoutWebFilter();
logoutWebFilter.setLogoutHandler(this.logoutHandler);
logoutWebFilter.setServerLogoutHandler(this.serverLogoutHandler);
logoutWebFilter.setRequiresLogout(this.requiresLogout);
return logoutWebFilter;

View File

@ -36,7 +36,7 @@ import org.springframework.web.server.WebFilterChain;
public class LogoutWebFilter implements WebFilter {
private AnonymousAuthenticationToken anonymousAuthenticationToken = new AnonymousAuthenticationToken("key", "anonymous",
AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
private LogoutHandler logoutHandler = new SecurityContextRepositoryLogoutHandler();
private ServerLogoutHandler serverLogoutHandler = new SecurityContextServerLogoutHandler();
private ServerWebExchangeMatcher requiresLogout = ServerWebExchangeMatchers
.pathMatchers("/logout");
@ -47,7 +47,8 @@ public class LogoutWebFilter implements WebFilter {
.filter( result -> result.isMatch())
.switchIfEmpty(chain.filter(exchange).then(Mono.empty()))
.flatMap( result -> authentication(exchange))
.flatMap( authentication -> this.logoutHandler.logout(new WebFilterExchange(exchange, chain), authentication));
.flatMap( authentication -> this.serverLogoutHandler
.logout(new WebFilterExchange(exchange, chain), authentication));
}
private Mono<Authentication> authentication(ServerWebExchange exchange) {
@ -56,9 +57,9 @@ public class LogoutWebFilter implements WebFilter {
.defaultIfEmpty(this.anonymousAuthenticationToken);
}
public final void setLogoutHandler(LogoutHandler logoutHandler) {
Assert.notNull(logoutHandler, "logoutHandler must not be null");
this.logoutHandler = logoutHandler;
public final void setServerLogoutHandler(ServerLogoutHandler serverLogoutHandler) {
Assert.notNull(serverLogoutHandler, "logoutHandler must not be null");
this.serverLogoutHandler = serverLogoutHandler;
}
public final void setRequiresLogout(ServerWebExchangeMatcher serverWebExchangeMatcher) {

View File

@ -30,7 +30,7 @@ import java.net.URI;
* @author Rob Winch
* @since 5.0
*/
public class SecurityContextRepositoryLogoutHandler implements LogoutHandler {
public class SecurityContextServerLogoutHandler implements ServerLogoutHandler {
private SecurityContextServerRepository repository = new WebSessionSecurityContextServerRepository();
private URI logoutSuccessUrl = URI.create("/login?logout");

View File

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