Search in sources :

Example 1 with KeyInfoType

use of org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType in project keycloak by keycloak.

the class SAMLParserTest method testSaml20AssertionDsaKey.

@Test
public void testSaml20AssertionDsaKey() throws Exception {
    AssertionType a = assertParsed("saml20-assertion-dsakey.xml", AssertionType.class);
    assertThat(a.getSubject().getConfirmation(), hasSize(1));
    assertThat(a.getSubject().getConfirmation().get(0).getSubjectConfirmationData(), notNullValue());
    assertThat(a.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType(), instanceOf(KeyInfoType.class));
    KeyInfoType kit = (KeyInfoType) a.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType();
    assertThat(kit.getContent(), hasItem(instanceOf(DSAKeyValueType.class)));
    DSAKeyValueType rsaKit = (DSAKeyValueType) kit.getContent().get(0);
    assertThat(rsaKit.getG(), notNullValue());
    assertThat(rsaKit.getJ(), nullValue());
    assertThat(rsaKit.getP(), notNullValue());
    assertThat(rsaKit.getQ(), notNullValue());
    assertThat(rsaKit.getY(), notNullValue());
}
Also used : EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) DSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType) KeyInfoType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType) Test(org.junit.Test)

Example 2 with KeyInfoType

use of org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType in project keycloak by keycloak.

the class SAMLParserTest method testSaml20AssertionContents.

@Test
public void testSaml20AssertionContents() throws Exception {
    AssertionType a = assertParsed("saml20-assertion-example.xml", AssertionType.class);
    assertThat(a.getSubject().getConfirmation(), hasSize(1));
    assertThat(a.getSubject().getConfirmation().get(0).getSubjectConfirmationData(), notNullValue());
    assertThat(a.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType(), instanceOf(KeyInfoType.class));
    KeyInfoType kit = (KeyInfoType) a.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType();
    assertThat(kit.getContent(), hasItem(instanceOf(RSAKeyValueType.class)));
    RSAKeyValueType rsaKit = (RSAKeyValueType) kit.getContent().get(0);
    assertThat(rsaKit.getModulus(), notNullValue());
    assertThat(rsaKit.getExponent(), notNullValue());
    assertThat(a.getStatements(), containsInAnyOrder(instanceOf(AuthnStatementType.class), instanceOf(AttributeStatementType.class)));
    for (StatementAbstractType statement : a.getStatements()) {
        if (statement instanceof AuthnStatementType) {
            AuthnStatementType as = (AuthnStatementType) statement;
            assertThat(as.getSessionNotOnOrAfter(), notNullValue());
            assertThat(as.getSessionNotOnOrAfter(), is(XMLTimeUtil.parse("2009-06-17T18:55:10.738Z")));
            final AuthnContextType ac = as.getAuthnContext();
            assertThat(ac, notNullValue());
            assertThat(ac.getSequence(), notNullValue());
            assertThat(ac.getSequence().getClassRef().getValue(), is(JBossSAMLURIConstants.AC_UNSPECIFIED.getUri()));
            assertThat(ac.getSequence(), notNullValue());
            assertThat(ac.getSequence().getAuthnContextDecl(), nullValue());
        }
    }
}
Also used : AuthnStatementType(org.keycloak.dom.saml.v2.assertion.AuthnStatementType) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) AuthnContextType(org.keycloak.dom.saml.v2.assertion.AuthnContextType) RSAKeyValueType(org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType) StatementAbstractType(org.keycloak.dom.saml.v2.assertion.StatementAbstractType) KeyInfoType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType) Test(org.junit.Test)

Example 3 with KeyInfoType

use of org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType in project keycloak by keycloak.

the class SAMLParserTest method testSaml20AuthnResponseNonAsciiNameDefaultUtf8.

@Test
public void testSaml20AuthnResponseNonAsciiNameDefaultUtf8() throws Exception {
    ResponseType rt = assertParsed("KEYCLOAK-3971-utf-8-no-header-authnresponse.xml", ResponseType.class);
    assertThat(rt.getAssertions().size(), is(1));
    final AssertionType assertion = rt.getAssertions().get(0).getAssertion();
    assertThat(assertion.getSubject().getSubType().getBaseID(), instanceOf(NameIDType.class));
    NameIDType nameId = (NameIDType) assertion.getSubject().getSubType().getBaseID();
    assertThat(nameId.getValue(), is("roàåאבčéèíñòøöùüßåäöü汉字"));
    assertThat(assertion.getSubject().getConfirmation(), hasSize(1));
    assertThat(assertion.getSubject().getConfirmation().get(0).getSubjectConfirmationData(), notNullValue());
    assertThat(assertion.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType(), instanceOf(KeyInfoType.class));
    KeyInfoType kit = (KeyInfoType) assertion.getSubject().getConfirmation().get(0).getSubjectConfirmationData().getAnyType();
    assertThat(kit.getContent(), hasItem(instanceOf(X509DataType.class)));
    X509DataType rsaKit = (X509DataType) kit.getContent().get(0);
    assertThat(rsaKit.getDataObjects(), hasSize(1));
    assertThat(rsaKit.getDataObjects().get(0), instanceOf(X509CertificateType.class));
}
Also used : X509CertificateType(org.keycloak.dom.xmlsec.w3.xmldsig.X509CertificateType) X509DataType(org.keycloak.dom.xmlsec.w3.xmldsig.X509DataType) EncryptedAssertionType(org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType) AssertionType(org.keycloak.dom.saml.v2.assertion.AssertionType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) KeyInfoType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType) Test(org.junit.Test)

