use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.
the class DelegatingAuthenticationEntryPointTests method testDefaultEntryPoint.
@Test
public void testDefaultEntryPoint() throws Exception {
AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
RequestMatcher firstRM = mock(RequestMatcher.class);
given(firstRM.matches(this.request)).willReturn(false);
this.entryPoints.put(firstRM, firstAEP);
this.daep.commence(this.request, null, null);
verify(this.defaultEntryPoint).commence(this.request, null, null);
verify(firstAEP, never()).commence(this.request, null, null);
}
use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.
the class MiscHttpConfigTests method getWhenUnauthenticatedThenUsesConfiguredAuthenticationEntryPoint.
@Test
public void getWhenUnauthenticatedThenUsesConfiguredAuthenticationEntryPoint() throws Exception {
this.spring.configLocations(xml("EntryPoint")).autowire();
AuthenticationEntryPoint entryPoint = this.spring.getContext().getBean(AuthenticationEntryPoint.class);
this.mvc.perform(get("/"));
verify(entryPoint).commence(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationException.class));
}
use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.
the class DefaultFilterChainValidatorTests method setUp.
@BeforeEach
public void setUp() {
AnonymousAuthenticationFilter aaf = new AnonymousAuthenticationFilter("anonymous");
this.fsi = new FilterSecurityInterceptor();
this.fsi.setAccessDecisionManager(this.accessDecisionManager);
this.fsi.setSecurityMetadataSource(this.metadataSource);
AuthenticationEntryPoint authenticationEntryPoint = new LoginUrlAuthenticationEntryPoint("/login");
ExceptionTranslationFilter etf = new ExceptionTranslationFilter(authenticationEntryPoint);
DefaultSecurityFilterChain securityChain = new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE, aaf, etf, this.fsi);
this.fcp = new FilterChainProxy(securityChain);
this.validator = new DefaultFilterChainValidator();
ReflectionTestUtils.setField(this.validator, "logger", this.logger);
}
use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.
the class DelegatingAuthenticationEntryPoint method commence.
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
for (RequestMatcher requestMatcher : this.entryPoints.keySet()) {
logger.debug(LogMessage.format("Trying to match using %s", requestMatcher));
if (requestMatcher.matches(request)) {
AuthenticationEntryPoint entryPoint = this.entryPoints.get(requestMatcher);
logger.debug(LogMessage.format("Match found! Executing %s", entryPoint));
entryPoint.commence(request, response, authException);
return;
}
}
logger.debug(LogMessage.format("No match found. Using default entry point %s", this.defaultEntryPoint));
// No EntryPoint matched, use defaultEntryPoint
this.defaultEntryPoint.commence(request, response, authException);
}
use of org.springframework.security.web.AuthenticationEntryPoint in project midpoint by Evolveum.
the class MidpointExceptionHandlingConfigurer method configure.
@Override
public void configure(H http) throws Exception {
AuthenticationEntryPoint entryPoint = getAuthenticationEntryPoint();
ExceptionTranslationFilter exceptionTranslationFilter = new MidpointExceptionTranslationFilter(entryPoint, getRequestCache(http)) {
@Override
protected Authentication createNewAuthentication(AnonymousAuthenticationToken authentication) {
return MidpointExceptionHandlingConfigurer.this.createNewAuthentication(authentication);
}
};
AccessDeniedHandler deniedHandler = getAccessDeniedHandler();
exceptionTranslationFilter.setAccessDeniedHandler(deniedHandler);
exceptionTranslationFilter.setAuthenticationTrustResolver(getAuthenticationTrustResolver());
exceptionTranslationFilter = postProcess(exceptionTranslationFilter);
http.addFilterAfter(exceptionTranslationFilter, MidpointAnonymousAuthenticationFilter.class);
}
Aggregations