ServerWebExchangeAttributeServerSecurityContextRepository->NoOpNoOpServerSecurityContextRepository

Issue: gh-4719
This commit is contained in:
Rob Winch
2017-10-27 18:07:46 -05:00
parent 3281cea46a
commit 2060125ebd
4 changed files with 24 additions and 13 deletions

View File

@@ -26,7 +26,7 @@ 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.context.ServerSecurityContextRepository;
import org.springframework.security.web.server.context.ServerWebExchangeAttributeServerSecurityContextRepository;
import org.springframework.security.web.server.context.NoOpServerSecurityContextRepository;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher;
import org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers;
import org.springframework.util.Assert;
@@ -49,7 +49,7 @@ public class AuthenticationWebFilter implements WebFilter {
private ServerAuthenticationFailureHandler serverAuthenticationFailureHandler = new ServerAuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
private ServerSecurityContextRepository serverSecurityContextRepository = new ServerWebExchangeAttributeServerSecurityContextRepository();
private ServerSecurityContextRepository serverSecurityContextRepository = NoOpServerSecurityContextRepository.getInstance();
private ServerWebExchangeMatcher requiresAuthenticationMatcher = ServerWebExchangeMatchers.anyExchange();
public AuthenticationWebFilter(ReactiveAuthenticationManager authenticationManager) {

View File

@@ -25,16 +25,23 @@ import reactor.core.publisher.Mono;
* @author Rob Winch
* @since 5.0
*/
public class ServerWebExchangeAttributeServerSecurityContextRepository
public class NoOpServerSecurityContextRepository
implements ServerSecurityContextRepository {
final String ATTR = "USER";
private static final NoOpServerSecurityContextRepository INSTANCE = new NoOpServerSecurityContextRepository();
public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
return Mono.fromRunnable(() ->exchange.getAttributes().put(ATTR, context));
return Mono.empty();
}
public Mono<SecurityContext> load(ServerWebExchange exchange) {
return Mono.justOrEmpty(exchange.<SecurityContext>getAttribute(ATTR));
return Mono.empty();
}
public static NoOpServerSecurityContextRepository getInstance() {
return INSTANCE;
}
private NoOpServerSecurityContextRepository() {}
}