ServerSecurityContextRepository members to securityContextRepository

Issue: gh-4822
This commit is contained in:
Rob Winch 2017-11-13 16:08:05 -06:00
parent 9956de8f29
commit 692233e431
4 changed files with 40 additions and 40 deletions

View File

@ -113,7 +113,7 @@ public class ServerHttpSecurity {
private ReactiveAuthenticationManager authenticationManager;
private ServerSecurityContextRepository serverSecurityContextRepository = new WebSessionServerSecurityContextRepository();
private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
@ -148,9 +148,9 @@ public class ServerHttpSecurity {
return this.securityMatcher;
}
public ServerHttpSecurity securityContextRepository(ServerSecurityContextRepository serverSecurityContextRepository) {
Assert.notNull(serverSecurityContextRepository, "securityContextRepository cannot be null");
this.serverSecurityContextRepository = serverSecurityContextRepository;
public ServerHttpSecurity securityContextRepository(ServerSecurityContextRepository securityContextRepository) {
Assert.notNull(securityContextRepository, "securityContextRepository cannot be null");
this.securityContextRepository = securityContextRepository;
return this;
}
@ -229,15 +229,15 @@ public class ServerHttpSecurity {
}
if(this.httpBasic != null) {
this.httpBasic.authenticationManager(this.authenticationManager);
if(this.serverSecurityContextRepository != null) {
this.httpBasic.securityContextRepository(this.serverSecurityContextRepository);
if(this.securityContextRepository != null) {
this.httpBasic.securityContextRepository(this.securityContextRepository);
}
this.httpBasic.configure(this);
}
if(this.formLogin != null) {
this.formLogin.authenticationManager(this.authenticationManager);
if(this.serverSecurityContextRepository != null) {
this.formLogin.securityContextRepository(this.serverSecurityContextRepository);
if(this.securityContextRepository != null) {
this.formLogin.securityContextRepository(this.securityContextRepository);
}
if(this.formLogin.serverAuthenticationEntryPoint == null) {
this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder()));
@ -303,7 +303,7 @@ public class ServerHttpSecurity {
}
private WebFilter securityContextRepositoryWebFilter() {
ServerSecurityContextRepository repository = this.serverSecurityContextRepository;
ServerSecurityContextRepository repository = this.securityContextRepository;
if(repository == null) {
return null;
}
@ -480,7 +480,7 @@ public class ServerHttpSecurity {
public class HttpBasicSpec {
private ReactiveAuthenticationManager authenticationManager;
private ServerSecurityContextRepository serverSecurityContextRepository = NoOpServerSecurityContextRepository.getInstance();
private ServerSecurityContextRepository securityContextRepository = NoOpServerSecurityContextRepository.getInstance();
private ServerAuthenticationEntryPoint entryPoint = new HttpBasicServerAuthenticationEntryPoint();
@ -489,8 +489,8 @@ public class ServerHttpSecurity {
return this;
}
public HttpBasicSpec securityContextRepository(ServerSecurityContextRepository serverSecurityContextRepository) {
this.serverSecurityContextRepository = serverSecurityContextRepository;
public HttpBasicSpec securityContextRepository(ServerSecurityContextRepository securityContextRepository) {
this.securityContextRepository = securityContextRepository;
return this;
}
@ -515,8 +515,8 @@ public class ServerHttpSecurity {
this.authenticationManager);
authenticationFilter.setServerAuthenticationFailureHandler(new ServerAuthenticationEntryPointFailureHandler(this.entryPoint));
authenticationFilter.setAuthenticationConverter(new ServerHttpBasicAuthenticationConverter());
if(this.serverSecurityContextRepository != null) {
authenticationFilter.setServerSecurityContextRepository(this.serverSecurityContextRepository);
if(this.securityContextRepository != null) {
authenticationFilter.setSecurityContextRepository(this.securityContextRepository);
}
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.HTTP_BASIC);
}
@ -535,7 +535,7 @@ public class ServerHttpSecurity {
private ReactiveAuthenticationManager authenticationManager;
private ServerSecurityContextRepository serverSecurityContextRepository = new WebSessionServerSecurityContextRepository();
private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint;
@ -580,8 +580,8 @@ public class ServerHttpSecurity {
return this;
}
public FormLoginSpec securityContextRepository(ServerSecurityContextRepository serverSecurityContextRepository) {
this.serverSecurityContextRepository = serverSecurityContextRepository;
public FormLoginSpec securityContextRepository(ServerSecurityContextRepository securityContextRepository) {
this.securityContextRepository = securityContextRepository;
return this;
}
@ -615,7 +615,7 @@ public class ServerHttpSecurity {
authenticationFilter.setServerAuthenticationFailureHandler(this.serverAuthenticationFailureHandler);
authenticationFilter.setAuthenticationConverter(new ServerFormLoginAuthenticationConverter());
authenticationFilter.setServerAuthenticationSuccessHandler(this.serverAuthenticationSuccessHandler);
authenticationFilter.setServerSecurityContextRepository(this.serverSecurityContextRepository);
authenticationFilter.setSecurityContextRepository(this.securityContextRepository);
http.addFilterAt(authenticationFilter, SecurityWebFiltersOrder.FORM_LOGIN);
}

View File

@ -49,7 +49,7 @@ public class AuthenticationWebFilter implements WebFilter {
private ServerAuthenticationFailureHandler serverAuthenticationFailureHandler = new ServerAuthenticationEntryPointFailureHandler(new HttpBasicServerAuthenticationEntryPoint());
private ServerSecurityContextRepository serverSecurityContextRepository = NoOpServerSecurityContextRepository.getInstance();
private ServerSecurityContextRepository securityContextRepository = NoOpServerSecurityContextRepository.getInstance();
private ServerWebExchangeMatcher requiresAuthenticationMatcher = ServerWebExchangeMatchers.anyExchange();
@ -80,15 +80,15 @@ public class AuthenticationWebFilter implements WebFilter {
ServerWebExchange exchange = webFilterExchange.getExchange();
SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(authentication);
return this.serverSecurityContextRepository.save(exchange, securityContext)
return this.securityContextRepository.save(exchange, securityContext)
.then(this.serverAuthenticationSuccessHandler
.onAuthenticationSuccess(webFilterExchange, authentication));
}
public void setServerSecurityContextRepository(
ServerSecurityContextRepository serverSecurityContextRepository) {
Assert.notNull(serverSecurityContextRepository, "securityContextRepository cannot be null");
this.serverSecurityContextRepository = serverSecurityContextRepository;
public void setSecurityContextRepository(
ServerSecurityContextRepository securityContextRepository) {
Assert.notNull(securityContextRepository, "securityContextRepository cannot be null");
this.securityContextRepository = securityContextRepository;
}
public void setServerAuthenticationSuccessHandler(ServerAuthenticationSuccessHandler serverAuthenticationSuccessHandler) {

View File

@ -31,25 +31,25 @@ import reactor.core.publisher.Mono;
* @since 5.0
*/
public class SecurityContextServerLogoutHandler implements ServerLogoutHandler {
private ServerSecurityContextRepository serverSecurityContextRepository = new WebSessionServerSecurityContextRepository();
private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository();
@Override
public Mono<Void> logout(WebFilterExchange exchange,
Authentication authentication) {
return this.serverSecurityContextRepository.save(exchange.getExchange(), null);
return this.securityContextRepository.save(exchange.getExchange(), null);
}
/**
* Sets the {@link ServerSecurityContextRepository} that should be used for logging
* out. Default is {@link WebSessionServerSecurityContextRepository}
*
* @param serverSecurityContextRepository the {@link ServerSecurityContextRepository}
* @param securityContextRepository the {@link ServerSecurityContextRepository}
* to use.
*/
public void setServerSecurityContextRepository(
ServerSecurityContextRepository serverSecurityContextRepository) {
Assert.notNull(serverSecurityContextRepository,
"serverSecurityContextRepository cannot be null");
this.serverSecurityContextRepository = serverSecurityContextRepository;
public void setSecurityContextRepository(
ServerSecurityContextRepository securityContextRepository) {
Assert.notNull(securityContextRepository,
"securityContextRepository cannot be null");
this.securityContextRepository = securityContextRepository;
}
}

View File

@ -62,7 +62,7 @@ public class AuthenticationWebFilterTests {
@Mock
private ServerAuthenticationFailureHandler failureHandler;
@Mock
private ServerSecurityContextRepository serverSecurityContextRepository;
private ServerSecurityContextRepository securityContextRepository;
private AuthenticationWebFilter filter;
@ -71,7 +71,7 @@ public class AuthenticationWebFilterTests {
this.filter = new AuthenticationWebFilter(this.authenticationManager);
this.filter.setServerAuthenticationSuccessHandler(this.successHandler);
this.filter.setAuthenticationConverter(this.authenticationConverter);
this.filter.setServerSecurityContextRepository(this.serverSecurityContextRepository);
this.filter.setSecurityContextRepository(this.securityContextRepository);
this.filter.setServerAuthenticationFailureHandler(this.failureHandler);
}
@ -154,7 +154,7 @@ public class AuthenticationWebFilterTests {
.expectBody(String.class).consumeWith(b -> assertThat(b.getResponseBody()).isEqualTo("ok"))
.returnResult();
verify(this.serverSecurityContextRepository, never()).save(any(), any());
verify(this.securityContextRepository, never()).save(any(), any());
verifyZeroInteractions(this.authenticationManager, this.successHandler,
this.failureHandler);
}
@ -174,7 +174,7 @@ public class AuthenticationWebFilterTests {
.expectStatus().is5xxServerError()
.expectBody().isEmpty();
verify(this.serverSecurityContextRepository, never()).save(any(), any());
verify(this.securityContextRepository, never()).save(any(), any());
verifyZeroInteractions(this.authenticationManager, this.successHandler,
this.failureHandler);
}
@ -185,7 +185,7 @@ public class AuthenticationWebFilterTests {
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
when(this.successHandler.onAuthenticationSuccess(any(), any())).thenReturn(Mono.empty());
when(this.serverSecurityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
when(this.securityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
WebTestClient client = WebTestClientBuilder
.bindToWebFilters(this.filter)
@ -200,7 +200,7 @@ public class AuthenticationWebFilterTests {
verify(this.successHandler).onAuthenticationSuccess(any(),
eq(authentication.block()));
verify(this.serverSecurityContextRepository).save(any(), any());
verify(this.securityContextRepository).save(any(), any());
verifyZeroInteractions(this.failureHandler);
}
@ -245,7 +245,7 @@ public class AuthenticationWebFilterTests {
.expectBody().isEmpty();
verify(this.failureHandler).onAuthenticationFailure(any(),any());
verify(this.serverSecurityContextRepository, never()).save(any(), any());
verify(this.securityContextRepository, never()).save(any(), any());
verifyZeroInteractions(this.successHandler);
}
@ -266,7 +266,7 @@ public class AuthenticationWebFilterTests {
.expectStatus().is5xxServerError()
.expectBody().isEmpty();
verify(this.serverSecurityContextRepository, never()).save(any(), any());
verify(this.securityContextRepository, never()).save(any(), any());
verifyZeroInteractions(this.successHandler, this.failureHandler);
}