class AmbariLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator {

  @Override
  public Collection<? extends GrantedAuthority> getGrantedAuthorities(DirContextOperations userData, String username) {
    username = AuthorizationHelper.resolveLoginAliasToUserName(username);

    log.info("Get authorities for user " + username + " from local DB");

    UserEntity user;

    user = userDAO.findUserByName(username);
    
    if (user == null) {
      log.error("Can't get authorities for user " + username + ", he is not present in local DB");
      return Collections.emptyList();
    }
    if(!user.getActive()){
      throw new InvalidUsernamePasswordCombinationException(username);
    }

    Collection<PrivilegeEntity> privilegeEntities = users.getUserPrivileges(user);

    return authorizationHelper.convertPrivilegesToAuthorities(privilegeEntities);
  }

  @Inject public  AmbariLdapAuthoritiesPopulator(AuthorizationHelper authorizationHelper,
                                        UserDAO userDAO, MemberDAO memberDAO, PrivilegeDAO privilegeDAO,
                                        Users users);

}