/** Construct UserDetails instance required by spring security */ public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { UserEntity user = userDao.loadUserByUserName(userName); if (user == null) { throw new UsernameNotFoundException( String.format(getMessageBundle().getString("badCredentials"), userName)); } // Just one simple authority, basically it should be located in the additional table of database Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority("ROLE_USER")); User userDetails = new User(user.getUserName(), user.getPassword(), authorities); return userDetails; }
/** * Retrieves full User record from database by user name * * @param userName * @return UserEntity */ public UserEntity loadUserEntityByUsername(String userName) { return userDao.loadUserByUserName(userName); }