use of org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim 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.model.ExternalClaim 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.model.ExternalClaim in project carbon-identity-framework by wso2.
the class ClaimMetadataManagementServiceImpl method addExternalClaim.
@Override
public void addExternalClaim(ExternalClaim externalClaim, String tenantDomain) throws ClaimMetadataException {
if (externalClaim == null || StringUtils.isBlank(externalClaim.getClaimURI())) {
throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_EXTERNAL_CLAIM_URI);
}
if (StringUtils.isBlank(externalClaim.getClaimDialectURI())) {
throw new ClaimMetadataClientException(ERROR_CODE_EMPTY_EXTERNAL_DIALECT_URI);
}
if (StringUtils.isBlank(externalClaim.getMappedLocalClaim())) {
throw new ClaimMetadataClientException(ERROR_CODE_MAPPED_TO_EMPTY_LOCAL_CLAIM_URI);
}
if (ClaimConstants.LOCAL_CLAIM_DIALECT_URI.equalsIgnoreCase(externalClaim.getClaimDialectURI())) {
throw new ClaimMetadataClientException(ERROR_CODE_INVALID_EXTERNAL_CLAIM_DIALECT);
}
ClaimConfig claimConfig = IdentityClaimManagementServiceDataHolder.getInstance().getClaimConfig();
String claimURIRegex = null;
if (claimConfig != null) {
claimURIRegex = claimConfig.getClaimUriRegex(externalClaim.getClaimDialectURI());
}
if (claimURIRegex != null && !externalClaim.getClaimURI().matches(claimURIRegex)) {
throw new ClaimMetadataClientException(ERROR_CODE_INVALID_EXTERNAL_CLAIM_URI);
}
// TODO : validate tenant domain?
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
if (isExistingExternalClaimURI(externalClaim.getClaimDialectURI(), externalClaim.getClaimURI(), tenantId)) {
throw new ClaimMetadataClientException(ERROR_CODE_EXISTING_EXTERNAL_CLAIM_URI.getCode(), String.format(ERROR_CODE_EXISTING_EXTERNAL_CLAIM_URI.getMessage(), externalClaim.getClaimURI(), externalClaim.getClaimDialectURI()));
}
boolean isLocalClaimAlreadyMapped = this.externalClaimDAO.isLocalClaimMappedWithinDialect(externalClaim.getMappedLocalClaim(), externalClaim.getClaimDialectURI(), tenantId);
if (isLocalClaimAlreadyMapped) {
throw new ClaimMetadataClientException((ERROR_CODE_EXISTING_LOCAL_CLAIM_MAPPING.getCode()), String.format(ERROR_CODE_EXISTING_LOCAL_CLAIM_MAPPING.getMessage(), externalClaim.getMappedLocalClaim(), externalClaim.getClaimDialectURI()));
}
// Add listener
this.externalClaimDAO.addExternalClaim(externalClaim, tenantId);
ClaimMetadataEventPublisherProxy.getInstance().publishPostAddExternalClaim(tenantId, externalClaim);
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim in project carbon-identity-framework by wso2.
the class CacheBackedExternalClaimDAO method updateExternalClaim.
public void updateExternalClaim(ExternalClaim externalClaim, int tenantId) throws ClaimMetadataException {
externalClaimDAO.updateExternalClaim(externalClaim, tenantId);
String externalClaimDialectURI = externalClaim.getClaimDialectURI();
ExternalClaimCacheKey cacheKey = new ExternalClaimCacheKey(externalClaimDialectURI);
externalClaimCache.clearCacheEntry(cacheKey, tenantId);
}
use of org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim in project carbon-identity-framework by wso2.
the class CacheBackedExternalClaimDAO method getExternalClaims.
public List<ExternalClaim> getExternalClaims(String externalDialectURI, int tenantId) throws ClaimMetadataException {
ExternalClaimCacheKey cacheKey = new ExternalClaimCacheKey(externalDialectURI);
List<ExternalClaim> externalClaimList = externalClaimCache.getValueFromCache(cacheKey, tenantId);
if (externalClaimList == null) {
if (log.isDebugEnabled()) {
log.debug("Cache miss for external claim list for dialect: " + externalDialectURI + " in tenant: " + tenantId);
}
externalClaimList = externalClaimDAO.getExternalClaims(externalDialectURI, tenantId);
externalClaimCache.addToCache(cacheKey, new ArrayList<>(externalClaimList), tenantId);
} else {
if (log.isDebugEnabled()) {
log.debug("Cache hit for external claim list for dialect: " + externalDialectURI + " in tenant: " + tenantId);
}
}
return externalClaimList;
}
Aggregations