Package org.apache.ambari.server.orm.entities

Examples of org.apache.ambari.server.orm.entities.UserEntity


  @Test(expected = AmbariException.class)
  public void testModifyPassword() throws Exception {
    users.createUser("user", "user");

    UserEntity userEntity = userDAO.findLocalUserByName("user");

    assertNotSame("user", userEntity.getUserPassword());
    assertTrue(passwordEncoder.matches("user", userEntity.getUserPassword()));

    users.modifyPassword("user", "admin", "user_new_password");

    assertTrue("user_new_password".equals(userDAO.findLocalUserByName("user").getUserPassword()));
View Full Code Here


  }

  private void createLdapUser() {
    RoleEntity role = roleDAO.findByName(users.getUserRole());
    UserEntity ldapUser = new UserEntity();

    ldapUser.setUserName("ldapUser");
    ldapUser.setLdapUser(true);

    userDAO.create(ldapUser);

    UserEntity userEntity = userDAO.findLdapUserByName("ldapUser");

    userEntity.getRoleEntities().add(role);
    role.getUserEntities().add(ldapUser);

    userDAO.merge(ldapUser);
    roleDAO.merge(role);
  }
View Full Code Here

    authentication =
        new UsernamePasswordAuthenticationToken("allowedAdmin", "password");
    Authentication result = authenticationProvider.authenticate(authentication);
    assertTrue(result.isAuthenticated());

    UserEntity allowedAdminEntity = userDAO.findLdapUserByName("allowedAdmin");

    authentication =
        new UsernamePasswordAuthenticationToken("allowedUser", "password");
    authenticationProvider.authenticate(authentication);
    UserEntity allowedUserEntity = userDAO.findLdapUserByName("allowedUser");


    RoleEntity adminRole = roleDAO.findByName(
        configuration.getConfigsMap().get(Configuration.ADMIN_ROLE_NAME_KEY));
    RoleEntity userRole = roleDAO.findByName(
        configuration.getConfigsMap().get(Configuration.USER_ROLE_NAME_KEY));


    assertTrue(allowedAdminEntity.getRoleEntities().contains(userRole));
    assertTrue(allowedAdminEntity.getRoleEntities().contains(adminRole));

    assertTrue(allowedUserEntity.getRoleEntities().contains(userRole));
    assertFalse(allowedUserEntity.getRoleEntities().contains(adminRole));


  }
View Full Code Here

    userDetailsService.loadUserByUsername("notExists_123123123");
  }

  @Test(expected = UsernameNotFoundException.class)
  public void testEmptyRoles() throws Exception {
    UserEntity user = userDAO.findLocalUserByName("userWithoutRoles");
    userDetailsService.loadUserByUsername(user.getUserName());
  }
View Full Code Here

  @Override
  public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
    log.info("Get roles for user " + username + " from local DB");

    UserEntity user;

    user = userDAO.findLdapUserByName(username);

    if (user == null) {
      log.info("User " + username + " not present in local DB - creating");

      createLdapUser(username);
      user = userDAO.findLdapUserByName(username);
    }

    //don't remove admin role from user if group mapping was not configured
    if (configuration.getLdapServerProperties().isGroupMappingEnabled()) {
      //Adding an "admin" user role if user is a member of ambari administrators
      // LDAP group
      Boolean isAdmin =
          (Boolean) userData.getObjectAttribute(AMBARI_ADMIN_LDAP_ATTRIBUTE_KEY);
      if ((isAdmin != null) && isAdmin) {
        log.info("Adding admin role to LDAP user " + username);
        addRole(user, configuration.getConfigsMap().
            get(Configuration.ADMIN_ROLE_NAME_KEY));
      } else {
        removeRole(user, configuration.getConfigsMap().
            get(Configuration.ADMIN_ROLE_NAME_KEY));
      }
    }

    return authorizationHelper.convertRolesToAuthorities(user.getRoleEntities());
  }
View Full Code Here

   * Creates record in local DB for LDAP user
   * @param username - name of user to create
   */
  @Transactional
  void createLdapUser(String username) {
    UserEntity newUser = new UserEntity();
    newUser.setLdapUser(true);
    newUser.setUserName(username);

    userDAO.create(newUser);

    //Adding a default "user" role
    addRole(newUser, configuration.getConfigsMap().
View Full Code Here

      roleEntity.setRoleName(roleName);
      roleDAO.create(roleEntity);
      roleEntity = roleDAO.findByName(roleEntity.getRoleName());
    }

    UserEntity userEntity = userDAO.findLdapUserByName(user.getUserName());
    if (userEntity == null) {
      userDAO.create(user);
      userEntity = userDAO.findLdapUserByName(user.getUserName());
    }

    if (!userEntity.getRoleEntities().contains(roleEntity)) {
      userEntity.getRoleEntities().add(roleEntity);
      roleEntity.getUserEntities().add(userEntity);
      roleDAO.merge(roleEntity);
      userDAO.merge(userEntity);
    }
  }
View Full Code Here

   * @param user
   * @param roleName
   */
  @Transactional
  void removeRole(UserEntity user, String roleName) {
    UserEntity userEntity = userDAO.findByPK(user.getUserId());
    RoleEntity roleEntity = roleDAO.findByName(roleName);

    if (userEntity.getRoleEntities().contains(roleEntity)) {
      log.info("Removing admin role from LDAP user " + user.getUserName());
      userEntity.getRoleEntities().remove(roleEntity);
      roleEntity.getUserEntities().remove(userEntity);
      userDAO.merge(userEntity);
      roleDAO.merge(roleEntity);
    }

View Full Code Here

    return users;
  }

  public User getUser(int userId) throws AmbariException {
    UserEntity userEntity = userDAO.findByPK(userId);
    if (userEntity != null) {
      return new User(userEntity);
    } else {
      throw new AmbariException("User with id '" + userId + " not found");
    }
View Full Code Here

      throw new AmbariException("User with id '" + userId + " not found");
    }
  }

  public User getAnyUser(String userName) {
    UserEntity userEntity = userDAO.findLdapUserByName(userName);
    if (null == userEntity) {
      userEntity = userDAO.findLocalUserByName(userName);
    }

    return (null == userEntity) ? null : new User(userEntity);
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.orm.entities.UserEntity

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.