Skip to content

Commit

Permalink
Add scimType to BadRequestException
Browse files Browse the repository at this point in the history
  • Loading branch information
hwupathum committed Jan 22, 2024
1 parent 22f2388 commit 5fc4a4e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Role createRole(Role role) throws CharonException, ConflictException, Bad
if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) {
throw new ConflictException(e.getMessage());
} else if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(
String.format("Error occurred while adding a new role: %s", role.getDisplayName()), e);
Expand Down Expand Up @@ -500,7 +500,7 @@ private void doUpdatePermissions(Role oldRole, Role newRole) throws BadRequestEx
roleManagementService.setPermissionsForRole(oldRole.getId(), newRolePermissions, tenantDomain);
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
}
Expand Down Expand Up @@ -709,7 +709,7 @@ private void doUpdateUsers(Set<String> newUserList, Set<String> deletedUserList,
new ArrayList<>(deletedUserIDList), tenantDomain);
} catch (IdentityRoleManagementException e) {
if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
if (OPERATION_FORBIDDEN.getCode().equals(e.getErrorCode())) {
throw new ForbiddenException(e.getMessage());
Expand Down Expand Up @@ -761,7 +761,7 @@ private void updatePermissions(String roleId, List<PatchOperation> permissionOpe
roleManagementService.setPermissionsForRole(roleId, newRolePermissions, tenantDomain);
} catch (IdentityRoleManagementException e) {
if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(
String.format("Error occurred while updating permissions for role: %s", roleId), e);
Expand Down Expand Up @@ -814,7 +814,8 @@ private void prepareAddedRemovedUserLists(Set<String> addedMembers, Set<String>
}

if (memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY) == null) {
throw new BadRequestException("User can't be resolved from the given user Id.");
throw new BadRequestException("User can't be resolved from the given user Id.",
ResponseCodeConstants.INVALID_VALUE);
}

List<String> roleList = Arrays.asList(userStoreManager.
Expand Down Expand Up @@ -867,7 +868,7 @@ private void doUpdateGroups(String roleId, Set<String> newGroupIDList, Set<Strin
new ArrayList<>(deleteGroupIDList), tenantDomain);
} catch (IdentityRoleManagementException e) {
if (INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(
String.format("Error occurred while updating groups in the role: %s", roleId), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public RoleV2 createRole(RoleV2 role)
if (StringUtils.equals(ROLE_ALREADY_EXISTS.getCode(), e.getErrorCode())) {
throw new ConflictException(e.getMessage());
} else if (StringUtils.equals(INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (INVALID_AUDIENCE.getCode().equals(e.getErrorCode()) ||
INVALID_PERMISSION.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
Expand Down Expand Up @@ -836,7 +836,7 @@ private void doUpdatePermissions(RoleV2 oldRole, RoleV2 newRole) throws BadReque
tenantDomain);
} catch (IdentityRoleManagementException e) {
if (StringUtils.equals(RoleConstants.Error.INVALID_REQUEST.getCode(), e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (RoleConstants.Error.INVALID_PERMISSION.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (StringUtils.equals(OPERATION_FORBIDDEN.getCode(), e.getErrorCode())) {
Expand Down Expand Up @@ -1102,7 +1102,7 @@ private void doUpdatePermissions(String roleId, Set<String> addedPermissions, Se
tenantDomain);
} catch (IdentityRoleManagementException e) {
if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (RoleConstants.Error.INVALID_PERMISSION.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
Expand All @@ -1122,7 +1122,7 @@ private void doUpdateGroups(String roleId, Set<String> newGroupIDList, Set<Strin
new ArrayList<>(deleteGroupIDList), tenantDomain);
} catch (IdentityRoleManagementException e) {
if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(
String.format("Error occurred while updating groups in the role with ID: %s", roleId), e);
Expand All @@ -1139,7 +1139,7 @@ private void doUpdateIdPGroups(String roleId, List<IdpGroup> newGroupIDList, Lis
roleManagementService.updateIdpGroupListOfRole(roleId, newGroupIDList, deleteGroupIDList, tenantDomain);
} catch (IdentityRoleManagementException e) {
if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(
String.format("Error occurred while updating groups in the role with ID: %s", roleId), e);
Expand All @@ -1164,7 +1164,7 @@ private void doUpdateUsers(Set<String> newUserList, Set<String> deletedUserList,
new ArrayList<>(deletedUserIDList), tenantDomain);
} catch (IdentityRoleManagementException e) {
if (RoleConstants.Error.INVALID_REQUEST.getCode().equals(e.getErrorCode())) {
throw new BadRequestException(e.getMessage());
throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE);
} else if (OPERATION_FORBIDDEN.getCode().equals(e.getErrorCode())) {
throw new ForbiddenException(e.getMessage());
}
Expand Down Expand Up @@ -1292,7 +1292,8 @@ private void prepareAddedRemovedUserLists(Set<String> addedMembers, Set<String>
}

if (memberObject.get(SCIMConstants.RoleSchemaConstants.DISPLAY) == null) {
throw new BadRequestException("User can't be resolved from the given user Id.");
throw new BadRequestException("User can't be resolved from the given user Id.",
ResponseCodeConstants.INVALID_VALUE);
}

List<String> roleList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public User createUser(User user, Map<String, Boolean> requiredAttributes)
} else {
throw new BadRequestException(
"The claim value for " + primaryLoginIdentifier + " " +
"and username should be same.");
"and username should be same.", ResponseCodeConstants.INVALID_VALUE);
}
} else {
claimsInLocalDialect.put(getPrimaryLoginIdentifierClaim(),
Expand Down Expand Up @@ -1582,7 +1582,8 @@ private String resolveDomainNameInAttributeValue(String domainName, ExpressionNo
.equalsIgnoreCase(domainName)) {
throw new BadRequestException(String.format(
" Domain name %s in the domain parameter does not match with the domain name %s in search "
+ "attribute value of %s claim.", domainName, extractedDomain, attributeName));
+ "attribute value of %s claim.", domainName, extractedDomain, attributeName),
ResponseCodeConstants.INVALID_VALUE);
}
if (StringUtils.isEmpty(domainName) && StringUtils.isNotEmpty(extractedDomain)) {
if (log.isDebugEnabled())
Expand Down Expand Up @@ -2377,7 +2378,7 @@ private void checkForPaginationSupport(Condition condition) throws UserStoreExce
if (hasBothIdentityClaimAndDefaultClaims && !paginationEnabled) {
String errorMessage =
"Pagination support is not enabled for multi attribute filtering with both identity claims and default claims";
throw new BadRequestException(errorMessage);
throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
}
}

Expand Down Expand Up @@ -3871,7 +3872,7 @@ private boolean isSCIMEnabled(String userStoreName) throws BadRequestException {

UserStoreManager userStoreManager = carbonUM.getSecondaryUserStoreManager(userStoreName);
if (userStoreManager == null) {
throw new BadRequestException("Invalid user store name.");
throw new BadRequestException("Invalid user store name.", ResponseCodeConstants.INVALID_VALUE);
}else {
try {
return userStoreManager.isSCIMEnabled();
Expand Down Expand Up @@ -4362,7 +4363,7 @@ private void appendDomainToMembers(Group group, String userStoreDomain) throws C
SCIMConstants.CommonSchemaConstants.DISPLAY);
if (displayNameAttribute == null) {
throw new BadRequestException("Display name attribute of a member is empty while adding to " +
"the group: " + group.getDisplayName());
"the group: " + group.getDisplayName(), ResponseCodeConstants.INVALID_VALUE);
}
String displayName =
AttributeUtil.getStringValueOfAttribute(displayNameAttribute.getValue(),
Expand Down Expand Up @@ -5973,7 +5974,7 @@ private void validateExtractedDomain(String domainName, String attributeName, St
throw new BadRequestException(String.format(
" Domain name: %s in the domain parameter does not match with the domain name: %s in "
+ "search attribute value of %s claim.", domainName, extractedDomain,
attributeName));
attributeName), ResponseCodeConstants.INVALID_VALUE);
}

// Check whether the domain name is an actually existing domain name.
Expand All @@ -6000,7 +6001,7 @@ private void validateExtractedDomain(String domainName, String attributeName, St
}
if (((UserStoreManager) userStoreManager).getSecondaryUserStoreManager(extractedDomain) == null) {
throw new BadRequestException("The provided domain name: " + extractedDomain + ", must be a valid " +
"user-store domain");
"user-store domain", ResponseCodeConstants.INVALID_VALUE);
}
} catch (UserStoreException e) {
throw resolveError(e, "Unable to retrieve user realm for the tenant domain: " + tenantDomain);
Expand Down

0 comments on commit 5fc4a4e

Please sign in to comment.