Search in sources :

Example 6 with FrameworkServiceDataHolder

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

the class PostAuthnMissingChallengeQuestionsHandlerTest method testAlreadyChallengeQuestionProvidedUserFlow.

@Test(description = "Test the flow for the user who has already given the challenge questions")
public void testAlreadyChallengeQuestionProvidedUserFlow() 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<>();
    claimsMap.put(IdentityRecoveryConstants.CHALLENGE_QUESTION_URI, "dummy_data");
    when(userStoreManager.getUserClaimValues("admin", new String[] { IdentityRecoveryConstants.CHALLENGE_QUESTION_URI }, UserCoreConstants.DEFAULT_PROFILE)).thenReturn(claimsMap);
    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) 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) Test(org.testng.annotations.Test)

Example 7 with FrameworkServiceDataHolder

use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder 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 8 with FrameworkServiceDataHolder

use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandler method executeFunction.

private void executeFunction(String outcomeName, DynamicDecisionNode dynamicDecisionNode, AuthenticationContext context) {
    SerializableJsFunction fn = dynamicDecisionNode.getFunctionMap().get(outcomeName);
    FrameworkServiceDataHolder dataHolder = FrameworkServiceDataHolder.getInstance();
    JsGraphBuilderFactory jsGraphBuilderFactory = dataHolder.getJsGraphBuilderFactory();
    JsGraphBuilder graphBuilder = jsGraphBuilderFactory.createBuilder(context, context.getSequenceConfig().getAuthenticationGraph().getStepMap(), dynamicDecisionNode);
    JsGraphBuilder.JsBasedEvaluator jsBasedEvaluator = graphBuilder.new JsBasedEvaluator(fn);
    jsBasedEvaluator.evaluate(context, (jsConsumer) -> jsConsumer.call(null, new JsAuthenticationContext(context)));
    if (dynamicDecisionNode.getDefaultEdge() == null) {
        dynamicDecisionNode.setDefaultEdge(new EndStep());
    }
}
Also used : JsGraphBuilderFactory(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsGraphBuilder(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) EndStep(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep) SerializableJsFunction(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)

Example 9 with FrameworkServiceDataHolder

use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandler method evaluateHandler.

private Object evaluateHandler(String outcomeName, ShowPromptNode dynamicDecisionNode, AuthenticationContext context, Object stepId) {
    SerializableJsFunction fn = dynamicDecisionNode.getHandlerMap().get(outcomeName);
    FrameworkServiceDataHolder dataHolder = FrameworkServiceDataHolder.getInstance();
    JsGraphBuilderFactory jsGraphBuilderFactory = dataHolder.getJsGraphBuilderFactory();
    JsGraphBuilder graphBuilder = jsGraphBuilderFactory.createBuilder(context, context.getSequenceConfig().getAuthenticationGraph().getStepMap(), dynamicDecisionNode);
    JsGraphBuilder.JsBasedEvaluator jsBasedEvaluator = graphBuilder.new JsBasedEvaluator(fn);
    return jsBasedEvaluator.evaluate(context, (jsFunction) -> jsFunction.call(null, stepId, new JsAuthenticationContext(context)));
}
Also used : JsGraphBuilderFactory(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsGraphBuilder(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) SerializableJsFunction(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)

Example 10 with FrameworkServiceDataHolder

use of org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder in project carbon-identity-framework by wso2.

the class JITProvisioningPostAuthenticationHandlerTest method testHandleWithAuthenticatedUserWithFederatedIdp.

@Test(description = "This test case tests the Post JIT provisioning handling flow with an authenticated user")
public void testHandleWithAuthenticatedUserWithFederatedIdp() throws FrameworkException, FederatedAssociationManagerException, AccountLockServiceException, UserStoreException {
    AuthenticationContext context = processAndGetAuthenticationContext(sp, true, true);
    FederatedAssociationManager federatedAssociationManager = mock(FederatedAssociationManagerImpl.class);
    when(FrameworkUtils.getFederatedAssociationManager()).thenReturn(federatedAssociationManager);
    doReturn("test").when(federatedAssociationManager).getUserForFederatedAssociation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
    when(FrameworkUtils.getStepBasedSequenceHandler()).thenReturn(Mockito.mock(StepBasedSequenceHandler.class));
    mockStatic(FrameworkServiceDataHolder.class);
    PowerMockito.when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
    mockStatic(AccountLockService.class);
    when(frameworkServiceDataHolder.getAccountLockService()).thenReturn(accountLockService);
    when(accountLockService.isAccountLocked(anyString(), anyString())).thenReturn(false);
    RealmService mockRealmService = mock(RealmService.class);
    PowerMockito.when(FrameworkServiceDataHolder.getInstance().getRealmService()).thenReturn(mockRealmService);
    UserRealm mockUserRealm = mock(UserRealm.class);
    UserStoreManager mockUserStoreManager = mock(UserStoreManager.class);
    Map<String, String> mockClaimValues = mock(HashMap.class);
    mockStatic(IdentityTenantUtil.class);
    when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(1);
    when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
    when(mockUserRealm.getUserStoreManager()).thenReturn(mockUserStoreManager);
    when(mockUserStoreManager.getUserClaimValues(anyString(), eq(new String[] { AccountConstants.ACCOUNT_DISABLED_CLAIM }), eq(UserCoreConstants.DEFAULT_PROFILE))).thenReturn(mockClaimValues);
    when(mockClaimValues.get(AccountConstants.ACCOUNT_DISABLED_CLAIM)).thenReturn("false");
    PostAuthnHandlerFlowStatus postAuthnHandlerFlowStatus = postJITProvisioningHandler.handle(request, response, context);
    Assert.assertEquals(postAuthnHandlerFlowStatus, PostAuthnHandlerFlowStatus.SUCCESS_COMPLETED, "Post JIT provisioning handler executed while having a authenticated user without federated " + "authenticator");
}
Also used : FederatedAssociationManager(org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) UserRealm(org.wso2.carbon.user.core.UserRealm) RealmService(org.wso2.carbon.user.core.service.RealmService) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) Mockito.anyString(org.mockito.Mockito.anyString) StepBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler) PostAuthnHandlerFlowStatus(org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus) Test(org.testng.annotations.Test) AbstractFrameworkTest(org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.testng.annotations.Test)9 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)6 RealmService (org.wso2.carbon.user.core.service.RealmService)6 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)5 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 JsGraphBuilderFactory (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory)4 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)4 FrameworkServiceDataHolder (org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder)4 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)4 UserRealm (org.wso2.carbon.user.core.UserRealm)4 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 JsGraphBuilder (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder)3 SerializableJsFunction (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)3 JsAuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext)3 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)3 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)3