Results 1 to 4 of 4

Thread: StackTrace instead of errorPage

  1. #1

    Default StackTrace instead of errorPage

    Hi,

    this is my code where I check if a user exists in the database. When I write a username correct and password wrong I get a page with an error description, as it is configured in spring-security.xml. But when there is no user in the database and an exception below is triggered I get an error page with a stack trace. How can I catch an exception, so it will display as it should (in a notice div on the login page).


    PHP Code:
    @Service("userDetailsService")
    public class 
    UserDetailsServiceImpl implements UserDetailsService {
        
        private static 
    Log logger LogFactory.getLog(UserDetailsServiceImpl.class);
        
        @
    Autowired
        
    private UserDetailsDao userDetailsDao;
        
        @
    Override
        
    @Transactional
        
    public UserDetails loadUserByUsername(String username)
                
    throws UsernameNotFoundExceptionDataAccessException {
            if (
    logger.isDebugEnabled()) {
                
    logger.debug("UserDetailsServiceImpl::getSystemUSer");
            }
            
            
    SystemUser systemUser this.userDetailsDao.findByUsername(username);
            if (
    systemUser != null) {
                return 
    systemUser;
            }
            throw new 
    AccessDeniedException("Access denied.");
        }
            

    Any help appreciated.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    As indicated in the javadoc of UserDetailsService your UserDetailsServiceImpl should be throwing a UsernameNotFoundException if the user is not found not an AccessDeniedException
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3

    Default

    Thanks that was it. Anyway, I'm throwing now an throw new UsernameNotFoundException("Access denied") but on the fron form I get Bad credentials message. Do I have to set something to allow my custom message?

  4. #4
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    You can use the SPRING_SECURITY_LAST_EXCEPTION session attribute to get this exception. You can then use the message on that exception to display a custom error message. Refer to the contacts sample application to see a JSP that does this.
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •