Search in sources :

Example 6 with AuthenticationEntryPoint

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);
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) Test(org.junit.jupiter.api.Test)

Example 7 with AuthenticationEntryPoint

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));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) AuthenticationException(org.springframework.security.core.AuthenticationException) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 8 with AuthenticationEntryPoint

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);
}
Also used : FilterChainProxy(org.springframework.security.web.FilterChainProxy) AnonymousAuthenticationFilter(org.springframework.security.web.authentication.AnonymousAuthenticationFilter) FilterSecurityInterceptor(org.springframework.security.web.access.intercept.FilterSecurityInterceptor) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) LoginUrlAuthenticationEntryPoint(org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint) ExceptionTranslationFilter(org.springframework.security.web.access.ExceptionTranslationFilter) LoginUrlAuthenticationEntryPoint(org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint) DefaultSecurityFilterChain(org.springframework.security.web.DefaultSecurityFilterChain) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with AuthenticationEntryPoint

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);
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint)

Example 10 with AuthenticationEntryPoint

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);
}
Also used : AccessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler) RequestMatcherDelegatingAccessDeniedHandler(org.springframework.security.web.access.RequestMatcherDelegatingAccessDeniedHandler) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) MidpointExceptionTranslationFilter(com.evolveum.midpoint.authentication.impl.filter.MidpointExceptionTranslationFilter) ExceptionTranslationFilter(org.springframework.security.web.access.ExceptionTranslationFilter) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointExceptionTranslationFilter(com.evolveum.midpoint.authentication.impl.filter.MidpointExceptionTranslationFilter)

Aggregations

AuthenticationEntryPoint (org.springframework.security.web.AuthenticationEntryPoint)20 RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)11 DelegatingAuthenticationEntryPoint (org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint)9 LinkedHashMap (java.util.LinkedHashMap)6 Test (org.junit.jupiter.api.Test)5 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)5 RequestHeaderRequestMatcher (org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher)5 LoginUrlAuthenticationEntryPoint (org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint)4 BasicAuthenticationEntryPoint (org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint)4 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 ExceptionTranslationFilter (org.springframework.security.web.access.ExceptionTranslationFilter)3 AndRequestMatcher (org.springframework.security.web.util.matcher.AndRequestMatcher)3 NegatedRequestMatcher (org.springframework.security.web.util.matcher.NegatedRequestMatcher)3 OrRequestMatcher (org.springframework.security.web.util.matcher.OrRequestMatcher)3 GitHubAuthenticationEntryPoint (io.pivotal.cla.security.GitHubAuthenticationEntryPoint)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2