Package org.picketlink.identity.federation.api.saml.v2.request

Examples of org.picketlink.identity.federation.api.saml.v2.request.SAML2Request


     * @throws IOException
     * @throws GeneralSecurityException
     */
    public static String getSAMLResponseURLWithSignature(ResponseType responseType, String relayState, PrivateKey signingKey)
            throws IOException, GeneralSecurityException {
        SAML2Response saml2Response = new SAML2Response();

        Document responseDoc = saml2Response.convert(responseType);

        // URL Encode the Request
        String responseString = DocumentUtil.getDocumentAsString(responseDoc);

        String urlEncodedResponse = RedirectBindingUtil.deflateBase64URLEncode(responseString);
View Full Code Here


    @Test
    public void testSigningResponse() throws Exception {
        IssuerInfoHolder issuerInfo = new IssuerInfoHolder("testIssuer");
        String id = IDGenerator.create("ID_");

        SAML2Response response = new SAML2Response();

        String authnContextDeclRef = JBossSAMLURIConstants.AC_PASSWORD_PROTECTED_TRANSPORT.get();

        AuthnStatementType authnStatement = response.createAuthnStatement(authnContextDeclRef, XMLTimeUtil.getIssueInstant());

        // Create an assertion
        AssertionType assertion = response.createAssertion(id, issuerInfo.getIssuer());
        assertion.addStatement(authnStatement);

        KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
        KeyPair kp = kpg.genKeyPair();

        id = IDGenerator.create("ID_"); // regenerate
        ResponseType responseType = response.createResponseType(id, issuerInfo, assertion);

        SAML2Signature ss = new SAML2Signature();
        ss.setSignatureMethod(SignatureMethod.DSA_SHA1);
        Document signedDoc = ss.sign(responseType, kp);
View Full Code Here

        assertTrue(isValid);
    }

    @Test
    public void testSigningAnAssertionWithinResponse() throws Exception {
        SAML2Response response = new SAML2Response();
        String fileName = "xml/dom/saml-response-2-assertions.xml";
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        InputStream is = tcl.getResourceAsStream(fileName);
        if (is == null)
            throw new RuntimeException("InputStream is null");

        ResponseType responseType = response.getResponseType(is);

        Document doc = response.convert(responseType);

        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        KeyPair kp = kpg.genKeyPair();

        // String id = "ID_0be488d8-7089-4892-8aeb-83594c800706";
View Full Code Here

        roles.add("roleA");
        roles.add("roleB");

        ResponseType responseType = null;

        SAML2Response saml2Response = new SAML2Response();

        // Create a response type
        String id = IDGenerator.create("ID_");

        IssuerInfoHolder issuerHolder = new IssuerInfoHolder("http://identityurl");
        issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());

        IDPInfoHolder idp = new IDPInfoHolder();
        idp.setNameIDFormatValue("testPrincipal");
        idp.setNameIDFormat(JBossSAMLURIConstants.NAMEID_FORMAT_PERSISTENT.get());

        SPInfoHolder sp = new SPInfoHolder();
        sp.setResponseDestinationURI("http://service");
        sp.setIssuer("http://service.issuer");
        responseType = saml2Response.createResponseType(id, sp, idp, issuerHolder);
        AssertionType assertion = responseType.getAssertions().get(0).getAssertion();

        AttributeStatementType attrStatement = StatementUtil.createAttributeStatement(roles);
        assertion.addStatement(attrStatement);

        // Add timed conditions
        saml2Response.createTimedConditions(assertion, 5000L);

        return responseType;
    }
View Full Code Here

        issuerHolder.setStatusCode(JBossSAMLURIConstants.STATUS_SUCCESS.get());

        IDPInfoHolder idp = new IDPInfoHolder();
        idp.setNameIDFormatValue(IDGenerator.create());

        SAML2Response saml2Response = new SAML2Response();

        SPInfoHolder sp = new SPInfoHolder();
        sp.setResponseDestinationURI("http://fakesp");
        sp.setIssuer("http://fakesp");
        ResponseType rt = saml2Response.createResponseType("response111", sp, idp, issuerHolder);
        Assert.assertNotNull(rt);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        saml2Response.marshall(rt, baos);
    }
