Search in sources :

Example 16 with AuthenticationEntryPoint

use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.

the class DefaultLoginPageConfigurer method configure.

@Override
@SuppressWarnings("unchecked")
public void configure(H http) {
    AuthenticationEntryPoint authenticationEntryPoint = null;
    ExceptionHandlingConfigurer<?> exceptionConf = http.getConfigurer(ExceptionHandlingConfigurer.class);
    if (exceptionConf != null) {
        authenticationEntryPoint = exceptionConf.getAuthenticationEntryPoint();
    }
    if (this.loginPageGeneratingFilter.isEnabled() && authenticationEntryPoint == null) {
        this.loginPageGeneratingFilter = postProcess(this.loginPageGeneratingFilter);
        http.addFilter(this.loginPageGeneratingFilter);
        LogoutConfigurer<H> logoutConfigurer = http.getConfigurer(LogoutConfigurer.class);
        if (logoutConfigurer != null) {
            http.addFilter(this.logoutPageGeneratingFilter);
        }
    }
}
Also used : AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint)

Example 17 with AuthenticationEntryPoint

use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.

the class MiscHttpConfigTests method requestWhenCustomHttpBasicEntryPointRefThenInvokesOnCommence.

@Test
public void requestWhenCustomHttpBasicEntryPointRefThenInvokesOnCommence() throws Exception {
    this.spring.configLocations(xml("CustomHttpBasicEntryPointRef")).autowire();
    AuthenticationEntryPoint entryPoint = this.spring.getContext().getBean(AuthenticationEntryPoint.class);
    // @formatter:off
    this.mvc.perform(get("/protected")).andExpect(status().isOk());
    // @formatter:on
    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 18 with AuthenticationEntryPoint

use of org.springframework.security.web.AuthenticationEntryPoint in project pivotal-cla by pivotalsoftware.

the class SecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    AuthenticationEntryPoint entryPoint = entryPoint();
    AdminRequestedAccessDeniedHandler accessDeniedHandler = new AdminRequestedAccessDeniedHandler(entryPoint);
    http.requiresChannel().requestMatchers(request -> request.getHeader("x-forwarded-port") != null).requiresSecure().and().exceptionHandling().authenticationEntryPoint(entryPoint).accessDeniedHandler(accessDeniedHandler).and().csrf().ignoringAntMatchers("/github/hooks/**").and().authorizeRequests().requestMatchers(CorsUtils::isPreFlightRequest).permitAll().mvcMatchers("/login/**", "/", "/about", "/faq").permitAll().mvcMatchers("/view/**").permitAll().mvcMatchers("/webjars/**", "/assets/**").permitAll().mvcMatchers("/github/hooks/**").permitAll().mvcMatchers("/admin", "/admin/cla/link/**", "/admin/help/**").hasRole("ADMIN").mvcMatchers("/admin/**", "/manage/**").hasRole("CLA_AUTHOR").anyRequest().authenticated().and().logout().logoutSuccessUrl("/?logout");
}
Also used : ServletException(javax.servlet.ServletException) Autowired(org.springframework.beans.factory.annotation.Autowired) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) AccessDeniedHandlerImpl(org.springframework.security.web.access.AccessDeniedHandlerImpl) LinkedHashMap(java.util.LinkedHashMap) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) HttpServletRequest(javax.servlet.http.HttpServletRequest) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) BasicAuthenticationEntryPoint(org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) GitHubAuthenticationEntryPoint(io.pivotal.cla.security.GitHubAuthenticationEntryPoint) CorsUtils(org.springframework.web.cors.CorsUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) AccessDeniedHandler(org.springframework.security.web.access.AccessDeniedHandler) User(io.pivotal.cla.data.User) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) EnableGlobalMethodSecurity(org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) HttpStatusEntryPoint(org.springframework.security.web.authentication.HttpStatusEntryPoint) HttpStatus(org.springframework.http.HttpStatus) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) Authentication(org.springframework.security.core.Authentication) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) CorsUtils(org.springframework.web.cors.CorsUtils) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) BasicAuthenticationEntryPoint(org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint) GitHubAuthenticationEntryPoint(io.pivotal.cla.security.GitHubAuthenticationEntryPoint) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint)

Example 19 with AuthenticationEntryPoint

use of org.springframework.security.web.AuthenticationEntryPoint in project pivotal-cla by pivotalsoftware.

the class SecurityConfig method entryPoint.

private AuthenticationEntryPoint entryPoint() {
    LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>();
    entryPoints.put(new AntPathRequestMatcher("/github/hooks/**"), new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));
    entryPoints.put(new AntPathRequestMatcher("/admin/**"), new GitHubAuthenticationEntryPoint(oauthConfig.getMain(), "user:email,repo:status,admin:repo_hook,admin:org_hook,read:org"));
    BasicAuthenticationEntryPoint basicEntryPoint = new BasicAuthenticationEntryPoint();
    basicEntryPoint.setRealmName("Pivotal CLA");
    entryPoints.put(new AntPathRequestMatcher("/manage/**"), basicEntryPoint);
    DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint(entryPoints);
    entryPoint.setDefaultEntryPoint(new GitHubAuthenticationEntryPoint(oauthConfig.getMain(), "user:email"));
    return entryPoint;
}
Also used : HttpStatusEntryPoint(org.springframework.security.web.authentication.HttpStatusEntryPoint) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) GitHubAuthenticationEntryPoint(io.pivotal.cla.security.GitHubAuthenticationEntryPoint) BasicAuthenticationEntryPoint(org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint) AntPathRequestMatcher(org.springframework.security.web.util.matcher.AntPathRequestMatcher) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) BasicAuthenticationEntryPoint(org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint) GitHubAuthenticationEntryPoint(io.pivotal.cla.security.GitHubAuthenticationEntryPoint) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) LinkedHashMap(java.util.LinkedHashMap)

Example 20 with AuthenticationEntryPoint

use of org.springframework.security.web.AuthenticationEntryPoint in project spring-security by spring-projects.

the class DelegatingAuthenticationEntryPointTests method testFirstEntryPoint.

@Test
public void testFirstEntryPoint() throws Exception {
    AuthenticationEntryPoint firstAEP = mock(AuthenticationEntryPoint.class);
    RequestMatcher firstRM = mock(RequestMatcher.class);
    AuthenticationEntryPoint secondAEP = mock(AuthenticationEntryPoint.class);
    RequestMatcher secondRM = mock(RequestMatcher.class);
    given(firstRM.matches(this.request)).willReturn(true);
    this.entryPoints.put(firstRM, firstAEP);
    this.entryPoints.put(secondRM, secondAEP);
    this.daep.commence(this.request, null, null);
    verify(firstAEP).commence(this.request, null, null);
    verify(secondAEP, never()).commence(this.request, null, null);
    verify(this.defaultEntryPoint, never()).commence(this.request, null, null);
    verify(secondRM, never()).matches(this.request);
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) Test(org.junit.jupiter.api.Test)

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