Search in sources :

Example 1 with StepBasedSequenceHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler in project carbon-identity-framework by wso2.

the class FrameworkUtils method getStepBasedSequenceHandler.

/**
 * Returns the step based sequence handler.
 * @return
 */
public static StepBasedSequenceHandler getStepBasedSequenceHandler() {
    StepBasedSequenceHandler stepBasedSequenceHandler;
    Object obj = ConfigurationFacade.getInstance().getExtensions().get(FrameworkConstants.Config.QNAME_EXT_STEP_BASED_SEQ_HANDLER);
    if (obj instanceof StepBasedSequenceHandler) {
        stepBasedSequenceHandler = (StepBasedSequenceHandler) obj;
    } else {
        stepBasedSequenceHandler = new GraphBasedSequenceHandler();
    }
    return stepBasedSequenceHandler;
}
Also used : GraphBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler) JSONObject(org.json.JSONObject) StepBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler)

Example 2 with StepBasedSequenceHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler 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 3 with StepBasedSequenceHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testHandleMultiOptionStep.

@Test
public void testHandleMultiOptionStep() throws Exception {
    StepHandler stepHandler = getMockedStepHandlerForIncompleteStep(true);
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getStepHandler()).thenReturn(stepHandler);
    StepConfig firstStep = new StepConfig();
    firstStep.setOrder(1);
    // Second step is completed.
    StepConfig lastStep = new StepConfig();
    lastStep.setMultiOption(true);
    lastStep.setOrder(2);
    lastStep.setCompleted(true);
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.getStepMap().put(1, firstStep);
    sequenceConfig.getStepMap().put(2, lastStep);
    doNothing().when(stepBasedSequenceHandler).handlePostAuthentication(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationContext.class));
    // currently we have completed second step
    context.setCurrentStep(2);
    context.setSequenceConfig(sequenceConfig);
    context.setRequestAuthenticated(false);
    stepBasedSequenceHandler.handle(request, response, context);
    assertResetContext(context);
    // Assert whether the sequence is retrying the step
    assertTrue(context.getSequenceConfig().getStepMap().get(context.getCurrentStep()).isRetrying());
    // Assert whether before retrying the context request authentication status was set to true.
    assertTrue(context.isRequestAuthenticated());
    // step handler completes the step successfully
    stepHandler = getMockedStepHandlerForSuccessfulRequestAuthentication();
    when(FrameworkUtils.getStepHandler()).thenReturn(stepHandler);
    stepBasedSequenceHandler.handle(request, response, context);
    assertTrue(context.getSequenceConfig().isCompleted());
    assertTrue(context.isRequestAuthenticated());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) StepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with StepBasedSequenceHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testHandleSingleStepFinish.

@Test
public void testHandleSingleStepFinish() throws Exception {
    // mock the step handler
    StepHandler stepHandler = getMockedStepHandlerForSuccessfulRequestAuthentication();
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getStepHandler()).thenReturn(stepHandler);
    StepConfig stepConfig = new StepConfig();
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.getStepMap().put(1, stepConfig);
    context.setSequenceConfig(sequenceConfig);
    doNothing().when(stepBasedSequenceHandler).handlePostAuthentication(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationContext.class));
    stepBasedSequenceHandler.handle(request, response, context);
    assertTrue(context.getSequenceConfig().isCompleted());
    assertTrue(context.isRequestAuthenticated());
    assertResetContext(context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) StepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with StepBasedSequenceHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler in project carbon-identity-framework by wso2.

the class FrameworkUtilsTest method testGetStepBasedSequenceHandlerExistingHandler.

@Test
public void testGetStepBasedSequenceHandlerExistingHandler() {
    DefaultStepBasedSequenceHandler testStepBasedSequenceHandler = new DefaultStepBasedSequenceHandler();
    ConfigurationFacade.getInstance().getExtensions().put(FrameworkConstants.Config.QNAME_EXT_STEP_BASED_SEQ_HANDLER, testStepBasedSequenceHandler);
    Object stepBasedSequenceHandler = FrameworkUtils.getStepBasedSequenceHandler();
    assertEquals(stepBasedSequenceHandler, testStepBasedSequenceHandler);
}
Also used : DefaultStepBasedSequenceHandler(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.DefaultStepBasedSequenceHandler) Mockito.anyObject(org.mockito.Mockito.anyObject) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Aggregations

PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Test (org.testng.annotations.Test)7 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)5 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)4 StepHandler (org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler)4 Mockito.anyObject (org.mockito.Mockito.anyObject)2 BeforeTest (org.testng.annotations.BeforeTest)2 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)2 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1 ApplicationConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ApplicationConfig)1 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)1 StepBasedSequenceHandler (org.wso2.carbon.identity.application.authentication.framework.handler.sequence.StepBasedSequenceHandler)1 DefaultStepBasedSequenceHandler (org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.DefaultStepBasedSequenceHandler)1 GraphBasedSequenceHandler (org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1