【发布时间】:2013-02-03 15:25:02
【问题描述】:
我正在尝试使用 Spring Security 3.1.2 配置一些自定义异常处理。我尝试按照我找到的here 和here 的示例进行操作,但都不起作用。我是 Spring Security 的新手,我想知道这是否与我使用 preauth 过滤器的事实有关。我在 AuthenticationUserDetailsService 实现的 loadUserDetails() 方法中抛出了我的自定义异常。
public class AuthServiceImpl implements AuthenticationUserDetailsService<Authentication> {
@Autowired
private AuthDao authDao;
@Override
public UserDetails loadUserDetails(Authentication auth) throws UsernameNotFoundException {
Request req = (Request) auth.getPrincipal();
//get user details
User u = authDao.loadUser(req.getSessionId());
//check user rights for requested action
if(!u.getRights().contains(req.getAction()){
throw new CustomAuthException("User does not have permission to perform this action");
}
return u;
}
}
当异常被抛出时,我只会得到带有异常详细信息的正常 Tomcat 500 页面。无论出于何种原因,我的自定义异常都没有得到处理。我什至在自定义处理程序中添加了一些 println(),它甚至没有被调用。
我开始怀疑这个方法是否以某种方式被排除在 Spring 的异常处理之外。如果需要,我可以提供更多代码示例,但目前我不确定要分享什么。
【问题讨论】:
-
你能说一下是什么不工作吗?
-
@TheZuck 我已经编辑了我的问题,以便更具体地解决我的问题
标签: java spring spring-mvc spring-security