serverAuthenticationEntryPoint->authenticationEntryPoint
Issue: gh-4822
This commit is contained in:
		
							parent
							
								
									9cf0dc6b38
								
							
						
					
					
						commit
						9e82fc0b83
					
				|  | @ -115,7 +115,7 @@ public class ServerHttpSecurity { | ||||||
| 
 | 
 | ||||||
| 	private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); | 	private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); | ||||||
| 
 | 
 | ||||||
| 	private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; | 	private ServerAuthenticationEntryPoint authenticationEntryPoint; | ||||||
| 
 | 
 | ||||||
| 	private List<DelegateEntry> defaultEntryPoints = new ArrayList<>(); | 	private List<DelegateEntry> defaultEntryPoints = new ArrayList<>(); | ||||||
| 
 | 
 | ||||||
|  | @ -239,7 +239,7 @@ public class ServerHttpSecurity { | ||||||
| 			if(this.securityContextRepository != null) { | 			if(this.securityContextRepository != null) { | ||||||
| 				this.formLogin.securityContextRepository(this.securityContextRepository); | 				this.formLogin.securityContextRepository(this.securityContextRepository); | ||||||
| 			} | 			} | ||||||
| 			if(this.formLogin.serverAuthenticationEntryPoint == null) { | 			if(this.formLogin.authenticationEntryPoint == null) { | ||||||
| 				this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder())); | 				this.webFilters.add(new OrderedWebFilter(new LoginPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGIN_PAGE_GENERATING.getOrder())); | ||||||
| 				this.webFilters.add(new OrderedWebFilter(new LogoutPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGOUT_PAGE_GENERATING.getOrder())); | 				this.webFilters.add(new OrderedWebFilter(new LogoutPageGeneratingWebFilter(), SecurityWebFiltersOrder.LOGOUT_PAGE_GENERATING.getOrder())); | ||||||
| 			} | 			} | ||||||
|  | @ -251,11 +251,11 @@ public class ServerHttpSecurity { | ||||||
| 		this.requestCache.configure(this); | 		this.requestCache.configure(this); | ||||||
| 		this.addFilterAt(new SecurityContextServerWebExchangeWebFilter(), SecurityWebFiltersOrder.SECURITY_CONTEXT_SERVER_WEB_EXCHANGE); | 		this.addFilterAt(new SecurityContextServerWebExchangeWebFilter(), SecurityWebFiltersOrder.SECURITY_CONTEXT_SERVER_WEB_EXCHANGE); | ||||||
| 		if(this.authorizeExchange != null) { | 		if(this.authorizeExchange != null) { | ||||||
| 			ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = getServerAuthenticationEntryPoint(); | 			ServerAuthenticationEntryPoint authenticationEntryPoint = getAuthenticationEntryPoint(); | ||||||
| 			ExceptionTranslationWebFilter exceptionTranslationWebFilter = new ExceptionTranslationWebFilter(); | 			ExceptionTranslationWebFilter exceptionTranslationWebFilter = new ExceptionTranslationWebFilter(); | ||||||
| 			if(serverAuthenticationEntryPoint != null) { | 			if(authenticationEntryPoint != null) { | ||||||
| 				exceptionTranslationWebFilter.setServerAuthenticationEntryPoint( | 				exceptionTranslationWebFilter.setAuthenticationEntryPoint( | ||||||
| 					serverAuthenticationEntryPoint); | 					authenticationEntryPoint); | ||||||
| 			} | 			} | ||||||
| 			this.addFilterAt(exceptionTranslationWebFilter, SecurityWebFiltersOrder.EXCEPTION_TRANSLATION); | 			this.addFilterAt(exceptionTranslationWebFilter, SecurityWebFiltersOrder.EXCEPTION_TRANSLATION); | ||||||
| 			this.authorizeExchange.configure(this); | 			this.authorizeExchange.configure(this); | ||||||
|  | @ -286,9 +286,9 @@ public class ServerHttpSecurity { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private ServerAuthenticationEntryPoint getServerAuthenticationEntryPoint() { | 	private ServerAuthenticationEntryPoint getAuthenticationEntryPoint() { | ||||||
| 		if(this.serverAuthenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) { | 		if(this.authenticationEntryPoint != null || this.defaultEntryPoints.isEmpty()) { | ||||||
| 			return this.serverAuthenticationEntryPoint; | 			return this.authenticationEntryPoint; | ||||||
| 		} | 		} | ||||||
| 		if(this.defaultEntryPoints.size() == 1) { | 		if(this.defaultEntryPoints.size() == 1) { | ||||||
| 			return this.defaultEntryPoints.get(0).getEntryPoint(); | 			return this.defaultEntryPoints.get(0).getEntryPoint(); | ||||||
|  | @ -432,8 +432,9 @@ public class ServerHttpSecurity { | ||||||
| 	 * @since 5.0 | 	 * @since 5.0 | ||||||
| 	 */ | 	 */ | ||||||
| 	public class ExceptionHandlingSpec { | 	public class ExceptionHandlingSpec { | ||||||
| 		public ExceptionHandlingSpec serverAuthenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { | 
 | ||||||
| 			ServerHttpSecurity.this.serverAuthenticationEntryPoint = authenticationEntryPoint; | 		public ExceptionHandlingSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { | ||||||
|  | 			ServerHttpSecurity.this.authenticationEntryPoint = authenticationEntryPoint; | ||||||
| 			return this; | 			return this; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -537,7 +538,7 @@ public class ServerHttpSecurity { | ||||||
| 
 | 
 | ||||||
| 		private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); | 		private ServerSecurityContextRepository securityContextRepository = new WebSessionServerSecurityContextRepository(); | ||||||
| 
 | 
 | ||||||
| 		private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; | 		private ServerAuthenticationEntryPoint authenticationEntryPoint; | ||||||
| 
 | 
 | ||||||
| 		private ServerWebExchangeMatcher requiresAuthenticationMatcher; | 		private ServerWebExchangeMatcher requiresAuthenticationMatcher; | ||||||
| 
 | 
 | ||||||
|  | @ -559,14 +560,14 @@ public class ServerHttpSecurity { | ||||||
| 
 | 
 | ||||||
| 		public FormLoginSpec loginPage(String loginPage) { | 		public FormLoginSpec loginPage(String loginPage) { | ||||||
| 			this.defaultEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage); | 			this.defaultEntryPoint = new RedirectServerAuthenticationEntryPoint(loginPage); | ||||||
| 			this.serverAuthenticationEntryPoint = this.defaultEntryPoint; | 			this.authenticationEntryPoint = this.defaultEntryPoint; | ||||||
| 			this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage); | 			this.requiresAuthenticationMatcher = ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, loginPage); | ||||||
| 			this.authenticationFailureHandler = new RedirectServerAuthenticationFailureHandler(loginPage + "?error"); | 			this.authenticationFailureHandler = new RedirectServerAuthenticationFailureHandler(loginPage + "?error"); | ||||||
| 			return this; | 			return this; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { | 		public FormLoginSpec authenticationEntryPoint(ServerAuthenticationEntryPoint authenticationEntryPoint) { | ||||||
| 			this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; | 			this.authenticationEntryPoint = authenticationEntryPoint; | ||||||
| 			return this; | 			return this; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | @ -595,7 +596,7 @@ public class ServerHttpSecurity { | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		protected void configure(ServerHttpSecurity http) { | 		protected void configure(ServerHttpSecurity http) { | ||||||
| 			if(this.serverAuthenticationEntryPoint == null) { | 			if(this.authenticationEntryPoint == null) { | ||||||
| 				loginPage("/login"); | 				loginPage("/login"); | ||||||
| 			} | 			} | ||||||
| 			if(http.requestCache != null) { | 			if(http.requestCache != null) { | ||||||
|  | @ -608,7 +609,7 @@ public class ServerHttpSecurity { | ||||||
| 			MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( | 			MediaTypeServerWebExchangeMatcher htmlMatcher = new MediaTypeServerWebExchangeMatcher( | ||||||
| 				MediaType.TEXT_HTML); | 				MediaType.TEXT_HTML); | ||||||
| 			htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); | 			htmlMatcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL)); | ||||||
| 			ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.serverAuthenticationEntryPoint)); | 			ServerHttpSecurity.this.defaultEntryPoints.add(0, new DelegateEntry(htmlMatcher, this.authenticationEntryPoint)); | ||||||
| 			AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter( | 			AuthenticationWebFilter authenticationFilter = new AuthenticationWebFilter( | ||||||
| 				this.authenticationManager); | 				this.authenticationManager); | ||||||
| 			authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher); | 			authenticationFilter.setRequiresAuthenticationMatcher(this.requiresAuthenticationMatcher); | ||||||
|  |  | ||||||
|  | @ -28,18 +28,18 @@ import reactor.core.publisher.Mono; | ||||||
|  */ |  */ | ||||||
| public class ServerAuthenticationEntryPointFailureHandler | public class ServerAuthenticationEntryPointFailureHandler | ||||||
| 	implements ServerAuthenticationFailureHandler { | 	implements ServerAuthenticationFailureHandler { | ||||||
| 	private final ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; | 	private final ServerAuthenticationEntryPoint authenticationEntryPoint; | ||||||
| 
 | 
 | ||||||
| 	public ServerAuthenticationEntryPointFailureHandler( | 	public ServerAuthenticationEntryPointFailureHandler( | ||||||
| 		ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { | 		ServerAuthenticationEntryPoint authenticationEntryPoint) { | ||||||
| 		Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null"); | 		Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null"); | ||||||
| 		this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; | 		this.authenticationEntryPoint = authenticationEntryPoint; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, | 	public Mono<Void> onAuthenticationFailure(WebFilterExchange webFilterExchange, | ||||||
| 		AuthenticationException exception) { | 		AuthenticationException exception) { | ||||||
| 		return this.serverAuthenticationEntryPoint | 		return this.authenticationEntryPoint | ||||||
| 			.commence(webFilterExchange.getExchange(), exception); | 			.commence(webFilterExchange.getExchange(), exception); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ import org.springframework.web.server.WebFilterChain; | ||||||
|  * @since 5.0 |  * @since 5.0 | ||||||
|  */ |  */ | ||||||
| public class ExceptionTranslationWebFilter implements WebFilter { | public class ExceptionTranslationWebFilter implements WebFilter { | ||||||
| 	private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint(); | 	private ServerAuthenticationEntryPoint authenticationEntryPoint = new HttpBasicServerAuthenticationEntryPoint(); | ||||||
| 
 | 
 | ||||||
| 	private ServerAccessDeniedHandler serverAccessDeniedHandler = new HttpStatusServerAccessDeniedHandler(HttpStatus.FORBIDDEN); | 	private ServerAccessDeniedHandler serverAccessDeniedHandler = new HttpStatusServerAccessDeniedHandler(HttpStatus.FORBIDDEN); | ||||||
| 
 | 
 | ||||||
|  | @ -59,17 +59,17 @@ public class ExceptionTranslationWebFilter implements WebFilter { | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * Sets the authentication entry point used when authentication is required | 	 * Sets the authentication entry point used when authentication is required | ||||||
| 	 * @param serverAuthenticationEntryPoint the authentication entry point to use. Default is | 	 * @param authenticationEntryPoint the authentication entry point to use. Default is | ||||||
| 	 * {@link HttpBasicServerAuthenticationEntryPoint} | 	 * {@link HttpBasicServerAuthenticationEntryPoint} | ||||||
| 	 */ | 	 */ | ||||||
| 	public void setServerAuthenticationEntryPoint( | 	public void setAuthenticationEntryPoint( | ||||||
| 		ServerAuthenticationEntryPoint serverAuthenticationEntryPoint) { | 		ServerAuthenticationEntryPoint authenticationEntryPoint) { | ||||||
| 		Assert.notNull(serverAuthenticationEntryPoint, "authenticationEntryPoint cannot be null"); | 		Assert.notNull(authenticationEntryPoint, "authenticationEntryPoint cannot be null"); | ||||||
| 		this.serverAuthenticationEntryPoint = serverAuthenticationEntryPoint; | 		this.authenticationEntryPoint = authenticationEntryPoint; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private <T> Mono<T> commenceAuthentication(ServerWebExchange exchange, AccessDeniedException denied) { | 	private <T> Mono<T> commenceAuthentication(ServerWebExchange exchange, AccessDeniedException denied) { | ||||||
| 		return this.serverAuthenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied)) | 		return this.authenticationEntryPoint.commence(exchange, new AuthenticationCredentialsNotFoundException("Not Authenticated", denied)) | ||||||
| 			.then(Mono.empty()); | 			.then(Mono.empty()); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -39,7 +39,7 @@ import static org.mockito.Mockito.when; | ||||||
| @RunWith(MockitoJUnitRunner.class) | @RunWith(MockitoJUnitRunner.class) | ||||||
| public class ServerAuthenticationEntryPointFailureHandlerTests { | public class ServerAuthenticationEntryPointFailureHandlerTests { | ||||||
| 	@Mock | 	@Mock | ||||||
| 	private ServerAuthenticationEntryPoint serverAuthenticationEntryPoint; | 	private ServerAuthenticationEntryPoint authenticationEntryPoint; | ||||||
| 	@Mock | 	@Mock | ||||||
| 	private ServerWebExchange exchange; | 	private ServerWebExchange exchange; | ||||||
| 	@Mock | 	@Mock | ||||||
|  | @ -53,15 +53,15 @@ public class ServerAuthenticationEntryPointFailureHandlerTests { | ||||||
| 
 | 
 | ||||||
| 	@Test(expected = IllegalArgumentException.class) | 	@Test(expected = IllegalArgumentException.class) | ||||||
| 	public void constructorWhenNullEntryPointThenException() { | 	public void constructorWhenNullEntryPointThenException() { | ||||||
| 		this.serverAuthenticationEntryPoint = null; | 		this.authenticationEntryPoint = null; | ||||||
| 		new ServerAuthenticationEntryPointFailureHandler(this.serverAuthenticationEntryPoint); | 		new ServerAuthenticationEntryPointFailureHandler(this.authenticationEntryPoint); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void onAuthenticationFailureWhenInvokedThenDelegatesToEntryPoint() { | 	public void onAuthenticationFailureWhenInvokedThenDelegatesToEntryPoint() { | ||||||
| 		Mono<Void> result = Mono.empty(); | 		Mono<Void> result = Mono.empty(); | ||||||
| 		BadCredentialsException e = new BadCredentialsException("Failed"); | 		BadCredentialsException e = new BadCredentialsException("Failed"); | ||||||
| 		when(this.serverAuthenticationEntryPoint.commence(this.exchange, e)).thenReturn(result); | 		when(this.authenticationEntryPoint.commence(this.exchange, e)).thenReturn(result); | ||||||
| 
 | 
 | ||||||
| 		assertThat(this.handler.onAuthenticationFailure(this.filterExchange, e)).isEqualTo(result); | 		assertThat(this.handler.onAuthenticationFailure(this.filterExchange, e)).isEqualTo(result); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -66,7 +66,7 @@ public class ExceptionTranslationWebFilterTests { | ||||||
| 		when(this.deniedHandler.handle(any(), any())).thenReturn(this.deniedPublisher.mono()); | 		when(this.deniedHandler.handle(any(), any())).thenReturn(this.deniedPublisher.mono()); | ||||||
| 		when(this.entryPoint.commence(any(), any())).thenReturn(this.entryPointPublisher.mono()); | 		when(this.entryPoint.commence(any(), any())).thenReturn(this.entryPointPublisher.mono()); | ||||||
| 
 | 
 | ||||||
| 		this.filter.setServerAuthenticationEntryPoint(this.entryPoint); | 		this.filter.setAuthenticationEntryPoint(this.entryPoint); | ||||||
| 		this.filter.setServerAccessDeniedHandler(this.deniedHandler); | 		this.filter.setServerAccessDeniedHandler(this.deniedHandler); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -155,6 +155,6 @@ public class ExceptionTranslationWebFilterTests { | ||||||
| 
 | 
 | ||||||
| 	@Test(expected = IllegalArgumentException.class) | 	@Test(expected = IllegalArgumentException.class) | ||||||
| 	public void setAuthenticationEntryPointWhenNullThenException() { | 	public void setAuthenticationEntryPointWhenNullThenException() { | ||||||
| 		this.filter.setServerAuthenticationEntryPoint(null); | 		this.filter.setAuthenticationEntryPoint(null); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue