Package org.picketlink.identity.federation.bindings.tomcat.idp

Examples of org.picketlink.identity.federation.bindings.tomcat.idp.IDPWebBrowserSSOValve


        ServiceProviderAuthenticator spAuthenticator = createSPAuthenticator(true);

        // first interaction with the SP. We should receive from the SP a AuthnRequest type
        String authnRequest = invokeSPAndGetAuthnRequest(spAuthenticator);

        IDPWebBrowserSSOValve idpAuthenticator = createIDPAuthenticator(true);

        // let's invoke the IDP with the previous AuthnRequest and perform the authentication. Now we should get a valid SAML
        // Response and Assertion.
        String idpResponse = invokeIDPAndGetSAMLResponse(idpAuthenticator, authnRequest);
View Full Code Here


    @Test
    public void testWrapWithSignedAssertion() throws Exception {
       // same workflow like previous test for obtaining valid idpResponse from IDP
       ServiceProviderAuthenticator spAuthenticator = createSPAuthenticator(true);
       String authnRequest = invokeSPAndGetAuthnRequest(spAuthenticator);
       IDPWebBrowserSSOValve idpAuthenticator = createIDPAuthenticator(true);
       String idpResponse = invokeIDPAndGetSAMLResponse(idpAuthenticator, authnRequest);
       byte[] samlIDPResponse = PostBindingUtil.base64Decode(idpResponse);
       Document samlResponseDoc = DocumentUtil.getDocument(new ByteArrayInputStream(samlIDPResponse));

       // remove signature element as it's signing whole samlResponse
       Element signature = (Element) samlResponseDoc.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature")
             .item(0);
       signature.getParentNode().removeChild(signature);

       // sign Assertion element only
       signAssertionElement(samlResponseDoc, idpAuthenticator.getKeyManager());

       // verify successful validation of signature on Assertion element
       Assert.assertTrue(new SAML2Signature().validate(samlResponseDoc, idpAuthenticator.getKeyManager().getSigningKeyPair().getPublic()));

       // wrap evil assertion
       wrapBadAssertionBeforeOriginal(samlResponseDoc);

       // let's now send the bad SAML response and the assertion back to the SP.
View Full Code Here

        ServiceProviderAuthenticator spAuthenticator = createSPAuthenticator(false);

        // first interaction with the SP. We should receive from the SP a AuthnRequest type
        String authnRequest = invokeSPAndGetAuthnRequest(spAuthenticator);

        IDPWebBrowserSSOValve idpAuthenticator = createIDPAuthenticator(false);

        // let's invoke the IDP with the previous AuthnRequest. Now we should get a valid SAML Response and Assertion.
        String idpResponse = invokeIDPAndGetSAMLResponse(idpAuthenticator, authnRequest);

        // let's replace the original assertion with a bad one
View Full Code Here

        ServiceProviderAuthenticator spAuthenticator = createSPAuthenticator(false);

        // first interaction with the SP. We should receive from the SP a AuthnRequest type
        String authnRequest = invokeSPAndGetAuthnRequest(spAuthenticator);

        IDPWebBrowserSSOValve idpAuthenticator = createIDPAuthenticator(false);

        // let's invoke the IDP with the previous AuthnRequest. Now we should get a valid SAML Response and Assertion.
        String idpResponse = invokeIDPAndGetSAMLResponse(idpAuthenticator, authnRequest);

        // let's replace the original assertion with a bad one
View Full Code Here

     *
     * @param supportsSignatures indicates if the authenticator supports signatures or not.
     * @return
     */
    private IDPWebBrowserSSOValve createIDPAuthenticator(boolean supportsSignatures) throws Exception {
        IDPWebBrowserSSOValve idpAuthenticator = new IDPWebBrowserSSOValve();

        IDPType idpType = new IDPType();

        idpType.setIdentityURL("http://localhost/idp");
        idpType.setSupportsSignature(supportsSignatures);

        idpAuthenticator.setConfigProvider(new MockSAMLConfigurationProvider(idpType));
        idpAuthenticator.setContainer(this.idpContext);

        idpAuthenticator.start();

        return idpAuthenticator;
    }
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    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

    }

    @SuppressWarnings("deprecation")
    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();

        return response;
    }
