Package ch.inftec.ju.db.auth.entity

Examples of ch.inftec.ju.db.auth.entity.AuthUser


   
    this.refresh();
  }
 
  public void createUser(String userName, String password) {
    AuthUser newUser = this.model.addUser(userName, password);
    addUserInfo(newUser);
  }
View Full Code Here


    TestUtils.assertCollectionEquals(this.authModel.getUserNames(), "user1");
    // Check the role of the first user
    TestUtils.assertCollectionEquals(this.authModel.getRoles(u1.get(0)), "role1");
   
    // Add a new user
    AuthUser u2 = this.authModel.addUser("newUser", "password");
    TestUtils.assertCollectionEquals(this.authModel.getUserNames(), "newUser", "user1");
   
    // Make sure it doesn't have any roles
    Assert.assertEquals(0, this.authModel.getRoles(u2).size());
   
View Full Code Here

  @Autowired
  private AuthenticationEditorModel authenticationEditorModel;
 
  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    AuthUser authUser = null;
    boolean noDbConn = false;
    try {
      authUser = this.authenticationEditorModel.getUser(username);
    } catch (TransactionException ex) {
      logger.warn(String.format("Couldn't get authentication info for user %s from DB", username), ex);
      noDbConn = true;
    }
   
    if (authUser == null) {
      if (this.unknownUserHandler != null) {
        // Check whether the user should be added
        NewUserInfo newUserInfo = this.unknownUserHandler.handleUser(username);
        if (newUserInfo != null) {
          if (!noDbConn) {
            // Create the user on the DB
            authUser = this.authenticationEditorModel.addUser(username, newUserInfo.getPassword(), newUserInfo.getAuthorities());
          } else {
            // No DB connectivity, so just return user as defined by UnknownUserHandler
            newUserInfo.getAuthorities();
           
            List<GrantedAuthority> grantedAuths = new ArrayList<>();
            for (String role : newUserInfo.getAuthorities()) {
              grantedAuths.add(new SimpleGrantedAuthority(role));
            }
            return new User(username, newUserInfo.getPassword(), grantedAuths);           
          }
        }
      }
     
      if (authUser == null) {
        throw new UsernameNotFoundException("No such user: " + username);
      }
    } else {
      this.authenticationEditorModel.updateLoginCount(authUser);
    }
   
    List<GrantedAuthority> grantedAuths = new ArrayList<>();
    for (AuthRole authRole : authUser.getRoles()) {
      grantedAuths.add(new SimpleGrantedAuthority(authRole.getName()));
    }
   
    User user = new User(username, authUser.getPassword(), grantedAuths);
   
    return user;
  }
View Full Code Here

  @Autowired
  private AuthenticationEditorModel authenticationEditorModel;
 
  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    AuthUser authUser = this.authenticationEditorModel.getUser(username);
   
    if (authUser == null) {
      if (this.unknownUserHandler != null) {
        // Check whether the user should be added
        NewUserInfo newUserInfo = this.unknownUserHandler.handleUser(username);
        if (newUserInfo != null) {
          // Create the user
          authUser = this.authenticationEditorModel.addUser(username, newUserInfo.getPassword(), newUserInfo.getAuthorities());
        }
      }
     
      if (authUser == null) {
        throw new UsernameNotFoundException("No such user: " + username);
      }
    } else {
      this.authenticationEditorModel.updateLoginCount(authUser);
    }
   
    List<GrantedAuthority> grantedAuths = new ArrayList<>();
    for (AuthRole authRole : authUser.getRoles()) {
      grantedAuths.add(new SimpleGrantedAuthority(authRole.getName()));
    }
   
    User user = new User(username, authUser.getPassword(), grantedAuths);
   
    return user;
  }
View Full Code Here

    if (password == null) {
      throw new JuRuntimeException("Password must not be null");
    }
   
   
    AuthUser newUser = new AuthUser();
    newUser.setName(userName);
    newUser.setPassword(password);
    newUser.setLoginCount(1);
    newUser.setLastLogin(new Date());
   
    this.userRepo.save(newUser);
   
    return newUser;
  }
View Full Code Here

  /**
   * Delete the specified user
   * @param userName User name
   */
  public void deleteUser(String userName) {
    AuthUser user = this.getUser(userName);
    if (user != null) {
      this.userRepo.delete(user);
    }
  }
View Full Code Here

   * @param password Password (non-null)
   * @param roles roles to be assigned
   * @return Added user
   */
  public AuthUser addUser(String userName, String password, List<String> roles) {
    AuthUser authUser = addUser(userName, password);
    setRoles(authUser, roles);
   
    return authUser;
  }
View Full Code Here

TOP

Related Classes of ch.inftec.ju.db.auth.entity.AuthUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.