Package org.picketlink.identity.federation.core.saml.v2.writers

Examples of org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter


     * @throws ConfigurationException
     */
    public boolean process(String samlRequest, HTTPContext httpContext, Set<SAML2Handler> handlers, Lock chainLock)
            throws ProcessingException, IOException, ParsingException, ConfigurationException {
        SAML2Request saml2Request = new SAML2Request();
        SAML2HandlerResponse saml2HandlerResponse = null;
        SAML2Object samlObject = null;
        SAMLDocumentHolder documentHolder = null;

        if (this.postBinding) {
            // we got a logout request from IDP
            InputStream is = PostBindingUtil.base64DecodeAsStream(samlRequest);
            samlObject = saml2Request.getSAML2ObjectFromStream(is);
        } else {
            InputStream is = RedirectBindingUtil.base64DeflateDecode(samlRequest);
            samlObject = saml2Request.getSAML2ObjectFromStream(is);
        }

        documentHolder = saml2Request.getSamlDocumentHolder();

        // Create the request/response
        SAML2HandlerRequest saml2HandlerRequest = getSAML2HandlerRequest(documentHolder, httpContext);
        saml2HandlerResponse = new DefaultSAML2HandlerResponse();
        saml2HandlerResponse.setPostBindingForResponse(postBinding);

        SAMLHandlerChainProcessor chainProcessor = new SAMLHandlerChainProcessor(handlers);

        // Set some request options
        setRequestOptions(saml2HandlerRequest);

        chainProcessor.callHandlerChain(samlObject, saml2HandlerRequest, saml2HandlerResponse, httpContext, chainLock);

        Document samlResponseDocument = saml2HandlerResponse.getResultingDocument();
        String relayState = saml2HandlerResponse.getRelayState();

        String destination = saml2HandlerResponse.getDestination();

        boolean willSendRequest = saml2HandlerResponse.getSendRequest();

        if (destination != null && samlResponseDocument != null) {
            if (postBinding) {
                sendRequestToIDP(destination, samlResponseDocument, relayState, httpContext.getResponse(), willSendRequest);
            } else {
                String destinationQuery = saml2HandlerResponse.getDestinationQueryStringWithSignature();

                // This is the case with signatures disabled
                if (destinationQuery == null) {
                   boolean areWeSendingRequest = saml2HandlerResponse.getSendRequest();
                   String samlMsg = DocumentUtil.getDocumentAsString(samlResponseDocument);

                   String base64Request = RedirectBindingUtil.deflateBase64URLEncode(samlMsg.getBytes("UTF-8"));
                   destinationQuery = RedirectBindingUtil.getDestinationQueryString(base64Request, relayState,
                         areWeSendingRequest);
View Full Code Here


        InputStream is = tcl.getResourceAsStream("saml2/metadata/idp-entitydescriptor.xml");
        assertNotNull("Inputstream not null", is);

        EntityDescriptorType edt = (EntityDescriptorType) parser.parse(is);
        assertNotNull(edt);
        FileBasedMetadataConfigurationStore fbd = new FileBasedMetadataConfigurationStore();
        fbd.persist(edt, id);

        EntityDescriptorType loaded = fbd.load(id);
        assertNotNull("loaded EntityDescriptorType not null", loaded);
        fbd.delete(id);

        try {
            fbd.load(id);
            fail("Did not delete the metadata persistent file");
        } catch (Exception t) {
            // pass
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testTrustedProviders() throws Exception {
        FileBasedMetadataConfigurationStore fbd = new FileBasedMetadataConfigurationStore();
        Map<String, String> trustedProviders = new HashMap<String, String>();
        trustedProviders.put("idp1", "http://localhost:8080/idp1/metadata");
        trustedProviders.put("idp2", "http://localhost:8080/idp2/metadata");
        fbd.persistTrustedProviders(id, trustedProviders);

        // Lets get back
        Map<String, String> loadTP = fbd.loadTrustedProviders(id);
        assertNotNull("Loaded Trusted Providers not null", loadTP);

        assertTrue("idp1", loadTP.containsKey("idp1"));
        assertTrue("idp2", loadTP.containsKey("idp2"));
        assertTrue("size 2", loadTP.size() == 2);

        fbd.deleteTrustedProviders(id);
        try {
            fbd.loadTrustedProviders(id);
            fail("Did not delete the trusted providers file");
        } catch (Exception t) {
            // pass
        }
    }
View Full Code Here

     * @return
     * @throws ProcessingException
     */
    public static String asString(AssertionType assertion) throws ProcessingException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
        writer.write(assertion);
        return new String(baos.toByteArray());
    }
View Full Code Here

     * @return
     * @throws ProcessingException
     */
    public static Document asDocument(AssertionType assertion) throws ProcessingException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
       
        writer.write(assertion);
       
        try {
            return DocumentUtil.getDocument(new ByteArrayInputStream(baos.toByteArray()));
        } catch (Exception e) {
            throw logger.processingError(e);
View Full Code Here

     * @return a reference to the {@code Element} that contains the marshaled SAML assertion.
     * @throws Exception if an error occurs while marshaling the assertion.
     */
    public static Element toElement(AssertionType assertion) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        SAMLAssertionWriter writer = new SAMLAssertionWriter(StaxUtil.getXMLStreamWriter(baos));
        writer.write(assertion);

        byte[] assertionBytes = baos.toByteArray();
        ByteArrayInputStream bis = new ByteArrayInputStream(assertionBytes);
        Document document = DocumentUtil.getDocument(bis);

View Full Code Here

        List<Object> list = validateTarget.getAny();
        for (Object validateTargetObj : list) {
            if (validateTargetObj instanceof AssertionType) {
                AssertionType assertion = (AssertionType) validateTargetObj;
                SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer);
                samlAssertionWriter.write(assertion);
            } else if (validateTargetObj instanceof Element) {
                StaxUtil.writeDOMElement(writer, (Element) validateTargetObj);
            } else
                throw logger.writerUnknownTypeError(validateTargetObj.getClass().getName());
        }
View Full Code Here

        List<Object> list = renewTarget.getAny();
        for (Object renewTargetObj : list) {
            if (renewTargetObj instanceof AssertionType) {
                AssertionType assertion = (AssertionType) renewTargetObj;
                SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer);
                samlAssertionWriter.write(assertion);
            } else if (renewTargetObj instanceof Element) {
                StaxUtil.writeDOMElement(writer, (Element) renewTargetObj);
            } else
                throw logger.writerUnknownTypeError(renewTargetObj.getClass().getName());
        }
View Full Code Here

        List<Object> list = cancelTarget.getAny();

        for (Object cancelTargetObj : list) {
            if (cancelTargetObj instanceof AssertionType) {
                AssertionType assertion = (AssertionType) cancelTargetObj;
                SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer);
                samlAssertionWriter.write(assertion);
            } else if (cancelTargetObj instanceof Element) {
                StaxUtil.writeDOMElement(writer, (Element) cancelTargetObj);
            } else
                throw logger.writerUnknownTypeError(cancelTargetObj.getClass().getName());
        }
View Full Code Here

                    WSTrustConstants.BASE_NAMESPACE);
            List<Object> theList = response.getRequestedSecurityToken().getAny();
            for (Object securityToken : theList) {
                if (securityToken instanceof AssertionType) {
                    AssertionType assertion = (AssertionType) securityToken;
                    SAMLAssertionWriter samlAssertionWriter = new SAMLAssertionWriter(this.writer);
                    samlAssertionWriter.write(assertion);
                } else if (securityToken instanceof Element) {
                    StaxUtil.writeDOMElement(this.writer, (Element) securityToken);
                } else
                    throw logger.writerUnknownTypeError(securityToken.getClass().getName());
            }
View Full Code Here

TOP

Related Classes of org.picketlink.identity.federation.core.saml.v2.writers.SAMLResponseWriter

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.