Search in sources :

Example 1 with ClaimMetadataManagementServiceImpl

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.

the class IdentityProviderManagementServiceTest method testGetAllLocalClaimUrisException.

@Test
public void testGetAllLocalClaimUrisException() throws Exception {
    ClaimMetadataManagementServiceImpl claimMetadataManagementService = mock(ClaimMetadataManagementServiceImpl.class);
    IdpMgtServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
    when(claimMetadataManagementService.getLocalClaims(anyString())).thenThrow(ClaimMetadataException.class);
    assertThrows(IdentityProviderManagementException.class, () -> identityProviderManagementService.getAllLocalClaimUris());
}
Also used : ClaimMetadataManagementServiceImpl(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl) Test(org.testng.annotations.Test)

Example 2 with ClaimMetadataManagementServiceImpl

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.

the class ClaimMetadataHandler method getMappingsFromOtherDialectToCarbon.

/**
 * @param otherDialectURI
 * @param otherClaimURIs
 * @param tenantDomain
 * @return
 * @throws ClaimMetadataException
 */
public Set<ExternalClaim> getMappingsFromOtherDialectToCarbon(String otherDialectURI, Set<String> otherClaimURIs, String tenantDomain) throws ClaimMetadataException {
    Set<ExternalClaim> returnSet = new HashSet<ExternalClaim>();
    if (otherDialectURI == null) {
        String message = "Invalid argument: \'otherDialectURI\' is \'NULL\'";
        log.error(message);
        throw new ClaimMetadataException(message);
    }
    try {
        ClaimMetadataManagementServiceImpl claimMetadataService = new ClaimMetadataManagementServiceImpl();
        if (otherDialectURI.equals(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
            List<LocalClaim> localClaims = claimMetadataService.getLocalClaims(tenantDomain);
            if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
                for (LocalClaim localClaim : localClaims) {
                    ExternalClaim claimMapping = new ExternalClaim(localClaim.getClaimDialectURI(), localClaim.getClaimURI(), localClaim.getClaimURI());
                    returnSet.add(claimMapping);
                }
                return returnSet;
            } else {
                for (LocalClaim localClaim : localClaims) {
                    if (otherClaimURIs.contains(localClaim.getClaimURI())) {
                        ExternalClaim claimMapping = new ExternalClaim(otherDialectURI, localClaim.getClaimURI(), localClaim.getClaimURI());
                        returnSet.add(claimMapping);
                    }
                }
                return returnSet;
            }
        } else {
            List<ExternalClaim> externalClaims = claimMetadataService.getExternalClaims(otherDialectURI, tenantDomain);
            if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
                returnSet = new HashSet<ExternalClaim>(externalClaims);
            } else {
                for (ExternalClaim externalClaim : externalClaims) {
                    if (otherClaimURIs.contains(externalClaim.getClaimURI())) {
                        returnSet.add(externalClaim);
                    }
                }
            }
            return returnSet;
        }
    } catch (ClaimMetadataException e) {
        throw new ClaimMetadataException(e.getMessage(), e);
    }
}
Also used : ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) HashSet(java.util.HashSet)

Example 3 with ClaimMetadataManagementServiceImpl

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.

the class DefaultApplicationValidator method validateClaimsConfigs.

/**
 * Validate claim related configurations and append to the validation msg list.
 *
 * @param validationMsg   validation error messages
 * @param claimConfig     claim config
 * @param subjectClaimUri Subject claim Uri
 * @param tenantDomain    tenant domain
 * @throws IdentityApplicationManagementException Identity Application Management Exception
 */
