mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 06:12:27 +00:00
ServerAuthenticationSuccessHandler.success->onAuthenticationSuccess
Fixes gh-4618
This commit is contained in:
parent
247f737bc8
commit
78d2069c46
@ -88,7 +88,7 @@ public class AuthenticationWebFilter implements WebFilter {
|
|||||||
securityContext.setAuthentication(authentication);
|
securityContext.setAuthentication(authentication);
|
||||||
return this.serverSecurityContextRepository.save(exchange, securityContext)
|
return this.serverSecurityContextRepository.save(exchange, securityContext)
|
||||||
.then(this.serverAuthenticationSuccessHandler
|
.then(this.serverAuthenticationSuccessHandler
|
||||||
.success(authentication, webFilterExchange));
|
.onAuthenticationSuccess(authentication, webFilterExchange));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerSecurityContextRepository(
|
public void setServerSecurityContextRepository(
|
||||||
|
@ -43,7 +43,7 @@ public class RedirectServerAuthenticationSuccessHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> success(Authentication authentication, WebFilterExchange webFilterExchange) {
|
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
|
||||||
ServerWebExchange exchange = webFilterExchange.getExchange();
|
ServerWebExchange exchange = webFilterExchange.getExchange();
|
||||||
return this.serverRedirectStrategy.sendRedirect(exchange, this.location);
|
return this.serverRedirectStrategy.sendRedirect(exchange, this.location);
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ import reactor.core.publisher.Mono;
|
|||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public interface ServerAuthenticationSuccessHandler {
|
public interface ServerAuthenticationSuccessHandler {
|
||||||
Mono<Void> success(Authentication authentication, WebFilterExchange webFilterExchange);
|
Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange);
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import reactor.core.publisher.Mono;
|
|||||||
public class WebFilterChainServerAuthenticationSuccessHandler
|
public class WebFilterChainServerAuthenticationSuccessHandler
|
||||||
implements ServerAuthenticationSuccessHandler {
|
implements ServerAuthenticationSuccessHandler {
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> success(Authentication authentication, WebFilterExchange webFilterExchange) {
|
public Mono<Void> onAuthenticationSuccess(Authentication authentication, WebFilterExchange webFilterExchange) {
|
||||||
ServerWebExchange exchange = webFilterExchange.getExchange();
|
ServerWebExchange exchange = webFilterExchange.getExchange();
|
||||||
return webFilterExchange.getChain().filter(exchange);
|
return webFilterExchange.getChain().filter(exchange);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ public class AuthenticationWebFilterTests {
|
|||||||
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
Mono<Authentication> authentication = Mono.just(new TestingAuthenticationToken("test", "this", "ROLE_USER"));
|
||||||
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
when(this.authenticationConverter.apply(any())).thenReturn(authentication);
|
||||||
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
|
when(this.authenticationManager.authenticate(any())).thenReturn(authentication);
|
||||||
when(this.successHandler.success(any(),any())).thenReturn(Mono.empty());
|
when(this.successHandler.onAuthenticationSuccess(any(),any())).thenReturn(Mono.empty());
|
||||||
when(this.serverSecurityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
when(this.serverSecurityContextRepository.save(any(),any())).thenAnswer( a -> Mono.just(a.getArguments()[0]));
|
||||||
|
|
||||||
WebTestClient client = WebTestClientBuilder
|
WebTestClient client = WebTestClientBuilder
|
||||||
@ -198,7 +198,7 @@ public class AuthenticationWebFilterTests {
|
|||||||
.expectStatus().isOk()
|
.expectStatus().isOk()
|
||||||
.expectBody().isEmpty();
|
.expectBody().isEmpty();
|
||||||
|
|
||||||
verify(this.successHandler).success(eq(authentication.block()), any());
|
verify(this.successHandler).onAuthenticationSuccess(eq(authentication.block()), any());
|
||||||
verify(this.serverSecurityContextRepository).save(any(), any());
|
verify(this.serverSecurityContextRepository).save(any(), any());
|
||||||
verifyZeroInteractions(this.failureHandler);
|
verifyZeroInteractions(this.failureHandler);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void successWhenNoSubscribersThenNoActions() {
|
public void successWhenNoSubscribersThenNoActions() {
|
||||||
this.handler.success(this.authentication, new WebFilterExchange(this.exchange,
|
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
||||||
this.chain));
|
this.chain));
|
||||||
|
|
||||||
verifyZeroInteractions(this.exchange);
|
verifyZeroInteractions(this.exchange);
|
||||||
@ -76,7 +76,7 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
|||||||
public void successWhenSubscribeThenStatusAndLocationSet() {
|
public void successWhenSubscribeThenStatusAndLocationSet() {
|
||||||
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
||||||
|
|
||||||
this.handler.success(this.authentication, new WebFilterExchange(this.exchange,
|
this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
||||||
this.chain)).block();
|
this.chain)).block();
|
||||||
|
|
||||||
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(
|
assertThat(this.exchange.getResponse().getStatusCode()).isEqualTo(
|
||||||
@ -91,7 +91,7 @@ public class RedirectServerAuthenticationSuccessHandlerTests {
|
|||||||
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
|
this.handler.setServerRedirectStrategy(this.serverRedirectStrategy);
|
||||||
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
this.exchange = MockServerHttpRequest.get("/").toExchange();
|
||||||
|
|
||||||
assertThat(this.handler.success(this.authentication, new WebFilterExchange(this.exchange,
|
assertThat(this.handler.onAuthenticationSuccess(this.authentication, new WebFilterExchange(this.exchange,
|
||||||
this.chain))).isEqualTo(result);
|
this.chain))).isEqualTo(result);
|
||||||
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
|
verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user