Package org.picketlink.test.identity.federation.bindings.mock

Examples of org.picketlink.test.identity.federation.bindings.mock.MockCatalinaResponse


        spEmpl.setContainer(context);
        spEmpl.testStart();

        MockCatalinaRequest catalinaRequest = new MockCatalinaRequest();

        MockCatalinaResponse catalinaResponse = new MockCatalinaResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        catalinaResponse.setOutputStream(baos);

        LoginConfig loginConfig = new LoginConfig();
        spEmpl.authenticate(catalinaRequest, catalinaResponse, loginConfig);

        String spResponse = new String(baos.toByteArray());
        Document spHTMLResponse = DocumentUtil.getDocument(spResponse);
        NodeList nodes = spHTMLResponse.getElementsByTagName("INPUT");
        Element inputElement = (Element) nodes.item(0);
        String idpResponse = inputElement.getAttributeNode("VALUE").getValue();
        @SuppressWarnings("unused")
        String relayState = null;
        if (nodes.getLength() > 1)
            relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();

        // Lets call the IDPServlet

        MockCatalinaSession session = new MockCatalinaSession();
        servletContext = new MockCatalinaContext();
        session.setServletContext(servletContext);
        IdentityServer server = this.getIdentityServer(session);
        servletContext.setAttribute("IDENTITY_SERVER", server);

        MockCatalinaContextClassLoader mclIDP = setupTCL(profile + "/idp");
        Thread.currentThread().setContextClassLoader(mclIDP);

        MockCatalinaRequest request = new MockCatalinaRequest();
        request.addHeader("Referer", "http://localhost:8080/employee/");

        request.setParameter(GeneralConstants.USERNAME_FIELD, "anil");
        request.setParameter(GeneralConstants.PASS_FIELD, "anil");

        MockCatalinaResponse response = new MockCatalinaResponse();
        baos = new ByteArrayOutputStream();
        response.setOutputStream(baos);

        context = new MockCatalinaContext();
        IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();
        idp.setContainer(context);
        idp.setSignOutgoingMessages(false);
View Full Code Here


        String idpResponse = PostBindingUtil.base64Encode(new String(readIDPResponse()));

        catalinaRequest.setParameter(GeneralConstants.SAML_RESPONSE_KEY, idpResponse);

        MockCatalinaResponse catalinaResponse = new MockCatalinaResponse();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        catalinaResponse.setWriter(new PrintWriter(baos));

        LoginConfig loginConfig = new LoginConfig();
        assertTrue(spEmpl.authenticate(catalinaRequest, catalinaResponse, loginConfig));

        Map<String, List<Object>> sessionMap = (Map<String, List<Object>>) session
