org.springframework.security.web.access.AccessDeniedHandlerImpl Java Examples

The following examples show how to use org.springframework.security.web.access.AccessDeniedHandlerImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSecurityBeanConfig.java    From webauthn4j-spring-security with Apache License 2.0 7 votes vote down vote up
@Bean
public AccessDeniedHandler accessDeniedHandler() {
    LinkedHashMap<Class<? extends AccessDeniedException>, AccessDeniedHandler> errorHandlers = new LinkedHashMap<>();

    // invalid csrf authenticator error handler
    AccessDeniedHandlerImpl invalidCsrfTokenErrorHandler = new AccessDeniedHandlerImpl();
    invalidCsrfTokenErrorHandler.setErrorPage("/api/status/403");
    errorHandlers.put(InvalidCsrfTokenException.class, invalidCsrfTokenErrorHandler);

    // missing csrf authenticator error handler
    AccessDeniedHandlerImpl missingCsrfTokenErrorHandler = new AccessDeniedHandlerImpl();
    missingCsrfTokenErrorHandler.setErrorPage("/api/status/403");
    errorHandlers.put(MissingCsrfTokenException.class, missingCsrfTokenErrorHandler);

    // default error handler
    AccessDeniedHandlerImpl defaultErrorHandler = new AccessDeniedHandlerImpl();
    defaultErrorHandler.setErrorPage("/api/status/403");

    return new DelegatingAccessDeniedHandler(errorHandlers, defaultErrorHandler);
}
 
Example #2
Source File: WebSecurityBeanConfig.java    From webauthn4j-spring-security with Apache License 2.0 6 votes vote down vote up
@Bean
public AccessDeniedHandler accessDeniedHandler() {
    LinkedHashMap<Class<? extends AccessDeniedException>, AccessDeniedHandler> errorHandlers = new LinkedHashMap<>();

    // invalid csrf authenticator error handler
    AccessDeniedHandlerImpl invalidCsrfTokenErrorHandler = new AccessDeniedHandlerImpl();
    invalidCsrfTokenErrorHandler.setErrorPage("/api/status/403");
    errorHandlers.put(InvalidCsrfTokenException.class, invalidCsrfTokenErrorHandler);

    // missing csrf authenticator error handler
    AccessDeniedHandlerImpl missingCsrfTokenErrorHandler = new AccessDeniedHandlerImpl();
    missingCsrfTokenErrorHandler.setErrorPage("/api/status/403");
    errorHandlers.put(MissingCsrfTokenException.class, missingCsrfTokenErrorHandler);

    // default error handler
    AccessDeniedHandlerImpl defaultErrorHandler = new AccessDeniedHandlerImpl();
    defaultErrorHandler.setErrorPage("/api/status/403");

    return new DelegatingAccessDeniedHandler(errorHandlers, defaultErrorHandler);
}
 
Example #3
Source File: SecurityConfig.java    From Spring with Apache License 2.0 5 votes vote down vote up
@Bean

    public ExceptionTranslationFilter exceptionTranslationFilter() {
        final AuthenticationEntryPoint loginUrlAuthenticationEntryPoint
                = new LoginUrlAuthenticationEntryPoint("/login.jsp");

        final AccessDeniedHandlerImpl accessDeniedHandlerImpl = new AccessDeniedHandlerImpl();
        accessDeniedHandlerImpl.setErrorPage("/accessDenied.jsp");

        final ExceptionTranslationFilter eTranslationFilter = new ExceptionTranslationFilter(loginUrlAuthenticationEntryPoint);
        eTranslationFilter.setAccessDeniedHandler(accessDeniedHandlerImpl);
        return eTranslationFilter;
    }
 
Example #4
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {

    http
            .csrf()
            .disable();
    http
            .addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
            .addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
    http
            .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/error").permitAll()
            .antMatchers("/saml/**").permitAll()
            .antMatchers("/css/**").permitAll()
            .anyRequest().authenticated();

    http
            .exceptionHandling().accessDeniedHandler(new AccessDeniedHandlerImpl())
            .authenticationEntryPoint(getAuthEntryPoint())
            .and()
            .formLogin()
            .loginProcessingUrl("/authenticate")
            .usernameParameter("username")
            .passwordParameter("password")
            .successHandler(new FormAuthSuccessHandler())
            .failureHandler(new SimpleUrlAuthenticationFailureHandler())
            .and()
            .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/")
            .permitAll();
}
 
Example #5
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 4 votes vote down vote up
@Bean
public AccessDeniedHandler nonRedirectingAccessDeniedHandler(){
    return new AccessDeniedHandlerImpl();
}
 
Example #6
Source File: AjaxSupportedAccessDeniedHandler.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public AjaxSupportedAccessDeniedHandler(){
	delegateAccessDeniedHandler = new AccessDeniedHandlerImpl();
}
 
Example #7
Source File: AjaxSupportedAccessDeniedHandler.java    From onetwo with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	AccessDeniedHandlerImpl adh = new AccessDeniedHandlerImpl();
	adh.setErrorPage(errorPage);
	this.delegateAccessDeniedHandler = adh;
}