if (deletedRoles != null) {
Arrays.sort(deletedRoles);
if(Arrays.binarySearch(deletedRoles, realmConfig.getEveryOneRoleName()) > -1){
log.error("An attempt to remove "+userName+" user from Everyone role ");
throw new UserStoreException("Everyone role is not updatable");
}
}
if (deletedRoles != null) {
Arrays.sort(deletedRoles);
if (realmConfig.getAdminUserName().equals(userName)
&& Arrays.binarySearch(deletedRoles, realmConfig.getAdminRoleName()) > -1) {
log.error("An attempt to remove Admin user from Admin role ");
throw new UserStoreException("Cannot remove Admin user from Admin role");
}
}
if (isReadOnly() == true) {
hybridRoleManager.updateHybridRoleListOfUser(userName, deletedRoles, newRoles);
} else {
String sqlStmt1 = realmConfig
.getUserStoreProperty(JDBCRealmConstants.REMOVE_ROLE_FROM_USER);
if (sqlStmt1 == null) {
throw new UserStoreException("The sql statement for remove user from role is null");
}
Connection dbConnection = null;
try {
dbConnection = getDBConnection();
String type = DatabaseCreator.getDatabaseType(dbConnection);
String sqlStmt2 = realmConfig
.getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER + "-" + type);
if (sqlStmt2 == null) {
sqlStmt2 = realmConfig
.getUserStoreProperty(JDBCRealmConstants.ADD_ROLE_TO_USER);
}
if (sqlStmt2 == null) {
throw new UserStoreException("The sql statement for add user to role is null");
}
if (deletedRoles != null) {
if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
deletedRoles, tenantId, userName, tenantId, tenantId);
} else {
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt1,
deletedRoles, tenantId, userName);
}
}
if (newRoles != null) {
if (sqlStmt1.contains(UserCoreConstants.UM_TENANT_COLUMN)) {
// System.out.println("" +
// DatabaseUtil.getIntegerValueFromDatabase(dbConnection,
// sqlStmt, params));
// System.out.println("" +
// DatabaseUtil.getIntegerValueFromDatabase(dbConnection,
// sqlStmt, params));
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
newRoles, tenantId, userName, tenantId, tenantId);
} else {
DatabaseUtil.udpateUserRoleMappingInBatchMode(dbConnection, sqlStmt2,
newRoles, tenantId, userName);
}
}
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);
}
}
}