Skip to content

Commit

Permalink
add forbidden scenarios for claim mgt
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-ariyaratne committed Nov 5, 2024
1 parent 5c02d29 commit ef91660
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
import static org.wso2.carbon.identity.api.server.common.Constants.XML_FILE_EXTENSION;
import static org.wso2.carbon.identity.api.server.common.Constants.YAML_FILE_EXTENSION;
import static org.wso2.carbon.identity.api.server.common.ContextLoader.buildURIForBody;
import static org.wso2.carbon.identity.claim.metadata.mgt.util.ClaimConstants.ErrorMessage.ERROR_CODE_NO_DELETE_SYSTEM_CLAIM;
import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_ORGANIZATION_NOT_FOUND_FOR_TENANT;

import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
Expand All @@ -159,6 +160,12 @@ public class ServerClaimManagementService {
ClaimConstants.ErrorMessage.ERROR_CODE_EXISTING_LOCAL_CLAIM_URI.getCode()
);

private static final List<String> forbiddenErrorScenarios = Arrays.asList(
ClaimConstants.ErrorMessage.ERROR_CODE_NO_RENAME_SYSTEM_DIALECT.getCode(),
ClaimConstants.ErrorMessage.ERROR_CODE_NO_DELETE_SYSTEM_DIALECT.getCode(),
ClaimConstants.ErrorMessage.ERROR_CODE_NO_DELETE_SYSTEM_CLAIM.getCode()
);

/**
* Add a claim dialect.
*
Expand Down Expand Up @@ -1266,6 +1273,9 @@ private APIError handleClaimManagementException(ClaimMetadataException e, Consta
if (isConflictScenario(e.getErrorCode())) {
status = CONFLICT;
}
if (isForbiddenScenario(e.getErrorCode())) {
status = FORBIDDEN;
}
if (StringUtils.isNotBlank(e.getErrorCode()) &&
e.getErrorCode().contains(Constant.CLAIM_MANAGEMENT_PREFIX)) {
return handleClaimManagementClientError(e.getErrorCode(), e.getMessage(), status, data);
Expand All @@ -1288,6 +1298,11 @@ private boolean isConflictScenario(String errorCode) {
return !StringUtils.isBlank(errorCode) && conflictErrorScenarios.contains(errorCode);
}

private boolean isForbiddenScenario(String errorCode) {

return !StringUtils.isBlank(errorCode) && forbiddenErrorScenarios.contains(errorCode);
}

private APIError handleClaimManagementClientError(Constant.ErrorMessage errorEnum, Response.Status status) {

return handleClaimManagementClientError(errorEnum, status, StringUtils.EMPTY);
Expand Down

0 comments on commit ef91660

Please sign in to comment.