我想用Spring Security 3.1.2配置一些自定義異常處理。我試着按照我發現的例子here和here,但都不起作用。我是Spring Security的新手,我想知道這是否與我使用預過濾器的事實有關。我從我的AuthenticationUserDetailsService實現的loadUserDetails()方法中拋出自定義異常。彈出安全性自定義異常處理程序preauth
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
@TheZuck我編輯了我的問題,以更具體地處理我的問題 – monitorjbl