View Full Code Here

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

        context = new MockCatalinaContext();
        IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();
        idp.setContainer(context);
        idp.setSignOutgoingMessages(false);
        idp.start();

        String samlAuth = DocumentUtil.getDocumentAsString(saml2Request.convert(art));

        String samlMessage = Base64.encodeBytes(samlAuth.getBytes());

        MockCatalinaRealm realm = new MockCatalinaRealm("anil", "test", new Principal() {
            public String getName() {
                return "anil";
            }
        });

        List<String> roles = new ArrayList<String>();
        roles.add("manager");
        roles.add("employee");

        request = new MockCatalinaRequest();
        request.setRemoteAddr(employee);
        request.setSession(session);
        request.setParameter("SAMLRequest", samlMessage);
        request.setUserPrincipal(new GenericPrincipal(realm, "anil", "test", roles));
        request.setMethod("POST");

        // Lets start the workflow with post
        idp.invoke(request, response);

        String idpResponseString = new String(baos.toByteArray());
        Document idpHTMLResponse = DocumentUtil.getDocument(idpResponseString);
        nodes = idpHTMLResponse.getElementsByTagName("INPUT");
        inputElement = (Element) nodes.item(0);
View Full Code Here

        request.setMethod("GET");

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

        IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();

        idp.setSignOutgoingMessages(false);
        idp.setIgnoreIncomingSignatures(true);
        idp.setStrictPostBinding(false);

        idp.setContainer(context);
        idp.start();
        idp.invoke(request, response);

        redirectStr = response.redirectString;
        assertNotNull(redirectStr);
        String samlResponse = RedirectBindingUtil.urlDecode(redirectStr.substring(redirectStr.indexOf(SAML_RESPONSE_KEY)
                + SAML_RESPONSE_KEY.length()));
