Package org.jboss.identity.federation.api.saml.v2.response

Examples of org.jboss.identity.federation.api.saml.v2.response.SAML2Response


        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

     *
     * @throws Exception
     */
    @Test
    public void constructAndSign() throws Exception {
        SAML2Response samlResponse = new SAML2Response();
        String ID = IDGenerator.create("ID_");

        IssuerInfoHolder issuerInfo = new IssuerInfoHolder("picketlink");

        IDPInfoHolder idp = new IDPInfoHolder();
        idp.setNameIDFormatValue("anil");

        // create the service provider(in this case BAS) holder object
        SPInfoHolder sp = new SPInfoHolder();
        sp.setResponseDestinationURI("http://sombody");

        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("TOKEN_USER_ID", String.valueOf(2));
        attributes.put("TOKEN_ORGANIZATION_DISPLAY_NAME", "Test Org");
        attributes.put("TOKEN_USER_DISPLAY_NAME", "Test User");

        AttributeStatementType attributeStatement = StatementUtil.createAttributeStatement(attributes);

        String assertionId = IDGenerator.create("ID_");

        AssertionType assertion = AssertionUtil.createAssertion(assertionId, issuerInfo.getIssuer());
        assertion.addStatement(attributeStatement);

        ResponseType responseType = samlResponse.createResponseType(ID, sp, idp, issuerInfo, assertion);
        SAML2Signature sig = new SAML2Signature();
        Document signedDoc = sig.sign(responseType, getKeyPair());
        assertNotNull(signedDoc);

        Logger.getLogger(SAML2ResponseUnitTestCase.class).debug("Signed Response=" + DocumentUtil.asString(signedDoc));

        Document convertedDoc = samlResponse.convert(responseType);
        assertNotNull(convertedDoc);

        // Now for the writing part
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

View Full Code Here

    private ResponseType createSignedResponse() throws ConfigurationException {
        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());

        SubjectType subject = new SubjectType();

        subject.setSubType(new STSubType());
        NameIDType nameId = new NameIDType();
        nameId.setValue("jduke");
        subject.getSubType().addBaseID(nameId);

        assertion.setSubject(subject);
        assertion.addStatement(authnStatement);

        AttributeStatementType attributes = new AttributeStatementType();

        AttributeType attribute = new AttributeType("Role");

        attribute.addAttributeValue("Manager");

        attributes.addAttribute(new ASTChoiceType(attribute));

        assertion.addStatement(attributes);

        id = IDGenerator.create("ID_"); // regenerate

        return response.createResponseType(id, issuerInfo, assertion);
    }
View Full Code Here

        MockServletContext servletContext = new MockServletContext();
        MockHttpServletRequest servletRequest = new MockHttpServletRequest(session, "POST");
        MockHttpServletResponse servletResponse = new MockHttpServletResponse();
        HTTPContext httpContext = new HTTPContext(servletRequest, servletResponse, servletContext);

        ResponseType saml2Object = new SAML2Response().createResponseType("fake_id");

        SAMLDocumentHolder docHolder = new SAMLDocumentHolder(saml2Object, null);
        IssuerInfoHolder issuerInfo = new IssuerInfoHolder("http://localhost:8080/idp/");
        SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext, issuerInfo.getIssuer(), docHolder,
                SAML2Handler.HANDLER_TYPE.IDP);
View Full Code Here

        return idpHandlerResponse;
    }

    private ResponseType getResponseTypeFromString(String responseString) throws Exception {
        InputStream is = new ByteArrayInputStream(responseString.getBytes());
        SAML2Response saml2Response = new SAML2Response();
        return saml2Response.getResponseType(is);
    }
View Full Code Here

    }

    private HandlerContext getHandlerRequestAndResponse(HTTPContext httpContext, IssuerInfoHolder issuerInfo,
            String responseString) throws Exception {
        ResponseType responseType = getResponseTypeFromString(responseString);
        SAML2Response saml2Response = new SAML2Response();
        Document doc = saml2Response.convert(responseType);
        SAMLDocumentHolder docHolder = new SAMLDocumentHolder(responseType, doc);

        SAML2HandlerRequest request = new DefaultSAML2HandlerRequest(httpContext, issuerInfo.getIssuer(), docHolder,
                SAML2Handler.HANDLER_TYPE.SP);
        SAML2HandlerResponse response = new DefaultSAML2HandlerResponse();
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

TOP

Related Classes of org.jboss.identity.federation.api.saml.v2.response.SAML2Response

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.