public void updateUserListOfHybridRole(String roleName, String[] deletedUsers, String[] newUsers)
throws UserStoreException {
if (realmConfig.getEveryOneRoleName().equals(roleName)) {
throw new UserStoreException("Everyone role is not updatable");
}
if (deletedUsers != null) {
Arrays.sort(deletedUsers);
if (realmConfig.getAdminRoleName().equals(roleName)
&& Arrays.binarySearch(deletedUsers, realmConfig.getAdminUserName()) > -1) {
log.error("An attempt to remove Admin user from Admin role ");
throw new UserStoreException("Cannot remove Admin user from Admin role");
}
}
String sqlStmt1 = HybridJDBCConstants.REMOVE_USER_FROM_ROLE_SQL;
String sqlStmt2 = HybridJDBCConstants.ADD_USER_TO_ROLE_SQL;
Connection dbConnection = null;
try {
dbConnection = getDBConnection();
String type = DatabaseCreator.getDatabaseType(dbConnection);
if (UserCoreConstants.MSSQL_TYPE.equals(type)) {
sqlStmt2 = HybridJDBCConstants.ADD_USER_TO_ROLE_SQL_MSSQL;
}
if (deletedUsers != null && deletedUsers.length > 0) {
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1, deletedUsers,
roleName, tenantId, tenantId);
}
if (newUsers != null && newUsers.length > 0) {
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2, newUsers,
roleName, tenantId, tenantId);
}
dbConnection.commit();
} catch (SQLException e) {
log.error(e.getMessage(), e);
throw new UserStoreException(e.getMessage(), e);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new UserStoreException(e.getMessage(), e);
} finally {
DatabaseUtil.closeAllConnections(dbConnection);
}
}