Search in sources :

Example 1 with ClaimMetadataManagementService

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService 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 ClaimMetadataManagementService

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

the class SSOConsentServiceImplTest method testGetConsentRequiredClaimsWithExistingConsents.

@Test
public void testGetConsentRequiredClaimsWithExistingConsents() throws Exception {
    ServiceProvider serviceProvider = new ServiceProvider();
    serviceProvider.setApplicationName("Travelocity.com");
    User user = new User();
    user.setTenantDomain("carbon.super");
    user.setUserStoreDomain("PRIMARY");
    serviceProvider.setOwner(user);
    ClaimConfig claimConfig = new ClaimConfig();
    Claim tempClaim1 = new Claim();
    tempClaim1.setClaimUri("http://wso2.org/claims/organization");
    ClaimMapping tempClaimMapping1 = new ClaimMapping();
    tempClaimMapping1.setRequested(true);
    tempClaimMapping1.setMandatory(false);
    tempClaimMapping1.setLocalClaim(tempClaim1);
    tempClaimMapping1.setRemoteClaim(tempClaim1);
    Claim tempClaim2 = new Claim();
    tempClaim2.setClaimUri("http://wso2.org/claims/country");
    ClaimMapping tempClaimMapping2 = new ClaimMapping();
    tempClaimMapping2.setRequested(true);
    tempClaimMapping2.setMandatory(true);
    tempClaimMapping2.setLocalClaim(tempClaim2);
    tempClaimMapping2.setRemoteClaim(tempClaim2);
    claimConfig.setClaimMappings(new ClaimMapping[] { tempClaimMapping1, tempClaimMapping2 });
    serviceProvider.setClaimConfig(claimConfig);
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = new LocalAndOutboundAuthenticationConfig();
    localAndOutboundAuthenticationConfig.setSubjectClaimUri(null);
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
    AuthenticatedUser authenticatedUser = getAuthenticatedUser();
    mockStatic(IdentityUtil.class);
    when(IdentityUtil.getProperty("Consent.PromptSubjectClaimRequestedConsent")).thenReturn(null);
    mockCarbonContextForTenant();
    mockStatic(FrameworkServiceDataHolder.class);
    when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
    setConsentManagerConfigurationHolder();
    RealmService realmService = mock(RealmService.class);
    configurationHolder.setRealmService(realmService);
    ConsentManager consentManager = new ConsentManagerImpl(configurationHolder);
    when(frameworkServiceDataHolder.getConsentManager()).thenReturn(consentManager);
    mockStatic(ConsentUtils.class);
    when(ConsentUtils.getTenantDomainFromCarbonContext()).thenReturn("carbon.super");
    mockRealmService(realmService);
    when(frameworkServiceDataHolder.getClaimMetadataManagementService()).thenReturn(claimMetadataManagementService);
    List<LocalClaim> localClaims = new ArrayList<>();
    LocalClaim localClaim = new LocalClaim("http://wso2.org/claims/country");
    LocalClaim localClaim2 = new LocalClaim("http://wso2.org/claims/organization");
    localClaims.add(localClaim);
    localClaims.add(localClaim2);
    when(claimMetadataManagementService.getLocalClaims(anyString())).thenReturn(localClaims);
    ConsentClaimsData consentClaimsData = ssoConsentService.getConsentRequiredClaimsWithExistingConsents(serviceProvider, authenticatedUser);
    assertEquals(consentClaimsData.getRequestedClaims().get(0).getClaimUri(), "http://wso2.org/claims/organization", "Incorrect requested claim URI");
    assertEquals(consentClaimsData.getMandatoryClaims().get(0).getClaimUri(), "http://wso2.org/claims/country", "Incorrect mandatory claim URI");
    assertNotNull(consentClaimsData.getMandatoryClaims().get(0).getClaimUri());
}
Also used : User(org.wso2.carbon.identity.application.common.model.User) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) ConsentManagerImpl(org.wso2.carbon.consent.mgt.core.ConsentManagerImpl) ArrayList(java.util.ArrayList) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) Claim(org.wso2.carbon.identity.application.common.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ClaimMetadataManagementService

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project identity-inbound-auth-oauth by wso2-extensions.

the class OpenIDConnectClaimFilterImplTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    openIDConnectClaimFilter = new OpenIDConnectClaimFilterImpl();
    scopeClaimMappingDAO = new ScopeClaimMappingDAOImpl();
    ServiceProvider serviceProvider = new ServiceProvider();
    ssoConsentService = mock(SSOConsentServiceImpl.class);
    ClaimMetadataManagementService claimMetadataManagementService = mock(ClaimMetadataManagementService.class);
    applicationMgtService = mock(ApplicationManagementService.class);
    OAuth2ServiceComponentHolder.setApplicationMgtService(applicationMgtService);
    when(applicationMgtService.getServiceProviderByClientId(CLIENT_ID, IdentityApplicationConstants.OAuth2.NAME, SP_TENANT_DOMAIN)).thenReturn(serviceProvider);
    OpenIDConnectServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
    OpenIDConnectServiceComponentHolder.getInstance().setSsoConsentService(ssoConsentService);
    RegistryService registryService = mock(RegistryService.class);
    UserRegistry userRegistry = mock(UserRegistry.class);
    resource = new ResourceImpl();
    OAuth2ServiceComponentHolder.setRegistryService(registryService);
    when(registryService.getConfigSystemRegistry(anyInt())).thenReturn(userRegistry);
    when(userRegistry.get(anyString())).thenReturn(resource);
    List externalClaims = new ArrayList<>();
    ExternalClaim externalClaim = new ExternalClaim("testUserClaimURI", "testUserClaimURI", "testUserClaimURI");
    externalClaims.add(externalClaim);
    when(claimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(externalClaims);
    List claimsWithConsent = getClaimsWithConsent();
    when(ssoConsentService.getClaimsWithConsents(any(), any())).thenReturn(claimsWithConsent);
}
Also used : ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) ArrayList(java.util.ArrayList) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) ArrayList(java.util.ArrayList) List(java.util.List) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) ScopeClaimMappingDAOImpl(org.wso2.carbon.identity.openidconnect.dao.ScopeClaimMappingDAOImpl) SSOConsentServiceImpl(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.SSOConsentServiceImpl) ClaimMetadataManagementService(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with ClaimMetadataManagementService

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService 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 ClaimMetadataManagementService

use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService 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

ClaimMetadataManagementService (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService)5 ArrayList (java.util.ArrayList)4 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)4 Test (org.testng.annotations.Test)3 ClaimMetadataManagementServiceImpl (org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl)3 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 ExternalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 Optional (java.util.Optional)1 MapUtils (org.apache.commons.collections.MapUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BundleContext (org.osgi.framework.BundleContext)1