private void validateClaimsConfigs(List<String> validationMsg, ClaimConfig claimConfig, String subjectClaimUri, String tenantDomain, String serviceProviderName) throws IdentityApplicationManagementException {
    if (claimConfig == null) {
        return;
    }
    ApplicationManagementService applicationMgtService = ApplicationManagementService.getInstance();
    String[] allLocalClaimUris = applicationMgtService.getAllLocalClaimUris(tenantDomain);
    ArrayList<String> remoteClaimUris = new ArrayList<>();
    ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
    if (claimMappings != null) {
        for (ClaimMapping claimMapping : claimMappings) {
            String claimUri = claimMapping.getLocalClaim().getClaimUri();
            remoteClaimUris.add(claimMapping.getRemoteClaim().getClaimUri());
            if (!Arrays.asList(allLocalClaimUris).contains(claimUri)) {
                validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, claimUri, tenantDomain));
            }
        }
    }
    String roleClaimUri = claimConfig.getRoleClaimURI();
    String userClaimUri = claimConfig.getUserClaimURI();
    if (claimConfig.isLocalClaimDialect()) {
        if (StringUtils.isNotBlank(roleClaimUri) && !Arrays.asList(allLocalClaimUris).contains(roleClaimUri)) {
            validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, roleClaimUri, tenantDomain));
        }
        if (StringUtils.isNotBlank(userClaimUri) && !Arrays.asList(allLocalClaimUris).contains(userClaimUri)) {
            validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, userClaimUri, tenantDomain));
        }
        if (StringUtils.isNotBlank(subjectClaimUri) && !Arrays.asList(allLocalClaimUris).contains(subjectClaimUri)) {
            validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, subjectClaimUri, tenantDomain));
        }
    } else {
        if (StringUtils.isNotBlank(roleClaimUri) && !(remoteClaimUris).contains(roleClaimUri)) {
            validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, roleClaimUri, serviceProviderName));
        }
        if (StringUtils.isNotBlank(userClaimUri) && !(remoteClaimUris).contains(userClaimUri)) {
            validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, userClaimUri, serviceProviderName));
        }
        if (StringUtils.isNotBlank(subjectClaimUri) && !(remoteClaimUris).contains(subjectClaimUri)) {
            validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, subjectClaimUri, serviceProviderName));
        }
    }
    String[] spClaimDialects = claimConfig.getSpClaimDialects();
    if (spClaimDialects != null) {
        try {
            ClaimMetadataManagementServiceImpl claimAdminService = new ClaimMetadataManagementServiceImpl();
            List<ClaimDialect> serverClaimMapping = claimAdminService.getClaimDialects(tenantDomain);
            if (serverClaimMapping != null) {
                List<String> serverDialectURIS = serverClaimMapping.stream().map(ClaimDialect::getClaimDialectURI).collect(Collectors.toList());
                for (String spClaimDialect : spClaimDialects) {
                    if (!serverDialectURIS.contains(spClaimDialect)) {
                        validationMsg.add(String.format(CLAIM_DIALECT_NOT_AVAILABLE, spClaimDialect, tenantDomain));
                    }
                }
            }
        } catch (ClaimMetadataException e) {
            validationMsg.add(String.format("Error in getting claim dialect for %s. ", tenantDomain));
        }
    }
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimMetadataException(org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException) ClaimDialect(org.wso2.carbon.identity.claim.metadata.mgt.model.ClaimDialect) ArrayList(java.util.ArrayList) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) ClaimMetadataManagementServiceImpl(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl)

Example 4 with ClaimMetadataManagementServiceImpl

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.

the class IdentityClaimManagementServiceComponent method activate.

