Search in sources :

Example 1 with ExternalClaim

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);
    }
}
Also used : ExternalClaimDTO(org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 2 with ExternalClaim

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);
    }
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Example 3 with ExternalClaim

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);
}
Also used : ClaimMetadataClientException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException) ClaimConfig(org.wso2.carbon.user.core.claim.inmemory.ClaimConfig)

Example 4 with 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);
}
Also used : ExternalClaimCacheKey(org.wso2.carbon.identity.claim.metadata.mgt.cache.ExternalClaimCacheKey)

Example 5 with ExternalClaim

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;
}
Also used : ExternalClaimCacheKey(org.wso2.carbon.identity.claim.metadata.mgt.cache.ExternalClaimCacheKey) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)

Aggregations

ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)44 HashMap (java.util.HashMap)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)20 Test (org.testng.annotations.Test)18 ArrayList (java.util.ArrayList)17 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 Map (java.util.Map)9 ClaimDialect (org.wso2.carbon.identity.claim.metadata.mgt.model.ClaimDialect)7 Matchers.anyString (org.mockito.Matchers.anyString)6 ClaimPropertyDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO)6 ExternalClaimDTO (org.wso2.carbon.identity.claim.metadata.mgt.dto.ExternalClaimDTO)5 OAuth2Util (org.wso2.carbon.identity.oauth2.util.OAuth2Util)5 Attribute (org.wso2.charon3.core.attributes.Attribute)5 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)5 HashSet (java.util.HashSet)4 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)4 ExpressionAttribute (org.wso2.carbon.user.core.model.ExpressionAttribute)4 AbstractAttribute (org.wso2.charon3.core.attributes.AbstractAttribute)4 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)4