View Full Code Here

    private void testWorkflow(String userAddress, String idpAddress) throws LifecycleException, IOException, ServletException {
        System.setProperty("picketlink.schema.validate", "true");
        MockCatalinaRequest request = AuthenticatorTestUtils.createRequest(userAddress, false);

        // Sends a initial request to the SP. Requesting a resource ...
        MockCatalinaResponse idpAuthRequest = sendSPRequest(request, false, idpAddress);

        assertNotNull("Redirect String can not be null.", idpAuthRequest.redirectString);

        // Sends a auth request to the IDP
        request = AuthenticatorTestUtils.createRequest(userAddress, true);

        setQueryStringFromResponse(idpAuthRequest, request);

        MockCatalinaResponse idpAuthResponse = sendIDPRequest(request);

        assertNotNull("Redirect String can not be null.", idpAuthResponse.redirectString);

        // Sends the IDP response to the SP. Now the user is succesfully authenticated and access for the requested resource is
        // granted...
View Full Code Here

    private MockCatalinaResponse sendIDPRequest(MockCatalinaRequest request) throws LifecycleException, IOException,
            ServletException {
        IDPWebBrowserSSOValve idp = createIdentityProvider();
        idp.setStrictPostBinding(false);

        MockCatalinaResponse response = new MockCatalinaResponse();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        response.setWriter(new PrintWriter(baos));

        idp.invoke(request, response);

        return response;
    }
View Full Code Here

    }

    private MockCatalinaResponse sendSPRequest(MockCatalinaRequest request, boolean validateAuthentication, String idpAddress)
            throws LifecycleException, IOException {

        MockCatalinaResponse response = new MockCatalinaResponse();

        if (validateAuthentication) {
            Assert.assertTrue("Employee app succesfully authenticated.",
                    getEmployeeServiceProvider().authenticate(request, response, new MockCatalinaLoginConfig()));
        } else {
View Full Code Here

        // requests a GLO logout to the Employee SP
        MockCatalinaRequest originalEmployeeLogoutRequest = createRequest(employeeHttpSession, true);

        originalEmployeeLogoutRequest.setParameter(GeneralConstants.GLOBAL_LOGOUT, "true");

        MockCatalinaResponse originalEmployeeLogoutResponse = sendSPRequest(originalEmployeeLogoutRequest,
                getEmployeeServiceProvider());

        assertNotNull(originalEmployeeLogoutResponse);

        // sends the LogoutRequest to the IDP
        MockCatalinaRequest idpLogoutRequest = createIDPRequest(true);

        setQueryStringFromResponse(originalEmployeeLogoutResponse, idpLogoutRequest);

        MockCatalinaResponse idpLogoutResponse = sendIDPRequest(idpLogoutRequest);

        // The IDP responds with a LogoutRequest. Send it to the Sales SP with the RelayState pointing to the Employee SP
        MockCatalinaRequest salesLogoutRequest = createRequest(salesHttpSession, true);

        setQueryStringFromResponse(idpLogoutResponse, salesLogoutRequest);

        MockCatalinaResponse salesLogoutResponse = sendSPRequest(salesLogoutRequest, getSalesServiceProvider());

        // At this moment the user is not logged in Sales SP anymore.
        assertTrue(this.salesHttpSession.isInvalidated());

        // sends the StatusResponse to the IDP to continue the logout process.
        MockCatalinaRequest processSalesStatusResponse = createIDPRequest(true);

        setQueryStringFromResponse(salesLogoutResponse, processSalesStatusResponse);

        MockCatalinaResponse salesStatusResponse = sendIDPRequest(processSalesStatusResponse);

        // The IDP responds with a LogoutRequest. Send it to the Employee SP.
        MockCatalinaRequest employeeLogoutRequest = createRequest(employeeHttpSession, true);

        setQueryStringFromResponse(salesStatusResponse, employeeLogoutRequest);

        MockCatalinaResponse employeeLogoutResponse = sendSPRequest(employeeLogoutRequest, getEmployeeServiceProvider());

        // At this moment the user is not logged in Employee SP anymore.
        assertTrue(this.employeeHttpSession.isInvalidated());

        Assert.assertNotNull(employeeLogoutRequest.getForwardPath());
View Full Code Here

        assertTrue(getIDPHttpSession().isInvalidated());
    }

    private MockCatalinaResponse sendSPRequest(MockCatalinaRequest request, SPRedirectSignatureFormAuthenticator sp)
            throws LifecycleException, IOException, ServletException {
        MockCatalinaResponse response = new MockCatalinaResponse();
        response.setWriter(new PrintWriter(new ByteArrayOutputStream()));

        sp.authenticate(request, response, new MockCatalinaLoginConfig());

        return response;
    }
View Full Code Here

    private MockCatalinaResponse sendIDPRequest(MockCatalinaRequest request) throws LifecycleException, IOException,
            ServletException {
        IDPWebBrowserSSOValve idp = getIDPWebBrowserSSOValve();
        idp.setStrictPostBinding(false);

        MockCatalinaResponse response = new MockCatalinaResponse();

        response.setWriter(new PrintWriter(new ByteArrayOutputStream()));

        idp.invoke(request, response);

        ((MockCatalinaSession) request.getSession()).clear();
View Full Code Here

    @Test
    public void testRoleGeneratorConfiguration() {
        logger.info("testRoleGeneratorConfiguration");

        MockCatalinaRequest request = AuthenticatorTestUtils.createRequest(SERVICE_PROVIDER_HOST_ADDRESS, true);
        MockCatalinaResponse response = new MockCatalinaResponse();

        sendAuthenticationRequest(request, response, SERVICE_PROVIDER_URL, true);

        ResponseType responseType = getResponseTypeAndCheckSignature(response, null);
View Full Code Here

    @Test
    public void testIdentityParticipantStackConfiguration() {
        logger.info("testIdentityParticipantStackConfiguration");

        MockCatalinaRequest request = AuthenticatorTestUtils.createRequest(SERVICE_PROVIDER_HOST_ADDRESS, true);
        MockCatalinaResponse response = new MockCatalinaResponse();

        sendAuthenticationRequest(request, response, SERVICE_PROVIDER_URL, true);

        IdentityParticipantStack testIdentityParticipantStack = TestIdentityParticipantStack.getDelegate();
View Full Code Here

TOP

Related Classes of org.picketlink.test.identity.federation.bindings.mock.MockCatalinaResponse

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.