Example usage for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException

List of usage examples for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException

Introduction

In this page you can find the example usage for org.springframework.security.core.userdetails UsernameNotFoundException UsernameNotFoundException.

Prototype

public UsernameNotFoundException(String msg, Throwable t) 

Source Link

Document

Constructs a UsernameNotFoundException with the specified message and root cause.

Usage

From source file:sample.service.impl.UserServiceImpl.java

public UserDetails loadUserByUsername(String username) throws AuthenticationException {
    try {//from  w w w.  j  av a2s  . co m
        User user = userDAO.findByUsername(username);

        return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
                true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER"));
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new UsernameNotFoundException("No matching account", e);
    }
}