Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshiAthapaththu committed Aug 16, 2023
1 parent e3c07e9 commit 6c3a0fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2626,26 +2626,15 @@ public Group createGroup(Group group, Map<String, Boolean> requiredAttributes)
}
}
}
// Add other scim attributes in the identity DB since user store doesn't support some attributes.
// Commented by Lakshi as we don't need to save this in the identity DB if there is ID support
// enabled in user store level.
// SCIMGroupHandler scimGroupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
// scimGroupHandler.createSCIMAttributes(group);
// carbonUM.addRoleWithID(group.getDisplayName(), members.toArray(new String[0]), null, false);
coreGroup = carbonUM.addGroupWithID(group.getDisplayName(), members.toArray(new String[0]), group.getDisplayName(),
group.getId(), group.getCreatedDate(), group.getLastModified(), group.getLocation());
coreGroup = carbonUM.addGroupWithID(group.getDisplayName(), group.getId(),
members.toArray(new String[0]), group.getCreatedDateTime(), group.getLastModifiedDateTime(),
group.getLocation());
if (log.isDebugEnabled()) {
log.debug("Group: " + group.getDisplayName() + " is created through SCIM.");
}
} else {
// Add other scim attributes in the identity DB since user store doesn't support some attributes.
// Commented by Lakshi as we don't need to save this in the identity DB if there is ID support
// enabled in user store level.
// SCIMGroupHandler scimGroupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
// scimGroupHandler.createSCIMAttributes(group);
// carbonUM.addRoleWithID(group.getDisplayName(), null, null, false);
coreGroup = carbonUM.addGroupWithID(group.getDisplayName(), null, group.getDisplayName(),
group.getId(), group.getCreatedDate(), group.getLastModified(), group.getLocation());
coreGroup = carbonUM.addGroupWithID(group.getDisplayName(), group.getId(), null,
group.getCreatedDateTime(), group.getLastModifiedDateTime(), group.getLocation());

if (log.isDebugEnabled()) {
log.debug("Group: " + group.getDisplayName() + " is created through SCIM.");
Expand All @@ -2656,15 +2645,6 @@ public Group createGroup(Group group, Map<String, Boolean> requiredAttributes)
group.setId(coreGroup.getGroupID());
}
} catch (UserStoreException e) {
// Commented by Lakshi as we don't need to save this in the identity DB if there is ID support
// enabled in user store level.
// try {
// SCIMGroupHandler scimGroupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
// scimGroupHandler.deleteGroupAttributes(group.getDisplayName());
// } catch (UserStoreException | IdentitySCIMException ex) {
// throw resolveError(e, "Error occurred while doing rollback operation of the SCIM " +
// "table entry for role: " + group.getDisplayName());
// }
handleErrorsOnRoleNamePolicy(e);
throw resolveError(e, "Error occurred while adding role : " + group.getDisplayName());
} catch (IdentitySCIMException | BadRequestException e) {
Expand Down Expand Up @@ -2787,11 +2767,6 @@ public void deleteGroup(String groupId) throws NotFoundException, CharonExceptio
// Set thread local property to signal the downstream SCIMUserOperationListener
// about the provisioning route.
SCIMCommonUtils.setThreadLocalIsManagedThroughSCIMEP(true);

// Get group name by id.
// SCIMGroupHandler groupHandler = new SCIMGroupHandler(carbonUM.getTenantId());
// String groupName = groupHandler.getGroupName(groupId);

String groupName = carbonUM.getGroupNameByGroupId(groupId);

if (groupName != null) {
Expand All @@ -2816,11 +2791,9 @@ public void deleteGroup(String groupId) throws NotFoundException, CharonExceptio
}

//delete group in carbon UM
// carbonUM.deleteRole(groupName);
carbonUM.deleteGroupWithID(groupId);
carbonUM.removeGroupRoleMappingByGroupName(groupName);

//we do not update Identity_SCIM DB here since it is updated in SCIMUserOperationListener's methods.
if (log.isDebugEnabled()) {
log.debug("Group: " + groupName + " is deleted through SCIM.");
}
Expand All @@ -2834,10 +2807,6 @@ public void deleteGroup(String groupId) throws NotFoundException, CharonExceptio
} catch (UserStoreException e) {
throw resolveError(e, "Error occurred while deleting group " + groupId);
}
// catch (IdentitySCIMException e) {
// throw new CharonException("Error occurred while deleting group " + groupId, e);
// }

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -628,27 +629,30 @@ private String createSearchValueForEwOperation(String attributeName, String filt
}

@Override
public void addGroup(String groupID, Date createdDate, Date lastModifiedDate, String location,
String displayName, int tenantId) throws UserStoreException {
public boolean addGroup(String displayName, String groupID, LocalDateTime createdDate,
LocalDateTime lastModifiedDate, String location, int tenantId) throws UserStoreException {

Map<String, String> attributes = new HashMap<>();
attributes.put(SCIMConstants.CommonSchemaConstants.ID_URI, groupID);
attributes.put(SCIMConstants.CommonSchemaConstants.CREATED_URI, AttributeUtil.formatDateTime(
createdDate.toInstant(ZoneOffset.UTC)));
attributes.put(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI, AttributeUtil.formatDateTime(
lastModifiedDate.toInstant(ZoneOffset.UTC)));
attributes.put(SCIMConstants.CommonSchemaConstants.LOCATION_URI, location);

try {
Map<String, String> attributes = new HashMap<>();
attributes.put(SCIMConstants.CommonSchemaConstants.ID_URI, groupID);
attributes.put(SCIMConstants.CommonSchemaConstants.CREATED_URI, AttributeUtil.formatDateTime(
createdDate.toInstant()));
attributes.put(SCIMConstants.CommonSchemaConstants.LAST_MODIFIED_URI, AttributeUtil.formatDateTime(
lastModifiedDate.toInstant()));
attributes.put(SCIMConstants.CommonSchemaConstants.LOCATION_URI, location);
GroupDAO groupDAO = new GroupDAO();
groupDAO.addSCIMGroupAttributes(tenantId, displayName, attributes);
} catch (IdentitySCIMException e) {
throw new UserStoreException(String.format("Error occurred while saving the " +
"group: %s in tenant: %s", displayName, tenantId), e);
}

return true;
}

@Override
public void deleteGroup(String groupName, int tenantId) throws UserStoreException {
public boolean deleteGroup(String groupName, int tenantId) throws UserStoreException {

try {
GroupDAO groupDAO = new GroupDAO();
Expand All @@ -664,5 +668,6 @@ public void deleteGroup(String groupName, int tenantId) throws UserStoreExceptio
throw new UserStoreException(String.format("Error occurred while deleting the " +
"group: %s in tenant: %s", groupName, tenantId), e);
}
return true;
}
}

0 comments on commit 6c3a0fb

Please sign in to comment.