Package org.pac4j.core.context

Examples of org.pac4j.core.context.MockWebContext


    }

    public void testAjaxRequest() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        try {
            client.redirect(context, false, true);
            fail("should fail");
        } catch (RequiresHttpAction e) {
            assertEquals(401, e.getCode());
            assertEquals(401, context.getResponseStatus());
        }
    }
View Full Code Here


    }

    public void testAlreadyTried() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        context.setSessionAttribute(client.getName() + BaseClient.ATTEMPTED_AUTHENTICATION_SUFFIX, "true");
        try {
            client.redirect(context, true, false);
            fail("should fail");
        } catch (RequiresHttpAction e) {
            assertEquals(403, e.getCode());
            assertEquals(403, context.getResponseStatus());
        }
    }
View Full Code Here

    }

    public void testSaveAlreadyTried() throws RequiresHttpAction {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE);
        client.setCallbackUrl(CALLBACK_URL);
        final MockWebContext context = MockWebContext.create();
        client.getCredentials(context);
        assertEquals("true",
                (String) context.getSessionAttribute(client.getName() + BaseClient.ATTEMPTED_AUTHENTICATION_SUFFIX));
    }
View Full Code Here

                (String) context.getSessionAttribute(client.getName() + BaseClient.ATTEMPTED_AUTHENTICATION_SUFFIX));
    }

    public void testStateParameter() {
        final MockBaseClient<Credentials> client = new MockBaseClient<Credentials>(TYPE);
        final MockWebContext context = MockWebContext.create();
        try {
            client.getStateParameter(context);
            fail("should fail");
        } catch (UnsupportedOperationException e) {
View Full Code Here

    public void testAuthenticationAndUserProfileRetrieval() throws Exception {
        ProfileHelper.setKeepRawData(true);
        try {
            final Client client = getClient();

            final MockWebContext context = MockWebContext.create();
            final WebClient webClient = TestsHelper.newWebClient(isJavascriptEnabled());

            final HtmlPage redirectionPage = getRedirectionPage(webClient, client, context);

            updateContextForAuthn(webClient, redirectionPage, context);
View Full Code Here

    // Default implementation use getCallbackUrl method
    protected void updateContextForAuthn(WebClient webClient, HtmlPage redirectionPage, MockWebContext context)
            throws Exception {
        final String callbackUrl = getCallbackUrl(webClient, redirectionPage);
        final MockWebContext mockWebContext = context;
        mockWebContext.addRequestParameters(TestsHelper.getParametersFromUrl(callbackUrl));
    }
View Full Code Here

    public void testCancelAuthentication() throws Exception {
        if (isCancellable()) {
            final Client client = getClient();

            final MockWebContext context = MockWebContext.create();
            final WebClient webClient = TestsHelper.newWebClient(isJavascriptEnabled());

            final HtmlPage redirectionPage = getRedirectionPage(webClient, client, context);

            updateContextForCancel(redirectionPage, context);
View Full Code Here

        }
    }

    protected void updateContextForCancel(HtmlPage redirectionPage, WebContext context) throws Exception {
        final String callbackUrl = getCallbackUrlForCancel(redirectionPage);
        final MockWebContext mockWebContext = (MockWebContext) context;
        mockWebContext.addRequestParameters(TestsHelper.getParametersFromUrl(callbackUrl));
    }
View Full Code Here

    }

    @Override
    protected void updateContextForAuthn(WebClient webClient, HtmlPage authorizationPage, MockWebContext context)
            throws Exception {
        final MockWebContext mockWebContext = context;
        final HtmlForm form = authorizationPage.getForms().get(0);
        final HtmlTextInput email = form.getInputByName("j_username");
        email.setValueAttribute("myself");
        final HtmlPasswordInput password = form.getInputByName("j_password");
        password.setValueAttribute("myself");
        final HtmlSubmitInput submit = form.getInputByValue("Login");
        final HtmlPage callbackPage = submit.click();
        String samlResponse = ((HtmlInput) callbackPage.getElementByName("SAMLResponse")).getValueAttribute();
        String relayState = ((HtmlInput) callbackPage.getElementByName("RelayState")).getValueAttribute();
        mockWebContext.addRequestParameter("SAMLResponse", samlResponse);
        mockWebContext.addRequestParameter("RelayState", relayState);
        mockWebContext.setRequestMethod("POST");
        mockWebContext.setFullRequestURL(callbackPage.getForms().get(0).getActionAttribute());
    }
View Full Code Here

        return basicAuthClient;
    }
   
    public void testRedirectionUrl() throws RequiresHttpAction {
        final BasicAuthClient basicAuthClient = getBasicAuthClient();
        MockWebContext context = MockWebContext.create();
        basicAuthClient.redirect(context, false, false);
        assertEquals(CALLBACK_URL, context.getResponseLocation());
    }
View Full Code Here

TOP

Related Classes of org.pac4j.core.context.MockWebContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.