Search in sources :

Example 81 with ServiceProvider

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

the class PostAuthAssociationHandlerTest method processAndGetAuthenticationContext.

/**
 * To get the authentication context and to call the handle method of the PostAuthAssociationHandler.
 *
 * @param sp1 Service Provider
 * @return relevant authentication context.
 * @throws FrameworkException Framework Exception.
 */
private AuthenticationContext processAndGetAuthenticationContext(ServiceProvider sp1, boolean withAuthenticatedUser, boolean isFederated, boolean withSpRoleMapping) throws FrameworkException {
    AuthenticationContext context = getAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.emptyMap(), sp1);
    sequenceConfig.getApplicationConfig().setAlwaysSendMappedLocalSubjectId(true);
    context.setSequenceConfig(sequenceConfig);
    context.setProperty(FrameworkConstants.STEP_BASED_SEQUENCE_HANDLER_TRIGGERED, true);
    ApplicationAuthenticator applicationAuthenticator = mock(ApplicationAuthenticator.class);
    if (isFederated) {
        applicationAuthenticator = mock(FederatedApplicationAuthenticator.class);
    }
    when(applicationAuthenticator.getName()).thenReturn("Authenticator1");
    if (withAuthenticatedUser) {
        AuthenticatedUser authenticatedUser = new AuthenticatedUser();
        authenticatedUser.setUserName("federated");
        authenticatedUser.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        authenticatedUser.setAuthenticatedSubjectIdentifier("federated");
        sequenceConfig.setAuthenticatedUser(authenticatedUser);
        AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
        authenticatorConfig.setApplicationAuthenticator(applicationAuthenticator);
        for (Map.Entry<Integer, StepConfig> entry : sequenceConfig.getStepMap().entrySet()) {
            StepConfig stepConfig = entry.getValue();
            stepConfig.setAuthenticatedAutenticator(authenticatorConfig);
            stepConfig.setAuthenticatedUser(authenticatedUser);
        }
        context.setSequenceConfig(sequenceConfig);
    }
    if (withSpRoleMapping) {
        sequenceConfig.getApplicationConfig().getClaimMappings().put(getLocalGroupsClaimURI(), getLocalGroupsClaimURI());
        sequenceConfig.getApplicationConfig().getServiceProvider().getClaimConfig().setLocalClaimDialect(true);
        sequenceConfig.getApplicationConfig().getRoleMappings().put(ORI_ROLE_1, SP_MAPPED_ROLE_1);
        sequenceConfig.getApplicationConfig().getRoleMappings().put(ORI_ROLE_2, SP_MAPPED_ROLE_2);
    }
    return context;
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) ApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) FederatedApplicationAuthenticator(org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Map(java.util.Map) HashMap(java.util.HashMap)

Example 82 with ServiceProvider

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

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

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

the class DefaultStepBasedSequenceHandlerTest method testHandlePostUserName.

@Test(dataProvider = "postAuthenticationDataProvider")
public void testHandlePostUserName(String subjectClaimUriFromAppConfig, String spSubjectClaimValue, boolean appendTenantDomainToSubject, boolean appendUserStoreDomainToSubject, String authenticatedUserNameInSequence, String expectedSubjectIdentifier) throws Exception {
    stepBasedSequenceHandler = new DefaultStepBasedSequenceHandler();
    ApplicationConfig applicationConfig = spy(new ApplicationConfig(new ServiceProvider()));
    when(applicationConfig.getSubjectClaimUri()).thenReturn(subjectClaimUriFromAppConfig);
    when(applicationConfig.isUseTenantDomainInLocalSubjectIdentifier()).thenReturn(appendTenantDomainToSubject);
    when(applicationConfig.isUseUserstoreDomainInLocalSubjectIdentifier()).thenReturn(appendUserStoreDomainToSubject);
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    authenticatedUser.setUserName(authenticatedUserNameInSequence);
    authenticatedUser.setTenantDomain(FOO_TENANT);
    authenticatedUser.setUserStoreDomain(XY_USER_STORE_DOMAIN);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    Map<Integer, StepConfig> stepConfigMap = new HashMap<>();
    StepConfig stepConfig = spy(new StepConfig());
    when(stepConfig.getAuthenticatedUser()).thenReturn(authenticatedUser);
    when(stepConfig.isSubjectIdentifierStep()).thenReturn(false);
    when(stepConfig.isSubjectAttributeStep()).thenReturn(false);
    AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig();
    authenticatorConfig.setApplicationAuthenticator(authenticator);
    when(stepConfig.getAuthenticatedAutenticator()).thenReturn(authenticatorConfig);
    stepConfigMap.put(1, stepConfig);
    sequenceConfig.setStepMap(stepConfigMap);
    sequenceConfig.setAuthenticatedUser(authenticatedUser);
    sequenceConfig.setApplicationConfig(applicationConfig);
    // SP subject claim value
    context.setProperty(FrameworkConstants.SERVICE_PROVIDER_SUBJECT_CLAIM_VALUE, spSubjectClaimValue);
    context.setSequenceConfig(sequenceConfig);
    stepBasedSequenceHandler.handlePostAuthentication(request, response, context);
    assertEquals(context.getSequenceConfig().getAuthenticatedUser().getUserName(), authenticatedUserNameInSequence);
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) HashMap(java.util.HashMap) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 85 with ServiceProvider

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

the class DefaultStepBasedSequenceHandlerTest method getMockedContextForJitProvisioning.

private AuthenticationContext getMockedContextForJitProvisioning(String provisioningUserStoreId, String provisioningUserStoreClaimUri, String tenantDomain) {
    ExternalIdPConfig externalIdPConfig = spy(new ExternalIdPConfig());
    when(externalIdPConfig.getProvisioningUserStoreId()).thenReturn(provisioningUserStoreId);
    when(externalIdPConfig.getProvisioningUserStoreClaimURI()).thenReturn(provisioningUserStoreClaimUri);
    ApplicationConfig applicationConfig = new ApplicationConfig(new ServiceProvider());
    applicationConfig.setApplicationName("DUMMY_NAME");
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.setApplicationConfig(applicationConfig);
    context.setTenantDomain(tenantDomain);
    context.setSequenceConfig(sequenceConfig);
    context.setExternalIdP(externalIdPConfig);
    return context;
}
Also used : ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ThreadLocalProvisioningServiceProvider(org.wso2.carbon.identity.application.common.model.ThreadLocalProvisioningServiceProvider) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19