Package org.opensaml.saml2.core

Examples of org.opensaml.saml2.core.Assertion


    }

    /** {@inheritDoc} */
    protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {

        Assertion assertion = (Assertion) samlObject;

        if (Assertion.ID_ATTRIB_NAME.equals(attribute.getLocalName())) {
            assertion.setID(attribute.getValue());
        } else if (Assertion.ISSUER_ATTRIB_NAME.equals(attribute.getLocalName())) {
            assertion.setIssuer(attribute.getValue());
        } else if (Assertion.ISSUEINSTANT_ATTRIB_NAME.equals(attribute.getLocalName())
                && !DatatypeHelper.isEmpty(attribute.getValue())) {
            assertion.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
        } else if (Assertion.MINORVERSION_ATTRIB_NAME.equals(attribute.getLocalName())) {
            if (attribute.getValue().equals("0")) {
                assertion.setVersion(SAMLVersion.VERSION_10);
            } else {
                assertion.setVersion(SAMLVersion.VERSION_11);
            }
        } else {
            super.processAttribute(samlObject, attribute);
        }
    }
View Full Code Here


        // Obtain the token
        Token tk = tkStorage.getToken(data.getTokenId());

        OMElement assertionOMElement = tk.getToken();
        Assertion samlAssertion;


        samlAssertion = SAMLUtils.buildAssertion((Element) assertionOMElement);
        if (samlAssertion.getConditions() == null) {
            samlAssertion.setConditions((Conditions) SAMLUtils.buildXMLObject(Conditions.DEFAULT_ELEMENT_NAME));
        }

        samlAssertion.getConditions().setNotBefore(new DateTime(creationTime));
        samlAssertion.getConditions().setNotOnOrAfter(new DateTime(expirationTime));

        // sign the assertion
        SAMLUtils.signAssertion(samlAssertion, crypto, config.getIssuerKeyAlias(), config.getIssuerKeyPassword());

        // Create the RequestedSecurityToken element and add the SAML token
        // to it
        OMElement reqSecTokenElem = TrustUtil
                .createRequestedSecurityTokenElement(wstVersion, rstrElem);

        Node tempNode = samlAssertion.getDOM();
        reqSecTokenElem.addChild((OMNode) ((Element) rstrElem)
                .getOwnerDocument().importNode(tempNode, true));

        return env;
