Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring security custom exception handler with preauth
    primarykey
    data
    text
    <p>I'm trying to configure some custom exception handling with Spring Security 3.1.2. I tried following the examples I found <a href="https://stackoverflow.com/questions/5094449/spring-exception-handler-to-not-handle-certain-types-of-exception">here</a> and <a href="http://rockycode.com/blog/custom-exception-handling-accessdeniedexception/" rel="nofollow noreferrer">here</a>, but neither works. I'm new to Spring Security, and I'm wondering if this might have something to do with the fact that I'm using a preauth filter. I'm throwing my custom exceptions from within the loadUserDetails() method of my AuthenticationUserDetailsService implementation.</p> <pre><code>public class AuthServiceImpl implements AuthenticationUserDetailsService&lt;Authentication&gt; { @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; } } </code></pre> <p>When the exception is thrown I just get the normal Tomcat 500 page with the exception details. For whatever reason my custom exceptions are not getting handled at all. I even added some println()s in the custom handler, and it's not even being called. </p> <p>I'm starting to wonder if this method is somehow excluded from Spring's exception handling. I can provide more code examples if needed, but at this point I'm not sure what would be relevant to share.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload