Package org.apache.ambari.server

Examples of org.apache.ambari.server.AmbariException


              + ", clusterId=" + cluster.getClusterId()
              + ", serviceName=" + getName()
              + ", serviceComponentName=" + component.getName());
        }
        if (components.containsKey(component.getName())) {
          throw new AmbariException("Cannot add duplicate ServiceComponent"
              + ", clusterName=" + cluster.getClusterName()
              + ", clusterId=" + cluster.getClusterId()
              + ", serviceName=" + getName()
              + ", serviceComponentName=" + component.getName());
        }
View Full Code Here


              + ", clusterId=" + cluster.getClusterId()
              + ", serviceName=" + getName()
              + ", serviceComponentName=" + serviceComponentName);
        }
        if (components.containsKey(serviceComponentName)) {
          throw new AmbariException("Cannot add duplicate ServiceComponent"
              + ", clusterName=" + cluster.getClusterName()
              + ", clusterId=" + cluster.getClusterId()
              + ", serviceName=" + getName()
              + ", serviceComponentName=" + serviceComponentName);
        }
View Full Code Here

            + ", clusterName=" + cluster.getClusterName()
            + ", serviceName=" + getName());
        // FIXME check dependencies from meta layer
        for (ServiceComponent component : components.values()) {
          if (!component.canBeRemoved()) {
            throw new AmbariException("Found non removable component when trying to"
                + " delete all components from service"
                + ", clusterName=" + cluster.getClusterName()
                + ", serviceName=" + getName()
                + ", componentName=" + component.getName());
          }
View Full Code Here

            + ", clusterName=" + cluster.getClusterName()
            + ", serviceName=" + getName()
            + ", componentName=" + componentName);
        // FIXME check dependencies from meta layer
        if (!component.canBeRemoved()) {
          throw new AmbariException("Could not delete component from cluster"
              + ", clusterName=" + cluster.getClusterName()
              + ", serviceName=" + getName()
              + ", componentName=" + componentName);
        }
View Full Code Here

  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

  }

  public User getLocalUser(String userName) throws AmbariException{
    UserEntity userEntity = userDAO.findLocalUserByName(userName);
    if (userEntity == null) {
      throw new AmbariException("User doesn't exist");
    }
    return new User(userEntity);
  }
View Full Code Here

  }

  public User getLdapUser(String userName) throws AmbariException{
    UserEntity userEntity = userDAO.findLdapUserByName(userName);
    if (userEntity == null) {
      throw new AmbariException("User doesn't exist");
    }
    return new User(userEntity);
  }
View Full Code Here

  public synchronized void modifyPassword(String userName, String currentUserPassword, String newPassword) throws AmbariException {

    SecurityContext securityContext = SecurityContextHolder.getContext();
    String currentUserName = securityContext.getAuthentication().getName();
    if (currentUserName == null) {
      throw new AmbariException("Authentication required. Please sign in.");
    }

    UserEntity currentUserEntity = userDAO.findLocalUserByName(currentUserName);

    //Authenticate LDAP admin user
    boolean isLdapAdmin = false;
    if (currentUserEntity == null) {
      currentUserEntity = userDAO.findLdapUserByName(currentUserName);
      try {
        ldapAuthenticationProvider.authenticate(
            new UsernamePasswordAuthenticationToken(currentUserName, currentUserPassword));
      isLdapAdmin = true;
      } catch (BadCredentialsException ex) {
        throw new AmbariException("Incorrect password provided for LDAP user " +
            currentUserName);
      }
    }

    UserEntity userEntity = userDAO.findLocalUserByName(userName);

    if ((userEntity != null) && (currentUserEntity != null)) {
      if (isLdapAdmin || passwordEncoder.matches(currentUserPassword, currentUserEntity.getUserPassword())) {
        userEntity.setUserPassword(passwordEncoder.encode(newPassword));
        userDAO.merge(userEntity);
      } else {
        throw new AmbariException("Wrong password provided");
      }

    } else {
      userEntity = userDAO.findLdapUserByName(userName);
      if (userEntity != null) {
        throw new AmbariException("Password of LDAP user cannot be modified");
      } else {
        throw new AmbariException("User " + userName + " not found");
      }
    }
  }
View Full Code Here

  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

      throws AmbariException {

    if (userDAO.findLdapUserByName(user.getUserName()) != null) {
      LOG.warn("Trying to add a role to the LDAP user"
          + ", user=" + user.getUserName());
      throw new AmbariException("Roles are not editable for LDAP users");
    }

    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

TOP

Related Classes of org.apache.ambari.server.AmbariException

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.