Search in sources :

Example 1 with ConfigurationFacade

use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project carbon-identity-framework by wso2.

the class PostAuthAssociationHandlerTest method setupSuite.

@BeforeMethod
protected void setupSuite() throws Exception {
    configurationLoader = new UIBasedConfigurationLoader();
    mockStatic(FrameworkUtils.class);
    mockStatic(ConfigurationFacade.class);
    mockStatic(ClaimMetadataHandler.class);
    mockStatic(IdentityTenantUtil.class);
    ConfigurationFacade configurationFacade = mock(ConfigurationFacade.class);
    PowerMockito.when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
    ClaimMetadataHandler claimMetadataHandler = mock(ClaimMetadataHandler.class);
    PowerMockito.when(ClaimMetadataHandler.getInstance()).thenReturn(claimMetadataHandler);
    Map<String, String> emptyMap = new HashMap<>();
    PowerMockito.when(ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(Mockito.anyString(), Mockito.anySet(), Mockito.anyString(), Mockito.anyBoolean())).thenReturn(emptyMap);
    IdentityProvider identityProvider = getTestIdentityProvider("default-tp-1.xml");
    ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(identityProvider);
    Mockito.doReturn(externalIdPConfig).when(configurationFacade).getIdPConfigByName(Mockito.anyString(), Mockito.anyString());
    when(FrameworkUtils.isStepBasedSequenceHandlerExecuted(Mockito.any(AuthenticationContext.class))).thenCallRealMethod();
    when(FrameworkUtils.prependUserStoreDomainToName(Mockito.anyString())).thenCallRealMethod();
    when(FrameworkUtils.buildClaimMappings(Mockito.anyMap())).thenCallRealMethod();
    when(FrameworkUtils.getStandardDialect(Mockito.anyString(), Mockito.any(ApplicationConfig.class))).thenCallRealMethod();
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    postAuthAssociationHandler = PostAuthAssociationHandler.getInstance();
    sp = getTestServiceProvider("default-sp-1.xml");
    PowerMockito.when(FrameworkUtils.getMultiAttributeSeparator()).thenReturn(",");
    ClaimHandler claimHandler = PowerMockito.mock(ClaimHandler.class);
    Map<String, String> claims = new HashMap<>();
    claims.put("claim1", "value1");
    claims.put(FrameworkConstants.LOCAL_ROLE_CLAIM_URI, String.format("%s,%s", ORI_ROLE_1, ORI_ROLE_2));
    PowerMockito.doReturn(claims).when(claimHandler).handleClaimMappings(any(StepConfig.class), any(AuthenticationContext.class), any(Map.class), anyBoolean());
    PowerMockito.when(FrameworkUtils.getClaimHandler()).thenReturn(claimHandler);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) ConfigurationFacade(org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade) ClaimMetadataHandler(org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataHandler) HashMap(java.util.HashMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Matchers.anyString(org.mockito.Matchers.anyString) ClaimHandler(org.wso2.carbon.identity.application.authentication.framework.handler.claims.ClaimHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) UIBasedConfigurationLoader(org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader) ApplicationConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) Map(java.util.Map) HashMap(java.util.HashMap) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with ConfigurationFacade

use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project identity-governance by wso2-extensions.

the class PostAuthnMissingChallengeQuestionsHandlerTest method testBeforeRequestingChallengeQuestionFlow.

@Test(description = "Test the flow of challenge question post authentication handler before requesting challenge " + "questions from the user")
public void testBeforeRequestingChallengeQuestionFlow() throws Exception {
    AuthenticationContext context = spy(new AuthenticationContext());
    when(context.getTenantDomain()).thenReturn("carbon.super");
    IdentityProvider residentIdp = spy(new IdentityProvider());
    IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
    IdentityProviderProperty idpProp = new IdentityProviderProperty();
    idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
    idpProp.setValue("true");
    idpProperties[0] = idpProp;
    residentIdp.setIdpProperties(idpProperties);
    mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    AuthenticatedUser user = spy(new AuthenticatedUser());
    user.setUserName("admin");
    when(sequenceConfig.getAuthenticatedUser()).thenReturn(user);
    context.setSequenceConfig(sequenceConfig);
    mockedMultitenantUtils.when(() -> MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
    mockedUtils.when(() -> Utils.getTenantId("carbon.super")).thenReturn(-1234);
    mockedIdentityRecoveryServiceDataHolder.when(IdentityRecoveryServiceDataHolder::getInstance).thenReturn(frameworkServiceDataHolder);
    RealmService realmService = mock(RealmService.class);
    UserStoreManager userStoreManager = mock(UserStoreManager.class);
    UserRealm userRealm = mock(UserRealm.class);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    when(frameworkServiceDataHolder.getRealmService()).thenReturn(realmService);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    Map<String, String> claimsMap = new HashMap<>();
    when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
    List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
    ChallengeQuestion challengeQuestion = spy(new ChallengeQuestion());
    challengeQuestion.setQuestionSetId("dummy_set");
    challengeQuestion.setQuestionId("dummy_id");
    challengeQuestion.setQuestion("dummy_question");
    challengeQuestions.add(challengeQuestion);
    when(challengeQuestionManager.getAllChallengeQuestions("carbon.super")).thenReturn(challengeQuestions);
    mockedChallengeQuestionManager.when(ChallengeQuestionManager::getInstance).thenReturn(challengeQuestionManager);
    doNothing().doThrow(Exception.class).when(httpServletResponse).sendRedirect((String) any());
    when(configurationFacade.getAuthenticationEndpointURL()).thenReturn("");
    when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
    PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
    String expectedResult = PostAuthnHandlerFlowStatus.INCOMPLETE.name();
    assertEquals(flowStatus.name(), expectedResult);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) UserRealm(org.wso2.carbon.user.core.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) RealmService(org.wso2.carbon.user.core.service.RealmService) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion) Test(org.testng.annotations.Test)

Example 3 with ConfigurationFacade

use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project carbon-identity-framework by wso2.

the class JITProvisioningPostAuthenticationHandlerTest method setupSuite.