View Full Code Here

        return this.postBinding || idpPostBinding;
    }

    private SAMLDocumentHolder getSAMLDocumentHolder(String samlResponse) throws ParsingException, ConfigurationException,
            ProcessingException {
        SAML2Response saml2Response = new SAML2Response();

        InputStream dataStream = null;

        if (isPostBinding()) {
            // deal with SAML response from IDP
            dataStream = PostBindingUtil.base64DecodeAsStream(samlResponse);
        } else {
            // deal with SAML response from IDP
            dataStream = RedirectBindingUtil.base64DeflateDecode(samlResponse);
        }

        try {
            saml2Response.getSAML2ObjectFromStream(dataStream);
        } catch (ProcessingException pe) {
            logger.samlResponseFromIDPParsingFailed();
            throw pe;
        } catch (ParsingException pe) {
            logger.samlResponseFromIDPParsingFailed();
            throw pe;
        }
       

        return saml2Response.getSamlDocumentHolder();
    }
View Full Code Here

        if (nodes.getLength() > 1)
            relayState = ((Element) nodes.item(1)).getAttributeNode("VALUE").getValue();

        byte[] samlIDPResponse = PostBindingUtil.base64Decode(idpResponse);

        SAML2Response saml2Response = new SAML2Response();
        ResponseType rt = saml2Response.getResponseType(new ByteArrayInputStream(samlIDPResponse));

        assertEquals("Match Identity URL:", this.identity, rt.getIssuer().getValue());
    }
View Full Code Here

     */
    private ResponseType getResponseType(MockCatalinaResponse response, ByteArrayOutputStream bos) {
        ResponseType responseType = null;

        try {
            SAML2Response samlResponse = new SAML2Response();

            if (bos == null) {
                MockCatalinaRequest requestTmp = new MockCatalinaRequest();

                AuthenticatorTestUtils.populateParametersWithQueryString(response.redirectString, requestTmp);

                responseType = (ResponseType) samlResponse.getSAML2ObjectFromStream(RedirectBindingUtil
                        .base64DeflateDecode(requestTmp.getParameter(GeneralConstants.SAML_RESPONSE_KEY)));
            } else {
                Document postBindingForm = DocumentUtil.getDocument(bos.toString());

                logger.info("POST Binding response from the IDP:");
                logger.info(prettyPrintDocument(postBindingForm).toString());

                NodeList nodes = postBindingForm.getElementsByTagName("INPUT");
                Element inputElement = (Element) nodes.item(0);
                String idpResponse = inputElement.getAttributeNode("VALUE").getValue();

                responseType = (ResponseType) samlResponse.getSAML2ObjectFromStream(PostBindingUtil
                        .base64DecodeAsStream(idpResponse));
            }

            Document convert = samlResponse.convert(responseType);

            logger.info("ResponseType returned from the IDP:");
            System.out.println(prettyPrintDocument(convert));
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

        logoutResponse = redirectStr.substring(redirectStr.indexOf(SAML_RESPONSE_KEY) + SAML_RESPONSE_KEY.length(),
                redirectStr.indexOf(RELAY_STATE_KEY) - 1);

        stream = RedirectBindingUtil.urlBase64DeflateDecode(logoutResponse);

        SAML2Response saml2Response = new SAML2Response();
        statusResponse = (StatusResponseType) saml2Request.getSAML2ObjectFromStream(stream);
        assertEquals("Match IDP URL", IDP, destination);

        // Now we should have got a full success report from IDP
        MockCatalinaContextClassLoader mclSPSales = setupTCL(profile + "/sp/employee");
View Full Code Here

     */
    @Test
    public void parseADFSClaims() throws Exception {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        InputStream configStream = tcl.getResourceAsStream("saml/v2/response/saml2-response-adfs-claims.xml");
        SAML2Response samlResponse = new SAML2Response();
        SAML2Object samlObject = samlResponse.getSAML2ObjectFromStream(configStream);
        assertNotNull(samlObject);

        SAML2Signature sig = new SAML2Signature();
        Document signedDoc = sig.sign((ResponseType) samlObject, getKeyPair());
        assertNotNull(signedDoc);
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.api.saml.v2.request.SAML2Request

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.