Ejemplo 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;
  }
Ejemplo n.º 2
0
  // TODO Запретить использовать для разных категорий одного пользователя
  @Transactional
  public void createOrUpdateUserForDivision(Division division) {
    TenderUser newUser = new TenderUser();
    newUser.setUsername(division.getManagerEmail());
    newUser.addRole("ROLE_USER");
    try {
      newUser.setPassword(hash(division.getManagerPassword()));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    int divId = division.getId();
    if (divId != 0) {
      // We are about to update existing division
      String oldUserName = divisionService.showDivision(divId).getManagerEmail();
      String newUserName = division.getManagerEmail();

      // Check if the user will be the same or not
      if (!newUserName.equals(oldUserName)) {
        userDao.deleteUser(oldUserName);
      }
    }
    userDao.storeUser(newUser);
  }
Ejemplo n.º 3
0
 @Transactional
 public void deleteUser(String username) {
   userDao.deleteUser(username);
 }