@BeforeClass
protected void setupSuite() throws XMLStreamException, IdentityProviderManagementException {
    configurationLoader = new UIBasedConfigurationLoader();
    mockStatic(FrameworkUtils.class);
    mockStatic(ConfigurationFacade.class);
    ConfigurationFacade configurationFacade = mock(ConfigurationFacade.class);
    PowerMockito.when(ConfigurationFacade.getInstance()).thenReturn(configurationFacade);
    IdentityProvider identityProvider = getTestIdentityProvider("default-tp-1.xml");
    ExternalIdPConfig externalIdPConfig = new ExternalIdPConfig(identityProvider);
    Mockito.doReturn(externalIdPConfig).when(configurationFacade).getIdPConfigByName(Mockito.anyString(), Mockito.anyString());
    when(FrameworkUtils.isStepBasedSequenceHandlerExecuted(Mockito.any(AuthenticationContext.class))).thenCallRealMethod();
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    postJITProvisioningHandler = JITProvisioningPostAuthenticationHandler.getInstance();
    sp = getTestServiceProvider("default-sp-1.xml");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UIBasedConfigurationLoader(org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) ConfigurationFacade(org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade) HttpServletResponse(javax.servlet.http.HttpServletResponse) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with ConfigurationFacade

use of org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade in project identity-governance by wso2-extensions.

the class PostAuthnMissingChallengeQuestionsHandlerTest method testAfterRequestingChallengeQuestionFlow.

@Test(description = "Test the flow of challenge question post authentication handler after requesting challenge " + "questions from the user")
public void testAfterRequestingChallengeQuestionFlow() throws Exception {
    AuthenticationContext context = spy(new AuthenticationContext());
    when(context.getTenantDomain()).thenReturn("carbon.super");
    IdentityProvider residentIdp = spy(new IdentityProvider());
    IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[1];
    IdentityProviderProperty idpProp = new IdentityProviderProperty();
    idpProp.setName(IdentityRecoveryConstants.ConnectorConfig.FORCE_ADD_PW_RECOVERY_QUESTION);
    idpProp.setValue("true");
    idpProperties[0] = idpProp;
    residentIdp.setIdpProperties(idpProperties);
    mockedIdentityProviderManager.when(IdentityProviderManager::getInstance).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP("carbon.super")).thenReturn(residentIdp);
    SequenceConfig sequenceConfig = spy(new SequenceConfig());
    AuthenticatedUser user = spy(new AuthenticatedUser());
    user.setUserName("admin");
    when(sequenceConfig.getAuthenticatedUser()).thenReturn(user);
    context.setSequenceConfig(sequenceConfig);
    mockedMultitenantUtils.when(() -> MultitenantUtils.getTenantDomain("admin")).thenReturn("carbon.super");
    mockedUtils.when(() -> Utils.getTenantId("carbon.super")).thenReturn(-1234);
    mockedIdentityRecoveryServiceDataHolder.when(IdentityRecoveryServiceDataHolder::getInstance).thenReturn(frameworkServiceDataHolder);
    RealmService realmService = mock(RealmService.class);
    UserStoreManager userStoreManager = mock(UserStoreManager.class);
    UserRealm userRealm = mock(UserRealm.class);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
    when(frameworkServiceDataHolder.getRealmService()).thenReturn(realmService);
    when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
    Map<String, String> claimsMap = new HashMap<>();
    when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
    List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
    ChallengeQuestion challengeQuestion = spy(new ChallengeQuestion());
    challengeQuestion.setQuestionSetId("dummy_set");
    challengeQuestion.setQuestionId("dummy_id");
    challengeQuestion.setQuestion("dummy_question");
    challengeQuestions.add(challengeQuestion);
    when(challengeQuestionManager.getAllChallengeQuestions("carbon.super")).thenReturn(challengeQuestions);
    mockedChallengeQuestionManager.when(ChallengeQuestionManager::getInstance).thenReturn(challengeQuestionManager);
    doNothing().doThrow(Exception.class).when(httpServletResponse).sendRedirect((String) any());
    when(configurationFacade.getAuthenticationEndpointURL()).thenReturn("");
    mockedConfigurationFacade.when(ConfigurationFacade::getInstance).thenReturn(configurationFacade);
    when(context.getParameter(CHALLENGE_QUESTIONS_REQUESTED)).thenReturn(true);
    Vector<String> set = new Vector<>();
    set.add("Q-dummy_question");
    set.add("A-dummy_answer");
    Enumeration<String> paramNames = new Vector(set).elements();
    when(httpServletRequest.getParameterNames()).thenReturn(paramNames);
    when(httpServletRequest.getParameter(anyString())).thenReturn("dummy_question");
    PostAuthnHandlerFlowStatus flowStatus = PostAuthnMissingChallengeQuestionsHandler.getInstance().handle(httpServletRequest, httpServletResponse, context);
    String expectedResult = PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED.name();
    assertEquals(flowStatus.name(), expectedResult);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) UserRealm(org.wso2.carbon.user.core.UserRealm) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) RealmService(org.wso2.carbon.user.core.service.RealmService) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Vector(java.util.Vector) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion) Test(org.testng.annotations.Test)

Aggregations

AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)4 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Test (org.testng.annotations.Test)2 ConfigurationFacade (org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade)2 UIBasedConfigurationLoader (org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader)2 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)2 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)2 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)2 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)2 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)2 ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)2 UserRealm (org.wso2.carbon.user.core.UserRealm)2 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)2 RealmService (org.wso2.carbon.user.core.service.RealmService)2 Map (java.util.Map)1