Example 4 with KeyInfoType

use of org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType in project keycloak by keycloak.

the class BaseWriter method write.

private void write(SubjectConfirmationDataType subjectConfirmationData) throws ProcessingException {
    StaxUtil.writeStartElement(writer, ASSERTION_PREFIX, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get(), ASSERTION_NSURI.get());
    // Let us look at attributes
    String inResponseTo = subjectConfirmationData.getInResponseTo();
    if (StringUtil.isNotNull(inResponseTo)) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.IN_RESPONSE_TO.get(), inResponseTo);
    }
    XMLGregorianCalendar notBefore = subjectConfirmationData.getNotBefore();
    if (notBefore != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_BEFORE.get(), notBefore.toString());
    }
    XMLGregorianCalendar notOnOrAfter = subjectConfirmationData.getNotOnOrAfter();
    if (notOnOrAfter != null) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.NOT_ON_OR_AFTER.get(), notOnOrAfter.toString());
    }
    String recipient = subjectConfirmationData.getRecipient();
    if (StringUtil.isNotNull(recipient)) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.RECIPIENT.get(), recipient);
    }
    String address = subjectConfirmationData.getAddress();
    if (StringUtil.isNotNull(address)) {
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.ADDRESS.get(), address);
    }
    if (subjectConfirmationData instanceof KeyInfoConfirmationDataType) {
        KeyInfoConfirmationDataType kicd = (KeyInfoConfirmationDataType) subjectConfirmationData;
        KeyInfoType keyInfo = (KeyInfoType) kicd.getAnyType();
        StaxWriterUtil.writeKeyInfo(writer, keyInfo);
    /*
             * if (keyInfo.getContent() == null || keyInfo.getContent().size() == 0) throw new
             * ProcessingException(ErrorCodes.WRITER_INVALID_KEYINFO_NULL_CONTENT); StaxUtil.writeStartElement(this.writer,
             * WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.KEYINFO, WSTrustConstants.XMLDSig.DSIG_NS);
             * StaxUtil.writeNameSpace(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.DSIG_NS); //
             * write the keyInfo content. Object content = keyInfo.getContent().get(0); if (content instanceof Element) {
             * Element element = (Element) keyInfo.getContent().get(0); StaxUtil.writeDOMNode(this.writer, element); } else if
             * (content instanceof X509DataType) { X509DataType type = (X509DataType) content; if (type.getDataObjects().size()
             * == 0) throw new ProcessingException(ErrorCodes.WRITER_NULL_VALUE + "X509Data");
             * StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.X509DATA,
             * WSTrustConstants.XMLDSig.DSIG_NS); Object obj = type.getDataObjects().get(0); if (obj instanceof Element) {
             * Element element = (Element) obj; StaxUtil.writeDOMElement(this.writer, element); } else if (obj instanceof
             * X509CertificateType) { X509CertificateType cert = (X509CertificateType) obj;
             * StaxUtil.writeStartElement(this.writer, WSTrustConstants.XMLDSig.DSIG_PREFIX, WSTrustConstants.XMLDSig.X509CERT,
             * WSTrustConstants.XMLDSig.DSIG_NS); StaxUtil.writeCharacters(this.writer, new
             * String(cert.getEncodedCertificate())); StaxUtil.writeEndElement(this.writer); }
             * StaxUtil.writeEndElement(this.writer); } StaxUtil.writeEndElement(this.writer);
             */
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) KeyInfoConfirmationDataType(org.keycloak.dom.saml.v2.assertion.KeyInfoConfirmationDataType) KeyInfoType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType)

Example 5 with KeyInfoType

use of org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType in project keycloak by keycloak.

the class SAML11ParserUtil method parseSubjectConfirmationData.

