Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API changes for claim management #730

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.ArrayList;
import java.util.List;

/**
* External claim response.
Expand All @@ -42,6 +44,9 @@ public class ExternalClaimResDTO extends ClaimResDTO {
@Valid
private String mappedLocalClaimURI = null;

@Valid
private List<PropertyDTO> properties = new ArrayList<PropertyDTO>();

/**
* External claim ID.
**/
Expand Down Expand Up @@ -90,6 +95,18 @@ public void setMappedLocalClaimURI(String mappedLocalClaimURI) {
this.mappedLocalClaimURI = mappedLocalClaimURI;
}

/**
* Define any additional properties if required.
**/
@ApiModelProperty(value = "Define any additional properties if required.")
@JsonProperty("properties")
public List<PropertyDTO> getProperties() {
return properties;
}
public void setProperties(List<PropertyDTO> properties) {
this.properties = properties;
}

@Override
public String toString() {

Expand All @@ -101,6 +118,7 @@ public String toString() {
sb.append(" claimURI: ").append(claimURI).append("\n");
sb.append(" claimDialectURI: ").append(claimDialectURI).append("\n");
sb.append(" mappedLocalClaimURI: ").append(mappedLocalClaimURI).append("\n");
sb.append(" properties: ").append(properties).append("\n");

sb.append("}\n");
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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 @@ -944,6 +950,7 @@ private ExternalClaimResDTO getExternalClaimResDTO(ExternalClaim externalClaim)
externalClaimResDTO.setClaimDialectURI(externalClaim.getClaimDialectURI());
externalClaimResDTO.setClaimURI(externalClaim.getClaimURI());
externalClaimResDTO.setMappedLocalClaimURI(externalClaim.getMappedLocalClaim());
externalClaimResDTO.setProperties(mapToProperties(externalClaim.getClaimProperties()));

return externalClaimResDTO;
}
Expand Down Expand Up @@ -1265,6 +1272,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 @@ -1287,6 +1297,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
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ definitions:
type: string
description: The local claim URI to map with the external claim.
example: "http://wso2.org/claims/username"
properties:
type: array
description: Define any additional properties if required.
items:
$ref: '#/definitions/Property'

#-----------------------------------------------------
# Property Object
Expand Down
Loading