@Test public void testIsUserCanBeRemoved() throws Exception { users.createUser("admin", "admin", UserType.LOCAL, true, true); users.createUser("admin222", "admin222", UserType.LOCAL, true, true); Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin"))); Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin222"))); users.removeUser(users.getAnyUser("admin222")); Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin"))); users.createUser("user", "user"); Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin"))); users.createUser("admin333", "admin333", UserType.LOCAL, true, true); Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin"))); Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin333"))); }
public synchronized boolean isUserCanBeRemoved(UserEntity userEntity) { List<PrincipalEntity> adminPrincipals = principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION); Set<UserEntity> userEntitysSet = new HashSet<UserEntity>(userDAO.findUsersByPrincipal(adminPrincipals)); return (userEntitysSet.contains(userEntity) && userEntitysSet.size() < 2) ? false : true; }
Users { public synchronized boolean isUserCanBeRemoved(UserEntity userEntity) { List<PrincipalEntity> adminPrincipals = principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION); Set<UserEntity> userEntitysSet = new HashSet<UserEntity>(userDAO.findUsersByPrincipal(adminPrincipals)); return (userEntitysSet.contains(userEntity) && userEntitysSet.size() < 2) ? false : true; } }
Users { public synchronized boolean isUserCanBeRemoved(UserEntity userEntity) { List<PrincipalEntity> adminPrincipals = principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION); Set<UserEntity> userEntitysSet = new HashSet<UserEntity>(userDAO.findUsersByPrincipal(adminPrincipals)); return (userEntitysSet.contains(userEntity) && userEntitysSet.size() < 2) ? false : true; }  }
Users { public synchronized boolean isUserCanBeRemoved(UserEntity userEntity) { List<PrincipalEntity> adminPrincipals = principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION); Set<UserEntity> userEntitysSet = new HashSet<UserEntity>(userDAO.findUsersByPrincipal(adminPrincipals)); return (userEntitysSet.contains(userEntity) && userEntitysSet.size() < 2) ? false : true; }  List<User> getAllUsers(); @Deprecated User getAnyUser(String userName); User getUser(String userName, UserType userType); User getUser(Integer userId); @Deprecated User getUserIfUnique(String userName); synchronized void modifyPassword(String userName, String currentUserPassword, String newPassword); synchronized void setUserActive(String userName, boolean active); synchronized void setUserLdap(String userName); synchronized void setGroupLdap(String groupName); void createUser(String userName, String password); synchronized void createUser(String userName, String password, UserType userType, Boolean active, Boolean
      admin); synchronized void removeUser(User user); Group getGroup(String groupName); Group getGroupByNameAndType(String groupName, GroupType groupType); Collection<User> getGroupMembers(String groupName); @Transactional synchronized void createGroup(String groupName, GroupType groupType); List<Group> getAllGroups(); List<String> getAllMembers(String groupName); @Transactional synchronized void removeGroup(Group group); synchronized void grantAdminPrivilege(Integer userId); synchronized void grantPrivilegeToGroup(Integer groupId, Long resourceId, ResourceType resourceType, String permissionName); synchronized void revokeAdminPrivilege(Integer userId); @Transactional synchronized void addMemberToGroup(String groupName, String userName); @Transactional synchronized void removeMemberFromGroup(String groupName, String userName); synchronized boolean isUserCanBeRemoved(UserEntity userEntity); void processLdapSync(LdapBatchDto batchInfo); Collection<PrivilegeEntity> getUserPrivileges(UserEntity userEntity); Collection<PrivilegeEntity> getGroupPrivileges(GroupEntity groupEntity); Collection<AmbariGrantedAuthority> getUserAuthorities(String userName, UserType userType); }
Users { public synchronized boolean isUserCanBeRemoved(UserEntity userEntity) { List<PrincipalEntity> adminPrincipals = principalDAO.findByPermissionId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION); Set<UserEntity> userEntitysSet = new HashSet<UserEntity>(userDAO.findUsersByPrincipal(adminPrincipals)); return (userEntitysSet.contains(userEntity) && userEntitysSet.size() < 2) ? false : true; }  List<User> getAllUsers(); @Deprecated User getAnyUser(String userName); User getUser(String userName, UserType userType); User getUser(Integer userId); @Deprecated User getUserIfUnique(String userName); synchronized void modifyPassword(String userName, String currentUserPassword, String newPassword); synchronized void setUserActive(String userName, boolean active); synchronized void setUserLdap(String userName); synchronized void setGroupLdap(String groupName); void createUser(String userName, String password); synchronized void createUser(String userName, String password, UserType userType, Boolean active, Boolean
      admin); synchronized void removeUser(User user); Group getGroup(String groupName); Group getGroupByNameAndType(String groupName, GroupType groupType); Collection<User> getGroupMembers(String groupName); @Transactional synchronized void createGroup(String groupName, GroupType groupType); List<Group> getAllGroups(); List<String> getAllMembers(String groupName); @Transactional synchronized void removeGroup(Group group); synchronized void grantAdminPrivilege(Integer userId); synchronized void grantPrivilegeToGroup(Integer groupId, Long resourceId, ResourceType resourceType, String permissionName); synchronized void revokeAdminPrivilege(Integer userId); @Transactional synchronized void addMemberToGroup(String groupName, String userName); @Transactional synchronized void removeMemberFromGroup(String groupName, String userName); synchronized boolean isUserCanBeRemoved(UserEntity userEntity); void processLdapSync(LdapBatchDto batchInfo); Collection<PrivilegeEntity> getUserPrivileges(UserEntity userEntity); Collection<PrivilegeEntity> getGroupPrivileges(GroupEntity groupEntity); Collection<AmbariGrantedAuthority> getUserAuthorities(String userName, UserType userType);  }