/**
 * Parse the {@link SubjectConfirmationDataType}
 *
 * @param xmlEventReader
 *
 * @return
 *
 * @throws ParsingException
 */
public static SubjectConfirmationDataType parseSubjectConfirmationData(XMLEventReader xmlEventReader) throws ParsingException {
    StartElement startElement = StaxParserUtil.getNextStartElement(xmlEventReader);
    StaxParserUtil.validate(startElement, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get());
    SubjectConfirmationDataType subjectConfirmationData = new SubjectConfirmationDataType();
    Attribute inResponseTo = startElement.getAttributeByName(new QName(JBossSAMLConstants.IN_RESPONSE_TO.get()));
    if (inResponseTo != null) {
        subjectConfirmationData.setInResponseTo(StaxParserUtil.getAttributeValue(inResponseTo));
    }
    Attribute notBefore = startElement.getAttributeByName(new QName(JBossSAMLConstants.NOT_BEFORE.get()));
    if (notBefore != null) {
        subjectConfirmationData.setNotBefore(XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(notBefore)));
    }
    Attribute notOnOrAfter = startElement.getAttributeByName(new QName(JBossSAMLConstants.NOT_ON_OR_AFTER.get()));
    if (notOnOrAfter != null) {
        subjectConfirmationData.setNotOnOrAfter(XMLTimeUtil.parse(StaxParserUtil.getAttributeValue(notOnOrAfter)));
    }
    Attribute recipient = startElement.getAttributeByName(new QName(JBossSAMLConstants.RECIPIENT.get()));
    if (recipient != null) {
        subjectConfirmationData.setRecipient(StaxParserUtil.getAttributeValue(recipient));
    }
    Attribute address = startElement.getAttributeByName(new QName(JBossSAMLConstants.ADDRESS.get()));
    if (address != null) {
        subjectConfirmationData.setAddress(StaxParserUtil.getAttributeValue(address));
    }
    XMLEvent xmlEvent = StaxParserUtil.peek(xmlEventReader);
    if (!(xmlEvent instanceof EndElement)) {
        startElement = StaxParserUtil.peekNextStartElement(xmlEventReader);
        String tag = StaxParserUtil.getElementName(startElement);
        if (tag.equals(WSTrustConstants.XMLDSig.KEYINFO)) {
            KeyInfoType keyInfo = parseKeyInfo(xmlEventReader);
            subjectConfirmationData.setAnyType(keyInfo);
        } else if (tag.equals(WSTrustConstants.XMLEnc.ENCRYPTED_KEY)) {
            subjectConfirmationData.setAnyType(StaxParserUtil.getDOMElement(xmlEventReader));
        } else
            throw logger.parserUnknownTag(tag, startElement.getLocation());
    }
    // Get the end tag
    EndElement endElement = (EndElement) StaxParserUtil.getNextEvent(xmlEventReader);
    StaxParserUtil.matches(endElement, JBossSAMLConstants.SUBJECT_CONFIRMATION_DATA.get());
    return subjectConfirmationData;
}
Also used : StartElement(javax.xml.stream.events.StartElement) SubjectConfirmationDataType(org.keycloak.dom.saml.v2.assertion.SubjectConfirmationDataType) Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) QName(javax.xml.namespace.QName) XMLEvent(javax.xml.stream.events.XMLEvent) KeyInfoType(org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType)

Aggregations

KeyInfoType (org.keycloak.dom.xmlsec.w3.xmldsig.KeyInfoType)7 StartElement (javax.xml.stream.events.StartElement)3 Test (org.junit.Test)3 AssertionType (org.keycloak.dom.saml.v2.assertion.AssertionType)3 EncryptedAssertionType (org.keycloak.dom.saml.v2.assertion.EncryptedAssertionType)3 DSAKeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.DSAKeyValueType)3 KeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.KeyValueType)3 RSAKeyValueType (org.keycloak.dom.xmlsec.w3.xmldsig.RSAKeyValueType)3 X509CertificateType (org.keycloak.dom.xmlsec.w3.xmldsig.X509CertificateType)3 X509DataType (org.keycloak.dom.xmlsec.w3.xmldsig.X509DataType)3 EndElement (javax.xml.stream.events.EndElement)2 XMLEvent (javax.xml.stream.events.XMLEvent)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1 Attribute (javax.xml.stream.events.Attribute)1 AuthnContextType (org.keycloak.dom.saml.v2.assertion.AuthnContextType)1 AuthnStatementType (org.keycloak.dom.saml.v2.assertion.AuthnStatementType)1 KeyInfoConfirmationDataType (org.keycloak.dom.saml.v2.assertion.KeyInfoConfirmationDataType)1 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)1 StatementAbstractType (org.keycloak.dom.saml.v2.assertion.StatementAbstractType)1