Search in sources :

Example 1 with StepHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method testHandleSingleStep.

/**
 * First step of the sequence is handled
 */
@Test
public void testHandleSingleStep() throws Exception {
    // mock the step handler
    StepHandler stepHandler = getMockedStepHandlerForIncompleteStep(true);
    mockStatic(FrameworkUtils.class);
    when(FrameworkUtils.getStepHandler()).thenReturn(stepHandler);
    StepConfig stepConfig = new StepConfig();
    SequenceConfig sequenceConfig = new SequenceConfig();
    sequenceConfig.getStepMap().put(1, stepConfig);
    context.setSequenceConfig(sequenceConfig);
    stepBasedSequenceHandler.handle(request, response, context);
    assertFalse(context.getSequenceConfig().isCompleted());
    assertTrue(context.isRequestAuthenticated());
}
Also used : StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) 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 2 with StepHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method getMockedStepHandlerForSuccessfulRequestAuthentication.

private StepHandler getMockedStepHandlerForSuccessfulRequestAuthentication() throws Exception {
    // mock the step handler
    StepHandler stepHandler = mock(StepHandler.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            AuthenticationContext context = invocationOnMock.getArgumentAt(2, AuthenticationContext.class);
            StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
            stepConfig.setCompleted(true);
            context.setRequestAuthenticated(true);
            return null;
        }
    }).when(stepHandler).handle(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationContext.class));
    return stepHandler;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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)

Example 3 with StepHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler in project carbon-identity-framework by wso2.

the class DefaultStepBasedSequenceHandlerTest method getMockedStepHandlerForIncompleteStep.

private StepHandler getMockedStepHandlerForIncompleteStep(final boolean isRequestAuthenticated) throws Exception {
    // mock the step handler
    StepHandler stepHandler = mock(StepHandler.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            AuthenticationContext context = invocationOnMock.getArgumentAt(2, AuthenticationContext.class);
            StepConfig stepConfig = context.getSequenceConfig().getStepMap().get(context.getCurrentStep());
            stepConfig.setCompleted(false);
            context.setRequestAuthenticated(isRequestAuthenticated);
            return null;
        }
    }).when(stepHandler).handle(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationContext.class));
    return stepHandler;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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)

Example 4 with StepHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler 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 5 with StepHandler

use of org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler in project carbon-identity-framework by wso2.

the class FrameworkUtilsTest method testGetStepHandlerExistHandler.

@Test
public void testGetStepHandlerExistHandler() {
    DefaultStepHandler testStepHandler = new DefaultStepHandler();
    ConfigurationFacade.getInstance().getExtensions().put(FrameworkConstants.Config.QNAME_EXT_STEP_HANDLER, testStepHandler);
    StepHandler stepHandler = FrameworkUtils.getStepHandler();
    assertEquals(stepHandler, testStepHandler);
}
Also used : DefaultStepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.DefaultStepHandler) DefaultStepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.DefaultStepHandler) StepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler) GraphBasedStepHandler(org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.GraphBasedStepHandler) 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

StepHandler (org.wso2.carbon.identity.application.authentication.framework.handler.step.StepHandler)9 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Test (org.testng.annotations.Test)6 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)6 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 GraphBasedStepHandler (org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.GraphBasedStepHandler)2 JSONObject (org.json.JSONObject)1 BeforeTest (org.testng.annotations.BeforeTest)1 DefaultStepHandler (org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.DefaultStepHandler)1 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)1