@Activate
protected void activate(ComponentContext ctxt) {
    try {
        BundleContext bundleCtx = ctxt.getBundleContext();
        IdentityClaimManagementServiceDataHolder.getInstance().setBundleContext(bundleCtx);
        if (IdentityClaimManagementServiceDataHolder.getInstance().getClaimConfigInitDAO() == null) {
            IdentityClaimManagementServiceDataHolder.getInstance().setClaimConfigInitDAO(new DefaultClaimConfigInitDAO());
        }
        ClaimMetadataStoreFactory claimMetadataStoreFactory = new ClaimMetadataStoreFactory();
        bundleCtx.registerService(ClaimManagerFactory.class.getName(), claimMetadataStoreFactory, null);
        ClaimMetadataManagementService claimManagementService = new ClaimMetadataManagementServiceImpl();
        bundleCtx.registerService(ClaimMetadataManagementService.class.getName(), claimManagementService, null);
        IdentityClaimManagementServiceDataHolder.getInstance().setClaimManagementService(claimManagementService);
        bundleCtx.registerService(TenantMgtListener.class.getName(), new ClaimMetadataTenantMgtListener(), null);
        registerClaimConfigListener(bundleCtx);
        // Register claim operation event handler implementation.
        bundleCtx.registerService(AbstractEventHandler.class.getName(), new ClaimMetadataManagementAuditLogger(), null);
        if (log.isDebugEnabled()) {
            log.debug("ClaimMetadataManagementAuditLogger is successfully registered.");
            log.debug("Identity Claim Management Core bundle is activated");
        }
    } catch (Throwable e) {
        log.error("Error occurred while activating Identity Claim Management Service Component", e);
    }
}
Also used : ClaimMetadataTenantMgtListener(org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataTenantMgtListener) TenantMgtListener(org.wso2.carbon.stratos.common.listeners.TenantMgtListener) ClaimMetadataManagementAuditLogger(org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataManagementAuditLogger) ClaimMetadataStoreFactory(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataStoreFactory) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) ClaimManagerFactory(org.wso2.carbon.user.core.claim.ClaimManagerFactory) ClaimMetadataTenantMgtListener(org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataTenantMgtListener) ClaimMetadataManagementServiceImpl(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl) ClaimMetadataManagementService(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService) DefaultClaimConfigInitDAO(org.wso2.carbon.identity.claim.metadata.mgt.internal.impl.DefaultClaimConfigInitDAO) BundleContext(org.osgi.framework.BundleContext) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with ClaimMetadataManagementServiceImpl

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.

the class IdentityProviderManagementServiceTest method testGetAllLocalClaimUris.

@Test
public void testGetAllLocalClaimUris() throws Exception {
    ClaimMetadataManagementServiceImpl claimMetadataManagementService = mock(ClaimMetadataManagementServiceImpl.class);
    IdpMgtServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
    LocalClaim localClaim1 = new LocalClaim("http://wso2.org/claims/test1");
    List<LocalClaim> claimList = new ArrayList<>();
    claimList.add(localClaim1);
    when(claimMetadataManagementService.getLocalClaims(anyString())).thenReturn(claimList);
    String[] allLocalClaimUris = identityProviderManagementService.getAllLocalClaimUris();
    Assert.assertEquals(allLocalClaimUris.length, 1);
    Assert.assertEquals(allLocalClaimUris[0], "http://wso2.org/claims/test1");
}
Also used : ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) Matchers.anyString(org.mockito.Matchers.anyString) ClaimMetadataManagementServiceImpl(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl) Test(org.testng.annotations.Test)

Aggregations

ClaimMetadataManagementServiceImpl (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl)4 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)2 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)2 HashSet (java.util.HashSet)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BundleContext (org.osgi.framework.BundleContext)1 Activate (org.osgi.service.component.annotations.Activate)1 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)1 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)1 ClaimMetadataManagementService (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService)1 ClaimMetadataStoreFactory (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataStoreFactory)1 DefaultClaimConfigInitDAO (org.wso2.carbon.identity.claim.metadata.mgt.internal.impl.DefaultClaimConfigInitDAO)1 ClaimMetadataManagementAuditLogger (org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataManagementAuditLogger)1 ClaimMetadataTenantMgtListener (org.wso2.carbon.identity.claim.metadata.mgt.listener.ClaimMetadataTenantMgtListener)1 ClaimDialect (org.wso2.carbon.identity.claim.metadata.mgt.model.ClaimDialect)1 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 TenantMgtListener (org.wso2.carbon.stratos.common.listeners.TenantMgtListener)1