Exemplo n.º 1
0
  @Transactional(readOnly = true)
  public UserDetails loadUserByUsername(String login)
      throws UsernameNotFoundException, DataAccessException {

    TenderUser userEntity = userDao.getUser(login);
    if (null == userEntity) {
      throw new UsernameNotFoundException("user not found in database");
    }

    String userName = userEntity.getUsername();
    String password = userEntity.getPassword();
    boolean enabled = true;
    boolean accountNonExpired = true;
    boolean credentialsNonExpired = true;
    boolean accountNonLocked = true;
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    authorities.add(new GrantedAuthorityImpl(userEntity.getRole()));

    User springSecurityUser =
        new User(
            userName,
            password,
            enabled,
            accountNonExpired,
            credentialsNonExpired,
            accountNonLocked,
            authorities);

    return springSecurityUser;
  }