Как добавить обработчик отказа в доступе в spring -security-javaconfig

Я использую библиотеку spring -security-javaconfig для безопасности spring. Если бы я использовал xml файлы конфигурации, я бы использовал что-то вроде этого, чтобы определить пользовательскую страницу Access Denied:

<http auto-config="true">
    <intercept-url pattern="/admin*" access="ROLE_ADMIN" />
    <access-denied-handler ref="accessDeniedHandler"/>
</http>

Вот мой класс конфигурации безопасности:

@Configuration
@EnableWebSecurity
public class SecurityConfigurator extends WebSecurityConfigurerAdapter {

    @Override
    protected void registerAuthentication(AuthenticationManagerBuilder auth)
            throws Exception {
        auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
        auth.inMemoryAuthentication().withUser("admin").password("password").roles("ADMIN");

    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeUrls().antMatchers( "/admin").hasRole("ADMIN");
    }
}

Ответ 1

Я предполагаю, что это должно сделать трюк:

HttpSecurity http = ...
http.exceptionHandling().accessDeniedHandler(myAccessDeniedHandler);