Skip to content

Commit

Permalink
Add UniquenessScope as a first class property for claim management
Browse files Browse the repository at this point in the history
  • Loading branch information
AfraHussaindeen committed Nov 17, 2024
1 parent 6fb4b3c commit 78d9cff
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,5 @@ public String toString() {
public static final String PROP_REG_EX = "RegEx";
public static final String PROP_REQUIRED = "Required";
public static final String PROP_SUPPORTED_BY_DEFAULT = "SupportedByDefault";
public static final String PROP_UNIQUENESS_SCOPE = "UniquenessScope";
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public class LocalClaimReqDTO {
@Valid
private Boolean supportedByDefault = null;

public enum UniquenessScopeEnum {
NONE, WITHIN_USERSTORE, ACROSS_USERSTORES,
};
@Valid
private UniquenessScopeEnum uniquenessScope = null;

@Valid
@NotNull(message = "Property attributeMapping cannot be null.")
private List<AttributeMappingDTO> attributeMapping = new ArrayList<AttributeMappingDTO>();
Expand Down Expand Up @@ -163,6 +169,18 @@ public void setSupportedByDefault(Boolean supportedByDefault) {
this.supportedByDefault = supportedByDefault;
}

/**
* Specifies the scope of uniqueness validation for the claim value.
**/
@ApiModelProperty(value = "Specifies the scope of uniqueness validation for the claim value.")
@JsonProperty("uniquenessScope")
public UniquenessScopeEnum getUniquenessScope() {
return uniquenessScope;
}
public void setUniquenessScope(UniquenessScopeEnum uniquenessScope) {
this.uniquenessScope = uniquenessScope;
}

/**
* Userstore attribute mappings.
**/
Expand Down Expand Up @@ -201,6 +219,7 @@ public String toString() {
sb.append(" regEx: ").append(regEx).append("\n");
sb.append(" required: ").append(required).append("\n");
sb.append(" supportedByDefault: ").append(supportedByDefault).append("\n");
sb.append(" uniquenessScope: ").append(uniquenessScope).append("\n");
sb.append(" attributeMapping: ").append(attributeMapping).append("\n");
sb.append(" properties: ").append(properties).append("\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO;
import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.ClaimResDTO;
import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.PropertyDTO;
import io.swagger.annotations.*;
import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -64,6 +65,12 @@ public class LocalClaimResDTO extends ClaimResDTO {
@Valid
private Boolean supportedByDefault = null;

public enum UniquenessScopeEnum {
NONE, WITHIN_USERSTORE, ACROSS_USERSTORES,
};
@Valid
private UniquenessScopeEnum uniquenessScope = null;

@Valid
private List<AttributeMappingDTO> attributeMapping = new ArrayList<AttributeMappingDTO>();

Expand Down Expand Up @@ -190,6 +197,18 @@ public void setSupportedByDefault(Boolean supportedByDefault) {
this.supportedByDefault = supportedByDefault;
}

/**
* Specifies the scope of uniqueness validation for the claim value.
**/
@ApiModelProperty(value = "Specifies the scope of uniqueness validation for the claim value.")
@JsonProperty("uniquenessScope")
public UniquenessScopeEnum getUniquenessScope() {
return uniquenessScope;
}
public void setUniquenessScope(UniquenessScopeEnum uniquenessScope) {
this.uniquenessScope = uniquenessScope;
}

/**
* Userstore attribute mappings.
**/
Expand Down Expand Up @@ -231,6 +250,7 @@ public String toString() {
sb.append(" regEx: ").append(regEx).append("\n");
sb.append(" required: ").append(required).append("\n");
sb.append(" supportedByDefault: ").append(supportedByDefault).append("\n");
sb.append(" uniquenessScope: ").append(uniquenessScope).append("\n");
sb.append(" attributeMapping: ").append(attributeMapping).append("\n");
sb.append(" properties: ").append(properties).append("\n");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.PROP_REG_EX;
import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.PROP_REQUIRED;
import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.PROP_SUPPORTED_BY_DEFAULT;
import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.PROP_UNIQUENESS_SCOPE;
import static org.wso2.carbon.identity.api.server.common.Constants.JSON_FILE_EXTENSION;
import static org.wso2.carbon.identity.api.server.common.Constants.MEDIA_TYPE_JSON;
import static org.wso2.carbon.identity.api.server.common.Constants.MEDIA_TYPE_XML;
Expand Down Expand Up @@ -994,6 +995,15 @@ private LocalClaimResDTO getLocalClaimResDTO(LocalClaim localClaim) {
localClaimResDTO.setRequired(Boolean.valueOf(claimProperties.remove(PROP_REQUIRED)));
localClaimResDTO.setSupportedByDefault(Boolean.valueOf(claimProperties.remove(PROP_SUPPORTED_BY_DEFAULT)));

String uniquenessScope = claimProperties.remove(PROP_UNIQUENESS_SCOPE);
if (StringUtils.isNotBlank(uniquenessScope)) {
try {
localClaimResDTO.setUniquenessScope(LocalClaimResDTO.UniquenessScopeEnum.valueOf(uniquenessScope));
} catch (IllegalArgumentException e) {
localClaimResDTO.setUniquenessScope(LocalClaimResDTO.UniquenessScopeEnum.NONE);
}
}

List<AttributeMappingDTO> attributeMappingDTOs = new ArrayList<>();
for (AttributeMapping attributeMapping : localClaim.getMappedAttributes()) {
AttributeMappingDTO attributeMappingDTO = new AttributeMappingDTO();
Expand Down Expand Up @@ -1042,6 +1052,10 @@ private LocalClaim createLocalClaim(LocalClaimReqDTO localClaimReqDTO) {
claimProperties.put(PROP_DISPLAY_ORDER, "0");
}

if (localClaimReqDTO.getUniquenessScope() != null) {
claimProperties.put(PROP_UNIQUENESS_SCOPE, localClaimReqDTO.getUniquenessScope().toString());
}

claimProperties.put(PROP_READ_ONLY, String.valueOf(localClaimReqDTO.getReadOnly()));
claimProperties.put(PROP_REQUIRED, String.valueOf(localClaimReqDTO.getRequired()));
claimProperties.put(PROP_SUPPORTED_BY_DEFAULT, String.valueOf(localClaimReqDTO.getSupportedByDefault()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,14 @@ definitions:
type: boolean
description: Specifies if the claim will be prompted during user registration and displayed on the user profile.
example: true
uniquenessScope:
type: string
description: Specifies the scope of uniqueness validation for the claim value.
enum:
- NONE
- WITHIN_USERSTORE
- ACROSS_USERSTORES
example: "NONE"
attributeMapping:
type: array
description: Userstore attribute mappings.
Expand Down Expand Up @@ -796,6 +804,14 @@ definitions:
type: boolean
description: Specifies if the claim will be prompted during user registration and displayed on the user profile.
example: true
uniquenessScope:
type: string
description: Specifies the scope of uniqueness validation for the claim value.
enum:
- NONE
- WITHIN_USERSTORE
- ACROSS_USERSTORES
example: "NONE"
attributeMapping:
type: array
description: Userstore attribute mappings.
Expand Down

0 comments on commit 78d9cff

Please sign in to comment.