use of org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO in project carbon-identity-framework by wso2.
the class ClaimMetadataManagementAdminService method getExternalClaims.
@SuppressWarnings("unused")
public ExternalClaimDTO[] getExternalClaims(String externalClaimDialectURI) throws ClaimMetadataException {
try {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
List<ExternalClaim> externalClaimList = IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().getExternalClaims(externalClaimDialectURI, tenantDomain);
ExternalClaim[] externalClaims = externalClaimList.toArray(new ExternalClaim[0]);
ExternalClaimDTO[] externalClaimDTOS = ClaimMetadataUtils.convertExternalClaimsToExternalClaimDTOs(externalClaims);
// Sort the external claims in the alphabetical order
Arrays.sort(externalClaimDTOS, new Comparator<ExternalClaimDTO>() {
@Override
public int compare(ExternalClaimDTO o1, ExternalClaimDTO o2) {
return o1.getExternalClaimURI().toLowerCase().compareTo(o2.getExternalClaimURI().toLowerCase());
}
});
return externalClaimDTOS;
} catch (Throwable e) {
log.error(e.getMessage(), e);
throw new ClaimMetadataException(e.getMessage(), e);
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO in project carbon-identity-framework by wso2.
the class ClaimMetadataManagementAdminService method addExternalClaim.
@SuppressWarnings("unused")
public void addExternalClaim(ExternalClaimDTO externalClaim) throws ClaimMetadataException {
try {
ExternalClaim claim = ClaimMetadataUtils.convertExternalClaimDTOToExternalClaim(externalClaim);
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
IdentityClaimManagementServiceDataHolder.getInstance().getClaimManagementService().addExternalClaim(claim, tenantDomain);
} catch (ClaimMetadataClientException e) {
if (log.isDebugEnabled()) {
log.debug(e.getMessage(), e);
}
throw new ClaimMetadataException(e.getMessage(), e);
} catch (Throwable e) {
log.error(e.getMessage(), e);
throw new ClaimMetadataException(e.getMessage(), e);
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO in project carbon-identity-framework by wso2.
the class ClaimMetadataUtils method convertExternalClaimToExternalClaimDTO.
public static ExternalClaimDTO convertExternalClaimToExternalClaimDTO(ExternalClaim externalClaim) {
ExternalClaimDTO externalClaimDTO = new ExternalClaimDTO();
externalClaimDTO.setExternalClaimDialectURI(externalClaim.getClaimDialectURI());
externalClaimDTO.setExternalClaimURI(externalClaim.getClaimURI());
externalClaimDTO.setMappedLocalClaimURI(externalClaim.getMappedLocalClaim());
// Convert Map<String, String> to ClaimPropertyDTO[]
Map<String, String> claimProperties = externalClaim.getClaimProperties();
ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[claimProperties.size()];
int j = 0;
for (Map.Entry<String, String> claimPropertyEntry : claimProperties.entrySet()) {
ClaimPropertyDTO claimProperty = new ClaimPropertyDTO();
claimProperty.setPropertyName(claimPropertyEntry.getKey());
claimProperty.setPropertyValue(claimPropertyEntry.getValue());
claimPropertyDTOs[j] = claimProperty;
j++;
}
externalClaimDTO.setClaimProperties(claimPropertyDTOs);
return externalClaimDTO;
}
use of org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO in project carbon-identity-framework by wso2.
the class ClaimMetadataUtils method convertExternalClaimDTOToExternalClaim.
public static ExternalClaim convertExternalClaimDTOToExternalClaim(ExternalClaimDTO externalClaimDTO) {
// TODO : Validate if externalClaimDTO null???
ExternalClaim externalClaim = new ExternalClaim(externalClaimDTO.getExternalClaimDialectURI(), externalClaimDTO.getExternalClaimURI(), externalClaimDTO.getMappedLocalClaimURI());
// Convert ClaimPropertyDTO[] to Map<String, String>
if (externalClaimDTO.getClaimProperties() != null) {
Map<String, String> claimProperties = new HashMap<>();
for (ClaimPropertyDTO claimPropertyDTO : externalClaimDTO.getClaimProperties()) {
claimProperties.put(claimPropertyDTO.getPropertyName(), claimPropertyDTO.getPropertyValue());
}
externalClaim.setClaimProperties(claimProperties);
}
return externalClaim;
}
use of org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO in project carbon-identity-framework by wso2.
the class ClaimMetadataUtilsTest method setUpExternalClaims.
private void setUpExternalClaims() {
String claimDialectURI = "testClaimDialectURI";
String externalClaimURI = "testExternalClaimURI";
String mappedLocalClaimURI = "testLocalClaimURI2";
externalClaim = new ExternalClaim(claimDialectURI, externalClaimURI, mappedLocalClaimURI);
int arraySize = 2;
externalClaims = new ExternalClaim[arraySize];
for (int i = 0; i < externalClaims.length; i++) {
externalClaims[i] = new ExternalClaim(claimDialectURI + i, externalClaimURI + i, mappedLocalClaimURI + i);
}
ClaimPropertyDTO claimPropertyDTO1 = new ClaimPropertyDTO();
claimPropertyDTO1.setPropertyName(ClaimConstants.DISPLAY_NAME_PROPERTY);
claimPropertyDTO1.setPropertyValue("username");
ClaimPropertyDTO claimPropertyDTO2 = new ClaimPropertyDTO();
claimPropertyDTO2.setPropertyName(ClaimConstants.READ_ONLY_PROPERTY);
claimPropertyDTO2.setPropertyValue("true");
ClaimPropertyDTO[] claimPropertyDTOs = new ClaimPropertyDTO[] { claimPropertyDTO1, claimPropertyDTO2 };
externalClaimDTO = new ExternalClaimDTO();
externalClaimDTO.setExternalClaimDialectURI(claimDialectURI);
externalClaimDTO.setExternalClaimURI(externalClaimURI);
externalClaimDTO.setMappedLocalClaimURI(mappedLocalClaimURI);
externalClaimDTO.setClaimProperties(claimPropertyDTOs);
}
Aggregations