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

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


    roleDAO.merge(roleEntity);
  }

  @Transactional
  public synchronized void removeUser(User user) throws AmbariException {
    UserEntity userEntity = userDAO.findByPK(user.getUserId());
    if (userEntity != null) {
      userDAO.remove(userEntity);
    } else {
      throw new AmbariException("User " + user + " doesn't exist");
    }
View Full Code Here


  @Transactional
  public synchronized void addRoleToUser(User user, String role)
      throws AmbariException {

    UserEntity userEntity = userDAO.findByPK(user.getUserId());
    if (userEntity == null) {
      throw new AmbariException("User " + user + " doesn't exist");
    }

    RoleEntity roleEntity = roleDAO.findByName(role);
    if (roleEntity == null) {
      LOG.warn("Trying to add user to non-existent role"
          + ", user=" + user.getUserName()
          + ", role=" + role);
      throw new AmbariException("Role " + role + " doesn't exist");
    }

    if (!userEntity.getRoleEntities().contains(roleEntity)) {
      userEntity.getRoleEntities().add(roleEntity);
      roleEntity.getUserEntities().add(userEntity);
      userDAO.merge(userEntity);
      roleDAO.merge(roleEntity);
    } else {
      throw new AmbariException("User " + user + " already owns role " + role);
View Full Code Here

  }

  @Transactional
  public synchronized void removeRoleFromUser(User user, String role)
      throws AmbariException {
    UserEntity userEntity = userDAO.findByPK(user.getUserId());
    if (userEntity == null) {
      throw new AmbariException("User " + user + " doesn't exist");
    }

    RoleEntity roleEntity = roleDAO.findByName(role);
    if (roleEntity == null) {
      throw new AmbariException("Role " + role + " doesn't exist");
    }

    if (userEntity.getRoleEntities().contains(roleEntity)) {
      userEntity.getRoleEntities().remove(roleEntity);
      roleEntity.getUserEntities().remove(userEntity);
      userDAO.merge(userEntity);
      roleDAO.merge(roleEntity);
    } else {
      throw new AmbariException("User " + user + " doesn't own role " + role);
View Full Code Here

      assertEquals(false, user.isLdapUser());
    }

    assertEquals(2, userDAO.findAll().size());

    UserEntity userEntity = userDAO.findLocalUserByName("user");
    assertNotNull("user", userEntity.getUserPassword());

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

    assertNotSame(userEntity.getUserPassword(), userDAO.findLocalUserByName("user").getUserPassword());
  }
View Full Code Here

  @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

    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

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

    UserEntity user = null;

    user = userDAO.findLdapUserByName(username);

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

      UserEntity newUser = new UserEntity();
      newUser.setLdapUser(true);
      newUser.setUserName(username);

      //Adding a default "user" role
      addRole(newUser, configuration.getConfigsMap().
          get(Configuration.USER_ROLE_NAME_KEY));
    }
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

   * Remove role "roleName" from user "user"
   * @param user
   * @param roleName
   */
  private 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

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.