diff --git a/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java b/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java index b25b4250df..4886dee3db 100644 --- a/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java +++ b/config/src/main/java/org/springframework/security/config/web/server/ServerHttpSecurity.java @@ -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); } diff --git a/web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java b/web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java index 9c1a4c882d..f254e5ccd5 100644 --- a/web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java +++ b/web/src/main/java/org/springframework/security/web/server/authentication/AuthenticationWebFilter.java @@ -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) { diff --git a/web/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextServerLogoutHandler.java b/web/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextServerLogoutHandler.java index 9f3261fcac..15e2d58e75 100644 --- a/web/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextServerLogoutHandler.java +++ b/web/src/main/java/org/springframework/security/web/server/authentication/logout/SecurityContextServerLogoutHandler.java @@ -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 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; } } diff --git a/web/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java b/web/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java index 43794c89fc..48c78ea42b 100644 --- a/web/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java +++ b/web/src/test/java/org/springframework/security/web/server/authentication/AuthenticationWebFilterTests.java @@ -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); }