Spring security позволяет вам расширить org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
, который вы можете прекрасно использовать с весенней загрузкой, например:
, например
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers("/settings").hasAuthority("Administrator");
}
}
Если предположить, что ваш Принципал проходит проверку подлинности и помещен в контекст безопасности Spring, это должно вызвать обработчик отказа в доступе.
Вы можете настроить это следующим образом:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers("/settings").hasAuthority("Administrator").and()
.exceptionHandling()
.accessDeniedPage(...)
.accessDeniedHandler(...)
}
}
Где вы можете настроить либо страницу запрещенного доступа, либо пользовательский обработчик.