Skip to content

Commit

Permalink
Enable group name update with group specific functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshiAthapaththu committed Aug 24, 2023
1 parent a2a9d3b commit cb9fc43
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,32 @@ private String removePrimaryDomainName(String roleName) {
return roleName;
}
}

public void updateGroupName(int tenantId, String oldGroupName, String newGroupName)
throws IdentitySCIMException {
Connection connection = IdentityDatabaseUtil.getDBConnection();
PreparedStatement prepStmt = null;

if (isExistingGroup(SCIMCommonUtils.getGroupNameWithDomain(oldGroupName), tenantId)) {
try {
prepStmt = connection.prepareStatement(SQLQueries.UPDATE_GROUP_NAME_SQL);

prepStmt.setString(1, SCIMCommonUtils.getGroupNameWithDomain(newGroupName));
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, SCIMCommonUtils.getGroupNameWithDomain(oldGroupName));

int count = prepStmt.executeUpdate();
if (log.isDebugEnabled()) {
log.debug("No. of records updated for updating SCIM Group : " + count);
}
connection.commit();
} catch (SQLException e) {
throw new IdentitySCIMException("Error updating the SCIM Group Attributes", e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt);
}
} else {
throw new IdentitySCIMException("Error when updating group name of the group: " + oldGroupName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ private void setGroupDisplayName(String oldGroupName, String newGroupName)

if (!StringUtils.equals(oldGroupName, newGroupName)) {
// Update group name in carbon UM.
carbonUM.updateRoleName(oldGroupName, newGroupName);
carbonUM.updateNameOfGroup(oldGroupName, newGroupName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,22 @@ public boolean deleteGroup(String groupName, int tenantId) throws UserStoreExcep
}
return true;
}

@Override
public boolean updateGroupName(String oldGroupName, String newGroupName, int tenantID) throws UserStoreException {

try {
GroupDAO groupDAO = new GroupDAO();
if (groupDAO.isExistingGroup(oldGroupName, tenantID)) {
groupDAO.updateGroupName(tenantID, oldGroupName, newGroupName);
} else {
log.warn("Non-existent group: " + oldGroupName + " is trying to be updated..");
}

} catch (IdentitySCIMException e) {
throw new UserStoreException(String.format("Error occurred while updating the " +
"group: %s in tenant: %s", oldGroupName, tenantID), e);
}
return true;
}
}

0 comments on commit cb9fc43

Please sign in to comment.