Search in sources :

Example 56 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class FileBasedApplicationDAO method getServiceProviderToLocalIdPClaimMapping.

@Override
public Map<String, String> getServiceProviderToLocalIdPClaimMapping(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider = ApplicationManagementServiceComponent.getFileBasedSPs().get(serviceProviderName);
    Map<String, String> claimMap = new HashMap<String, String>();
    if (serviceProvider == null || serviceProvider.getClaimConfig() == null) {
        return claimMap;
    }
    ClaimMapping[] claimMappings = serviceProvider.getClaimConfig().getClaimMappings();
    if (claimMappings != null && claimMappings.length > 0) {
        for (ClaimMapping mapping : claimMappings) {
            if (mapping.getLocalClaim() != null && mapping.getLocalClaim().getClaimUri() != null && mapping.getRemoteClaim() != null && mapping.getRemoteClaim().getClaimUri() != null) {
                claimMap.put(mapping.getRemoteClaim().getClaimUri(), mapping.getLocalClaim().getClaimUri());
            }
        }
    }
    return claimMap;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider)

Example 57 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class SSOConsentServiceImplTest method getAuthenticatedUser.

private AuthenticatedUser getAuthenticatedUser() {
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setAuthenticatedSubjectIdentifier("");
    Map<ClaimMapping, String> userAttributes = new HashMap<>();
    Claim tempClaim1 = new Claim();
    tempClaim1.setClaimUri("http://wso2.org/claims/organization");
    ClaimMapping tempClaimMapping1 = new ClaimMapping();
    tempClaimMapping1.setRequested(false);
    tempClaimMapping1.setMandatory(false);
    tempClaimMapping1.setLocalClaim(tempClaim1);
    tempClaimMapping1.setRemoteClaim(tempClaim1);
    userAttributes.put(tempClaimMapping1, "WSO2");
    Claim tempClaim2 = new Claim();
    tempClaim2.setClaimUri("http://wso2.org/claims/country");
    ClaimMapping tempClaimMapping2 = new ClaimMapping();
    tempClaimMapping1.setRequested(false);
    tempClaimMapping1.setMandatory(false);
    tempClaimMapping2.setLocalClaim(tempClaim2);
    tempClaimMapping2.setRemoteClaim(tempClaim2);
    userAttributes.put(tempClaimMapping2, "Sri Lanka");
    authenticatedUser.setUserAttributes(userAttributes);
    authenticatedUser.setFederatedUser(false);
    authenticatedUser.setTenantDomain("carbon.super");
    authenticatedUser.setUserStoreDomain("PRIMARY");
    authenticatedUser.setUserName("alexy");
    return authenticatedUser;
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Claim(org.wso2.carbon.identity.application.common.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Example 58 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping 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 59 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class SSOConsentServiceImplTest method testGetClaimsWithConsents.

@Test
public void testGetClaimsWithConsents() 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 tempClaim = new Claim();
    tempClaim.setClaimUri(TEMPORARY_CLAIM_URI);
    ClaimMapping tempClaimMapping = new ClaimMapping();
    tempClaimMapping.setRequested(true);
    tempClaimMapping.setLocalClaim(tempClaim);
    tempClaimMapping.setRemoteClaim(tempClaim);
    claimConfig.setClaimMappings(new ClaimMapping[] { tempClaimMapping });
    serviceProvider.setClaimConfig(claimConfig);
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = new LocalAndOutboundAuthenticationConfig();
    localAndOutboundAuthenticationConfig.setSubjectClaimUri(null);
    serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
    AuthenticatedUser authenticatedUser = getAuthenticatedUser();
    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);
    assertNotNull(ssoConsentService.getClaimsWithConsents(serviceProvider, authenticatedUser));
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) User(org.wso2.carbon.identity.application.common.model.User) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) 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) ConsentManagerImpl(org.wso2.carbon.consent.mgt.core.ConsentManagerImpl) ConsentManager(org.wso2.carbon.consent.mgt.core.ConsentManager) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) 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 60 with ClaimMapping

use of org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testGetIdpRoleClaimUriFromClaimMappings.

@Test(dataProvider = "idpClaimMappingProvider")
public void testGetIdpRoleClaimUriFromClaimMappings(Object claimMappings, String expectedRoleClaimUri) throws Exception {
    Util.mockIdentityUtil();
    ExternalIdPConfig externalIdPConfig = mock(ExternalIdPConfig.class);
    when(externalIdPConfig.getClaimMappings()).thenReturn((ClaimMapping[]) claimMappings);
    String roleClaim = stepBasedSequenceHandler.getIdpRoleClaimUri(externalIdPConfig);
    assertEquals(roleClaim, expectedRoleClaimUri);
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)109 HashMap (java.util.HashMap)60 ArrayList (java.util.ArrayList)52 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)28 Map (java.util.Map)26 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)24 ClaimMapping (org.wso2.carbon.identity.application.common.model.xsd.ClaimMapping)24 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)24 Claim (org.wso2.carbon.identity.application.common.model.Claim)23 Test (org.testng.annotations.Test)22 Claim (org.wso2.carbon.identity.application.common.model.xsd.Claim)21 LocalClaim (org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)21 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)20 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)20 List (java.util.List)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 UserStoreException (org.wso2.carbon.user.api.UserStoreException)17 Matchers.anyString (org.mockito.Matchers.anyString)16 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)14 ClaimMetadataException (org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException)13