Search in sources :

Example 1 with AttributeQueryType

use of org.keycloak.dom.saml.v2.protocol.AttributeQueryType in project keycloak by keycloak.

the class SAMLAttributeQueryParserTest method testSaml20AttributeQueryWithExtension.

@Test(timeout = 2000)
public void testSaml20AttributeQueryWithExtension() throws Exception {
    try (InputStream is = SAMLAttributeQueryParserTest.class.getResourceAsStream("saml20-attributequery-with-extension.xml")) {
        Object parsedObject = parser.parse(is);
        assertThat(parsedObject, instanceOf(AttributeQueryType.class));
        AttributeQueryType query = (AttributeQueryType) parsedObject;
        assertThat(query.getSignature(), nullValue());
        assertThat(query.getConsent(), nullValue());
        assertThat(query.getIssuer(), not(nullValue()));
        assertThat(query.getIssuer().getValue(), is("https://sp/"));
        NameIDType nameId = (NameIDType) query.getSubject().getSubType().getBaseID();
        assertThat(nameId.getValue(), is("CN=trscavo@uiuc.edu,OU=User,O=NCSA-TEST,C=US"));
        assertThat(query.getExtensions(), not(nullValue()));
        assertThat(query.getExtensions().getAny().size(), is(1));
        assertThat(query.getExtensions().getAny().get(0), instanceOf(Element.class));
        Element el = (Element) query.getExtensions().getAny().get(0);
        assertThat(el.getLocalName(), is("KeyInfo"));
        assertThat(el.getNamespaceURI(), is("urn:keycloak:ext:key:1.0"));
        assertThat(el.getAttribute("MessageSigningKeyId"), is("FJ86GcF3jTbNLOco4NvZkUCIUmfYCqoqtOQeMfbhNlE"));
    }
}
Also used : InputStream(java.io.InputStream) Element(org.w3c.dom.Element) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) AttributeQueryType(org.keycloak.dom.saml.v2.protocol.AttributeQueryType) Test(org.junit.Test)

Example 2 with AttributeQueryType

use of org.keycloak.dom.saml.v2.protocol.AttributeQueryType in project keycloak by keycloak.

the class SAMLRequestWriter method write.

public void write(AttributeQueryType request) throws ProcessingException {
    StaxUtil.writeStartElement(writer, PROTOCOL_PREFIX, JBossSAMLConstants.ATTRIBUTE_QUERY.get(), PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, PROTOCOL_PREFIX, PROTOCOL_NSURI.get());
    StaxUtil.writeNameSpace(writer, ASSERTION_PREFIX, ASSERTION_NSURI.get());
    StaxUtil.writeDefaultNameSpace(writer, ASSERTION_NSURI.get());
    // Attributes
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ID.get(), request.getID());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.VERSION.get(), request.getVersion());
    StaxUtil.writeAttribute(writer, JBossSAMLConstants.ISSUE_INSTANT.get(), request.getIssueInstant().toString());
    URI destination = request.getDestination();
    if (destination != null)
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.DESTINATION.get(), destination.toASCIIString());
    String consent = request.getConsent();
    if (StringUtil.isNotNull(consent))
        StaxUtil.writeAttribute(writer, JBossSAMLConstants.CONSENT.get(), consent);
    NameIDType issuer = request.getIssuer();
    if (issuer != null) {
        write(issuer, new QName(ASSERTION_NSURI.get(), JBossSAMLConstants.ISSUER.get(), ASSERTION_PREFIX));
    }
    Element sig = request.getSignature();
    if (sig != null) {
        StaxUtil.writeDOMElement(writer, sig);
    }
    ExtensionsType extensions = request.getExtensions();
    if (extensions != null && !extensions.getAny().isEmpty()) {
        write(extensions);
    }
    SubjectType subject = request.getSubject();
    if (subject != null) {
        write(subject);
    }
    List<AttributeType> attributes = request.getAttribute();
    for (AttributeType attr : attributes) {
        write(attr);
    }
    StaxUtil.writeEndElement(writer);
    StaxUtil.flush(writer);
}
Also used : SubjectType(org.keycloak.dom.saml.v2.assertion.SubjectType) QName(javax.xml.namespace.QName) AttributeType(org.keycloak.dom.saml.v2.assertion.AttributeType) Element(org.w3c.dom.Element) ExtensionsType(org.keycloak.dom.saml.v2.protocol.ExtensionsType) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) PROTOCOL_NSURI(org.keycloak.saml.common.constants.JBossSAMLURIConstants.PROTOCOL_NSURI) URI(java.net.URI) ASSERTION_NSURI(org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)

Example 3 with AttributeQueryType

use of org.keycloak.dom.saml.v2.protocol.AttributeQueryType in project keycloak by keycloak.

the class SamlDocumentStepBuilder method saml2Object2String.