View Full Code Here

     * @return true if the token has been signed by the issuer.
     */
    private boolean isValid(Token token, PublicKey issuerPBKey) {
        // extract SAMLAssertion object from token
        OMElement assertionOMElement = token.getToken();
        Assertion samlAssertion;

        try {
            samlAssertion = SAMLUtils.buildAssertion((Element) assertionOMElement);

            log.info("Verifying token validity...");

            // check if the token has been signed by the issuer.
            SignatureValidator validator = new SignatureValidator(samlAssertion.getSignature().getSigningCredential());
            validator.validate(samlAssertion.getSignature());

        } catch (ValidationException e) {
            log.error("Signature verification failed on SAML token.", e);
            return false;
        }
View Full Code Here

        assertNotNull("RequestedSecurityToken missing", rst);

        OMElement elem = rst.getFirstChildWithName(new QName(RahasConstants.SAML_NS, "Assertion"));
        assertNotNull("Missing SAML Assertion", elem);

        Assertion assertion = getAssertionObjectFromOMElement(elem);
        List<AuthenticationStatement> authStmts = assertion.getAuthenticationStatements();
        assertNotNull("At least one Authentication Statement should be present in the assertion",
                   authStmts.get(0));

        SubjectStatement authStmt = authStmts.get(0);
        List<ConfirmationMethod> subConfirmationMethods = authStmt.getSubject().
View Full Code Here

     * Build the SAML Assertion object from the OMElement for the ease of processing
     * @param omElement OMElement containing the SAML Assertion
     * @return Assertion object
     */
    private Assertion getAssertionObjectFromOMElement(OMElement omElement){
        Assertion assertion = null;
        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilderFactory.setNamespaceAware(true);
            DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();
            Document document = docBuilder.parse(new ByteArrayInputStream(omElement.toString().getBytes()));
View Full Code Here

                    "OpenSaml engine not initialized. Please make sure to initialize the OpenSaml "
                    + "engine prior using it"
                );
            }
        }
        Assertion assertion =
            assertionV1Builder.buildObject(
                Assertion.DEFAULT_ELEMENT_NAME,
                Assertion.TYPE_NAME
            );
        assertion.setVersion(SAMLVersion.VERSION_11);
        assertion.setIssuer(issuer);
        assertion.setIssueInstant(new DateTime()); // now
        assertion.setID(IDGenerator.generateID("_"));
        return assertion;
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    protected void marshallAttributes(XMLObject samlElement, Element domElement) throws MarshallingException {

        Assertion assertion = (Assertion) samlElement;

        if (assertion.getID() != null) {
            domElement.setAttributeNS(null, Assertion.ID_ATTRIB_NAME, assertion.getID());
            if (assertion.getMinorVersion() != 0){
                domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true);
            }
        }
       
        if (assertion.getIssuer() != null) {
            domElement.setAttributeNS(null, Assertion.ISSUER_ATTRIB_NAME, assertion.getIssuer());
        }

        if (assertion.getIssueInstant() != null) {
            String date = ISODateTimeFormat.dateTime().print(assertion.getIssueInstant());
            domElement.setAttributeNS(null, Assertion.ISSUEINSTANT_ATTRIB_NAME, date);
        }

        domElement.setAttributeNS(null, Assertion.MAJORVERSION_ATTRIB_NAME, "1");
        if(assertion.getMinorVersion() == 0){
            domElement.setAttributeNS(null, Assertion.MINORVERSION_ATTRIB_NAME, "0");
        }else{
            domElement.setAttributeNS(null, Assertion.MINORVERSION_ATTRIB_NAME, "1");
        }
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    public XMLObject unmarshall(Element domElement) throws UnmarshallingException {
        // After regular unmarshalling, check the minor version and set ID-ness if not SAML 1.0
        Assertion assertion = (Assertion) super.unmarshall(domElement);
        if (assertion.getMinorVersion() != 0 && !DatatypeHelper.isEmpty(assertion.getID())) {
            domElement.setIdAttributeNS(null, Assertion.ID_ATTRIB_NAME, true);
        }
        return assertion;
    }
View Full Code Here

    /** {@inheritDoc} */
    protected void processChildElement(XMLObject parentSAMLObject, XMLObject childSAMLObject)
            throws UnmarshallingException {

        Assertion assertion = (Assertion) parentSAMLObject;

        if (childSAMLObject instanceof Signature) {
            assertion.setSignature((Signature) childSAMLObject);
        } else if (childSAMLObject instanceof Conditions) {
            assertion.setConditions((Conditions) childSAMLObject);
        } else if (childSAMLObject instanceof Advice) {
            assertion.setAdvice((Advice) childSAMLObject);
        } else if (childSAMLObject instanceof Statement) {
            assertion.getStatements().add((Statement) childSAMLObject);
        } else {
            super.processChildElement(parentSAMLObject, childSAMLObject);
        }
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException {

        Assertion assertion = (Assertion) samlObject;

        if (Assertion.ID_ATTRIB_NAME.equals(attribute.getLocalName())) {
            assertion.setID(attribute.getValue());
        } else if (Assertion.ISSUER_ATTRIB_NAME.equals(attribute.getLocalName())) {
            assertion.setIssuer(attribute.getValue());
        } else if (Assertion.ISSUEINSTANT_ATTRIB_NAME.equals(attribute.getLocalName())
                && !DatatypeHelper.isEmpty(attribute.getValue())) {
            assertion.setIssueInstant(new DateTime(attribute.getValue(), ISOChronology.getInstanceUTC()));
        } else if (Assertion.MINORVERSION_ATTRIB_NAME.equals(attribute.getLocalName())) {
            if (attribute.getValue().equals("0")) {
                assertion.setVersion(SAMLVersion.VERSION_10);
            } else {
                assertion.setVersion(SAMLVersion.VERSION_11);
            }
        } else {
            super.processAttribute(samlObject, attribute);
        }
    }
View Full Code Here

TOP

Related Classes of org.opensaml.saml2.core.Assertion

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.