【发布时间】:2016-08-06 02:59:52
【问题描述】:
在 AngularJS 网络应用程序中,如何为 403 http 响应显示自定义错误消息/页面。
我使用 Spring 安全性并检查用户是否具有适当的角色。如果他没有角色,则应用程序返回 http 错误代码 403。
目前在这种情况下我没有显示任何错误消息/页面。并想实现这一点。我们该怎么做呢?
Spring Boot java 代码
http.httpBasic()
.and()
.authorizeRequests()
// Permit these resources
.antMatchers("/login", "/4_security/login.html", "/bower_components/**", "/4_security/*.js", "/")
.permitAll()
// URL based Authorization control
.antMatchers("/1_reportingEntities/*.html").hasAnyAuthority(authorities)
// All other requests needs authentication
.anyRequest().authenticated()
// Access denied page (403 error)
.and().exceptionHandling().accessDeniedPage("/0_common/accessDenied.html")
.and()
// CSRF protection
.csrf().csrfTokenRepository(csrfTokenRepository()).and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class);
【问题讨论】:
标签: java angularjs spring-security