public static String saml2Object2String(final SAML2Object transformed) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLStreamWriter xmlStreamWriter = StaxUtil.getXMLStreamWriter(bos);
        if (transformed instanceof AuthnRequestType) {
            new SAMLRequestWriter(xmlStreamWriter).write((AuthnRequestType) transformed);
        } else if (transformed instanceof LogoutRequestType) {
            new SAMLRequestWriter(xmlStreamWriter).write((LogoutRequestType) transformed);
        } else if (transformed instanceof ArtifactResolveType) {
            new SAMLRequestWriter(xmlStreamWriter).write((ArtifactResolveType) transformed);
        } else if (transformed instanceof AttributeQueryType) {
            new SAMLRequestWriter(xmlStreamWriter).write((AttributeQueryType) transformed);
        } else if (transformed instanceof ResponseType) {
            new SAMLResponseWriter(xmlStreamWriter).write((ResponseType) transformed);
        } else if (transformed instanceof ArtifactResponseType) {
            new SAMLResponseWriter(xmlStreamWriter).write((ArtifactResponseType) transformed);
        } else if (transformed instanceof StatusResponseType) {
            new SAMLResponseWriter(xmlStreamWriter).write((StatusResponseType) transformed, SAMLProtocolQNames.LOGOUT_RESPONSE.getQName("samlp"));
        } else {
            Assert.assertNotNull("Unknown type: <null>", transformed);
            Assert.fail("Unknown type: " + transformed.getClass().getName());
        }
        return new String(bos.toByteArray(), GeneralConstants.SAML_CHARSET);
    } catch (ProcessingException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ArtifactResolveType(org.keycloak.dom.saml.v2.protocol.ArtifactResolveType) LogoutRequestType(org.keycloak.dom.saml.v2.protocol.LogoutRequestType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) SAMLResponseWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLResponseWriter) AuthnRequestType(org.keycloak.dom.saml.v2.protocol.AuthnRequestType) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) SAMLRequestWriter(org.keycloak.saml.processing.core.saml.v2.writers.SAMLRequestWriter) ArtifactResponseType(org.keycloak.dom.saml.v2.protocol.ArtifactResponseType) AttributeQueryType(org.keycloak.dom.saml.v2.protocol.AttributeQueryType) ProcessingException(org.keycloak.saml.common.exceptions.ProcessingException)

Example 4 with AttributeQueryType

use of org.keycloak.dom.saml.v2.protocol.AttributeQueryType in project keycloak by keycloak.

the class SAMLAttributeQueryParserTest method testSaml20AttributeQuery.

@Test(timeout = 2000000)
public void testSaml20AttributeQuery() throws Exception {
    try (InputStream is = SAMLAttributeQueryParserTest.class.getResourceAsStream("saml20-attributequery.xml")) {
        Object parsedObject = parser.parse(is);
        assertThat(parsedObject, instanceOf(AttributeQueryType.class));
        AttributeQueryType query = (AttributeQueryType) parsedObject;
        assertThat(query.getSignature(), nullValue());
        assertThat(query.getConsent(), nullValue());
        assertThat(query.getIssuer(), not(nullValue()));
        assertThat(query.getIssuer().getValue(), is("https://sp/"));
        NameIDType nameId = (NameIDType) query.getSubject().getSubType().getBaseID();
        assertThat(nameId.getValue(), is("CN=trscavo@uiuc.edu,OU=User,O=NCSA-TEST,C=US"));
    }
}
Also used : InputStream(java.io.InputStream) NameIDType(org.keycloak.dom.saml.v2.assertion.NameIDType) AttributeQueryType(org.keycloak.dom.saml.v2.protocol.AttributeQueryType) Test(org.junit.Test)

Example 5 with AttributeQueryType

use of org.keycloak.dom.saml.v2.protocol.AttributeQueryType in project keycloak by keycloak.

the class SAMLAttributeQueryParser method instantiateElement.

@Override
protected AttributeQueryType instantiateElement(XMLEventReader xmlEventReader, StartElement element) throws ParsingException {
    SAMLParserUtil.validateAttributeValue(element, SAMLProtocolQNames.ATTR_VERSION, VERSION_2_0);
    String id = StaxParserUtil.getRequiredAttributeValue(element, SAMLProtocolQNames.ATTR_ID);
    XMLGregorianCalendar issueInstant = XMLTimeUtil.parse(StaxParserUtil.getRequiredAttributeValue(element, SAMLProtocolQNames.ATTR_ISSUE_INSTANT));
    AttributeQueryType authnRequest = new AttributeQueryType(id, issueInstant);
    super.parseBaseAttributes(element, authnRequest);
    return authnRequest;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) AttributeQueryType(org.keycloak.dom.saml.v2.protocol.AttributeQueryType)

Aggregations

AttributeQueryType (org.keycloak.dom.saml.v2.protocol.AttributeQueryType)4 NameIDType (org.keycloak.dom.saml.v2.assertion.NameIDType)3 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 Element (org.w3c.dom.Element)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 QName (javax.xml.namespace.QName)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)1 SubjectType (org.keycloak.dom.saml.v2.assertion.SubjectType)1 ArtifactResolveType (org.keycloak.dom.saml.v2.protocol.ArtifactResolveType)1 ArtifactResponseType (org.keycloak.dom.saml.v2.protocol.ArtifactResponseType)1 AuthnRequestType (org.keycloak.dom.saml.v2.protocol.AuthnRequestType)1 ExtensionsType (org.keycloak.dom.saml.v2.protocol.ExtensionsType)1 LogoutRequestType (org.keycloak.dom.saml.v2.protocol.LogoutRequestType)1 ResponseType (org.keycloak.dom.saml.v2.protocol.ResponseType)1 StatusResponseType (org.keycloak.dom.saml.v2.protocol.StatusResponseType)1 ASSERTION_NSURI (org.keycloak.saml.common.constants.JBossSAMLURIConstants.ASSERTION_NSURI)1