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;
}
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());
}
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));
}
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);
}
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;
}
Aggregations