View Full Code Here

        session.setServletContext(catalinaContext);

        IdentityServer server = this.getIdentityServer(session);
        catalinaContext.setAttribute("IDENTITY_SERVER", server);

        IDPWebBrowserSSOValve idp = new IDPWebBrowserSSOValve();

        idp.setContainer(catalinaContext);
        idp.setSignOutgoingMessages(false);
        idp.setIgnoreIncomingSignatures(true);
        idp.setStrictPostBinding(false);
        idp.start();

        // Assume that we already have the principal and roles set in the session
        MockCatalinaRealm realm = new MockCatalinaRealm("anil", "test", new Principal() {
            public String getName() {
                return "anil";
            }
        });
        List<String> roles = new ArrayList<String>();
        roles.add("manager");
        roles.add("employee");

        List<String> rolesList = new ArrayList<String>();
        rolesList.add("manager");

        MockCatalinaRequest request = new MockCatalinaRequest();
        session.clear();
        request.setSession(session);

        request.addHeader("Referer", sales);

        GenericPrincipal genericPrincipal = new GenericPrincipal(realm, "anil", "test", roles);
        request.setUserPrincipal(genericPrincipal);

        //We start the workflow with the sales application sending a logout request
        String samlMessage = RedirectBindingUtil.deflateBase64Encode(createLogOutRequest(sales).getBytes());
        request.setParameter("SAMLRequest", samlMessage);

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

        // The IDP is preloaded with 2 participants : "http://localhost:8080/sales/"
        // and "http://localhost:8080/employee"

        // Lets start the workflow with get
        request.setMethod("GET");
        idp.invoke(request, response);

        String redirectStr = response.redirectString;

        String destination = redirectStr.substring(0, redirectStr.indexOf(SAML_REQUEST_KEY) - 1);
        String relayState = redirectStr.substring(redirectStr.indexOf(RELAY_STATE_KEY) + RELAY_STATE_KEY.length());
        String logoutRequest = redirectStr.substring(redirectStr.indexOf(SAML_REQUEST_KEY) + SAML_REQUEST_KEY.length(),
                redirectStr.indexOf(RELAY_STATE_KEY) - 1);

        InputStream stream = RedirectBindingUtil.urlBase64DeflateDecode(logoutRequest);

        SAML2Request saml2Request = new SAML2Request();
        LogoutRequestType lor = (LogoutRequestType) saml2Request.getRequestType(stream);
        assertEquals("Match Employee URL", employee, destination);
        assertEquals("Destination exists", employee, lor.getDestination().toString());

        // IDP has sent a LogOutRequest which we feed to SPRedirectFormAuthenticator for Employee
        MockCatalinaContextClassLoader mclSPEmp = setupTCL(profile + "/sp/employee");
        Thread.currentThread().setContextClassLoader(mclSPEmp);

        MockCatalinaContext context = new MockCatalinaContext();
        context.setRealm(realm);
        session.setServletContext(context);

        SPRedirectFormAuthenticator sp = new SPRedirectFormAuthenticator();
        sp.setContainer(context);
        sp.testStart();
        sp.getConfiguration().setIdpUsesPostBinding(false);

        request = new MockCatalinaRequest();
        request.setSession(session);
        request.setMethod("GET");
        request.setParameter("SAMLRequest", RedirectBindingUtil.urlDecode(logoutRequest));
        request.setParameter("RelayState", relayState);

        MockCatalinaResponse filterResponse = new MockCatalinaResponse();
        ByteArrayOutputStream filterbaos = new ByteArrayOutputStream();
        filterResponse.setWriter(new PrintWriter(filterbaos));

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

        redirectStr = response.redirectString;

        destination = redirectStr.substring(0, redirectStr.indexOf(SAML_RESPONSE_KEY) - 1);
        relayState = redirectStr.substring(redirectStr.indexOf(RELAY_STATE_KEY) + RELAY_STATE_KEY.length());
        assertNotNull("RelayState exists", relayState);
        String logoutResponse = redirectStr.substring(redirectStr.indexOf(SAML_RESPONSE_KEY) + SAML_RESPONSE_KEY.length(),
                redirectStr.indexOf(RELAY_STATE_KEY) - 1);

        stream = RedirectBindingUtil.urlBase64DeflateDecode(logoutResponse);
        StatusResponseType statusResponse = (StatusResponseType) saml2Request.getSAML2ObjectFromStream(stream);
        assertEquals("Match IDP URL", IDP, destination);

        // Now the SP (employee app) has logged out and sending a status response to IDP
        Thread.currentThread().setContextClassLoader(mclIDP);

        session.clear();
        request.clear();

        request.setMethod("GET");
        request.setSession(session);
        request.setUserPrincipal(genericPrincipal);
        request.setParameter("SAMLResponse", RedirectBindingUtil.urlDecode(logoutResponse));
        request.setParameter("RelayState", relayState);

        baos = new ByteArrayOutputStream();
        response.setOutputStream(baos);
        response.setWriter(new PrintWriter(baos));
        idp.invoke(request, response);

        destination = redirectStr.substring(0, redirectStr.indexOf(SAML_RESPONSE_KEY) - 1);
        relayState = redirectStr.substring(redirectStr.indexOf(RELAY_STATE_KEY) + RELAY_STATE_KEY.length());
        logoutResponse = redirectStr.substring(redirectStr.indexOf(SAML_RESPONSE_KEY) + SAML_RESPONSE_KEY.length(),
                redirectStr.indexOf(RELAY_STATE_KEY) - 1);
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.bindings.tomcat.idp.IDPWebBrowserSSOValve

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.