/** 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)); } Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority("ROLE_USER")); User userDetails = new User(user.getUserName(), user.getPassword(), authorities); return userDetails; }
/** * Create user - persist to database * * @param userEntity * @return true if success */ public boolean createUser(UserEntity userEntity) { if (!userDao.checkAvailable(userEntity.getUserName())) { FacesMessage message = constructErrorMessage( String.format( getMessageBundle().getString("userExistsMsg"), userEntity.getUserName()), null); getFacesContext().addMessage(null, message); return false; } try { userDao.save(userEntity); } catch (Exception e) { FacesMessage message = constructFatalMessage(e.getMessage(), null); getFacesContext().addMessage(null, message); return false; } return true; }