mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	serverRedirectStrategy->redirectStrategy
Issue: gh-4822
This commit is contained in:
		
							parent
							
								
									2cbdb4ba02
								
							
						
					
					
						commit
						1c977ca15f
					
				| @ -39,7 +39,7 @@ public class RedirectServerAuthenticationEntryPoint | ||||
| 	implements ServerAuthenticationEntryPoint { | ||||
| 	private final URI location; | ||||
| 
 | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 	private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 
 | ||||
| 	private ServerRequestCache requestCache = new WebSessionServerRequestCache(); | ||||
| 
 | ||||
| @ -56,15 +56,15 @@ public class RedirectServerAuthenticationEntryPoint | ||||
| 	@Override | ||||
| 	public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) { | ||||
| 		return this.requestCache.saveRequest(exchange) | ||||
| 			.then(this.serverRedirectStrategy.sendRedirect(exchange, this.location)); | ||||
| 			.then(this.redirectStrategy.sendRedirect(exchange, this.location)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Sets the RedirectStrategy to use. | ||||
| 	 * @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 */ | ||||
| 	public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { | ||||
| 		Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.serverRedirectStrategy = serverRedirectStrategy; | ||||
| 	public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) { | ||||
| 		Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.redirectStrategy = redirectStrategy; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -35,7 +35,7 @@ public class RedirectServerAuthenticationFailureHandler | ||||
| 	implements ServerAuthenticationFailureHandler { | ||||
| 	private final URI location; | ||||
| 
 | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 	private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 
 | ||||
| 	public RedirectServerAuthenticationFailureHandler(String location) { | ||||
| 		Assert.notNull(location, "location cannot be null"); | ||||
| @ -44,16 +44,16 @@ public class RedirectServerAuthenticationFailureHandler | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Sets the RedirectStrategy to use. | ||||
| 	 * @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 */ | ||||
| 	public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { | ||||
| 		Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.serverRedirectStrategy = serverRedirectStrategy; | ||||
| 	public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) { | ||||
| 		Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.redirectStrategy = redirectStrategy; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Mono<Void> onAuthenticationFailure( | ||||
| 		WebFilterExchange webFilterExchange, AuthenticationException exception) { | ||||
| 		return this.serverRedirectStrategy.sendRedirect(webFilterExchange.getExchange(), this.location); | ||||
| 		return this.redirectStrategy.sendRedirect(webFilterExchange.getExchange(), this.location); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -36,7 +36,7 @@ public class RedirectServerAuthenticationSuccessHandler | ||||
| 	implements ServerAuthenticationSuccessHandler { | ||||
| 	private URI location = URI.create("/"); | ||||
| 
 | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 	private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 
 | ||||
| 	private ServerRequestCache requestCache = new WebSessionServerRequestCache(); | ||||
| 
 | ||||
| @ -59,7 +59,7 @@ public class RedirectServerAuthenticationSuccessHandler | ||||
| 			.map(r -> r.getPath().pathWithinApplication().value()) | ||||
| 			.map(URI::create) | ||||
| 			.defaultIfEmpty(this.location) | ||||
| 			.flatMap(location -> this.serverRedirectStrategy.sendRedirect(exchange, location)); | ||||
| 			.flatMap(location -> this.redirectStrategy.sendRedirect(exchange, location)); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| @ -73,10 +73,10 @@ public class RedirectServerAuthenticationSuccessHandler | ||||
| 
 | ||||
| 	/** | ||||
| 	 * The RedirectStrategy to use. | ||||
| 	 * @param serverRedirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 * @param redirectStrategy the strategy to use. Default is DefaultRedirectStrategy. | ||||
| 	 */ | ||||
| 	public void setServerRedirectStrategy(ServerRedirectStrategy serverRedirectStrategy) { | ||||
| 		Assert.notNull(serverRedirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.serverRedirectStrategy = serverRedirectStrategy; | ||||
| 	public void setRedirectStrategy(ServerRedirectStrategy redirectStrategy) { | ||||
| 		Assert.notNull(redirectStrategy, "redirectStrategy cannot be null"); | ||||
| 		this.redirectStrategy = redirectStrategy; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -34,11 +34,11 @@ public class RedirectServerLogoutSuccessHandler implements ServerLogoutSuccessHa | ||||
| 
 | ||||
| 	private URI logoutSuccessUrl = URI.create(DEFAULT_LOGOUT_SUCCESS_URL); | ||||
| 
 | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 	private ServerRedirectStrategy redirectStrategy = new DefaultServerRedirectStrategy(); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Mono<Void> onLogoutSuccess(WebFilterExchange exchange, Authentication authentication) { | ||||
| 		return this.serverRedirectStrategy | ||||
| 		return this.redirectStrategy | ||||
| 			.sendRedirect(exchange.getExchange(), this.logoutSuccessUrl); | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -44,7 +44,7 @@ public class RedirectServerAuthenticationEntryPointTests { | ||||
| 	@Mock | ||||
| 	private ServerWebExchange exchange; | ||||
| 	@Mock | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy; | ||||
| 	private ServerRedirectStrategy redirectStrategy; | ||||
| 
 | ||||
| 	private String location = "/login"; | ||||
| 
 | ||||
| @ -83,8 +83,8 @@ public class RedirectServerAuthenticationEntryPointTests { | ||||
| 	@Test | ||||
| 	public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() { | ||||
| 		PublisherProbe<Void> redirectResult = PublisherProbe.empty(); | ||||
| 		when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.entryPoint.setServerRedirectStrategy(this.serverRedirectStrategy); | ||||
| 		when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.entryPoint.setRedirectStrategy(this.redirectStrategy); | ||||
| 		this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build()); | ||||
| 
 | ||||
| 		this.entryPoint.commence(this.exchange, this.exception).block(); | ||||
| @ -94,6 +94,6 @@ public class RedirectServerAuthenticationEntryPointTests { | ||||
| 
 | ||||
| 	@Test(expected = IllegalArgumentException.class) | ||||
| 	public void setRedirectStrategyWhenNullThenException() { | ||||
| 		this.entryPoint.setServerRedirectStrategy(null); | ||||
| 		this.entryPoint.setRedirectStrategy(null); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -44,7 +44,7 @@ public class RedirectServerAuthenticationFailureHandlerTests { | ||||
| 
 | ||||
| 	private WebFilterExchange exchange; | ||||
| 	@Mock | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy; | ||||
| 	private ServerRedirectStrategy redirectStrategy; | ||||
| 
 | ||||
| 	private String location = "/login"; | ||||
| 
 | ||||
| @ -83,8 +83,8 @@ public class RedirectServerAuthenticationFailureHandlerTests { | ||||
| 	@Test | ||||
| 	public void commenceWhenCustomServerRedirectStrategyThenCustomServerRedirectStrategyUsed() { | ||||
| 		PublisherProbe<Void> redirectResult = PublisherProbe.empty(); | ||||
| 		when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.handler.setServerRedirectStrategy(this.serverRedirectStrategy); | ||||
| 		when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.handler.setRedirectStrategy(this.redirectStrategy); | ||||
| 		this.exchange = createExchange(); | ||||
| 
 | ||||
| 		this.handler.onAuthenticationFailure(this.exchange, this.exception).block(); | ||||
| @ -94,7 +94,7 @@ public class RedirectServerAuthenticationFailureHandlerTests { | ||||
| 
 | ||||
| 	@Test(expected = IllegalArgumentException.class) | ||||
| 	public void setRedirectStrategyWhenNullThenException() { | ||||
| 		this.handler.setServerRedirectStrategy(null); | ||||
| 		this.handler.setRedirectStrategy(null); | ||||
| 	} | ||||
| 
 | ||||
| 	private WebFilterExchange createExchange() { | ||||
|  | ||||
| @ -50,7 +50,7 @@ public class RedirectServerAuthenticationSuccessHandlerTests { | ||||
| 	@Mock | ||||
| 	private WebFilterChain chain; | ||||
| 	@Mock | ||||
| 	private ServerRedirectStrategy serverRedirectStrategy; | ||||
| 	private ServerRedirectStrategy redirectStrategy; | ||||
| 	@Mock | ||||
| 	private Authentication authentication; | ||||
| 
 | ||||
| @ -90,19 +90,19 @@ public class RedirectServerAuthenticationSuccessHandlerTests { | ||||
| 	@Test | ||||
| 	public void successWhenCustomLocationThenCustomLocationUsed() { | ||||
| 		PublisherProbe<Void> redirectResult = PublisherProbe.empty(); | ||||
| 		when(this.serverRedirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.handler.setServerRedirectStrategy(this.serverRedirectStrategy); | ||||
| 		when(this.redirectStrategy.sendRedirect(any(), any())).thenReturn(redirectResult.mono()); | ||||
| 		this.handler.setRedirectStrategy(this.redirectStrategy); | ||||
| 		this.exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build()); | ||||
| 
 | ||||
| 		this.handler.onAuthenticationSuccess(new WebFilterExchange(this.exchange, | ||||
| 			this.chain), this.authentication).block(); | ||||
| 		redirectResult.assertWasSubscribed(); | ||||
| 		verify(this.serverRedirectStrategy).sendRedirect(any(), eq(this.location)); | ||||
| 		verify(this.redirectStrategy).sendRedirect(any(), eq(this.location)); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test(expected = IllegalArgumentException.class) | ||||
| 	public void setRedirectStrategyWhenNullThenException() { | ||||
| 		this.handler.setServerRedirectStrategy(null); | ||||
| 		this.handler.setRedirectStrategy(null); | ||||
| 	} | ||||
| 
 | ||||
| 	@Test(expected = IllegalArgumentException.class) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user