简体   繁体   中英

Using SAML Assertion in XSD

I have a webservice operation where i'll be getting SAML Assertion as part of the request Body. I have following XSD:

<xsd:element name="CreateRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="info" type="SomeRequestObj"/>
            <xsd:element ref="saml:Assertion" />
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

The saml:Assertion refers to:

<xsd:import namespace="urn:oasis:names:tc:SAML:2.0:assertion"schemaLocation="../samlv2_0/saml-schema-assertion-2.0.xsd"/>

This saml schema is copied from SAML 2.0 . This generates classes with name * Type.java . And i am having a hard time creating a unit test for this (which is a separate application with UI).

My Request requires a SAML AssertionType element in the request Body. So, i cannot use OpneSaml for generating that as it gives me a SAML Assertion object and not AssertionType.

I tried generating the AssertionType object manually but i am having a hard time doing so.
Is there a way to use OpenSaml for generating this?
As i see the xml is going to be the same that i would get in case i just use OpenSaml to generate Assertion object. Is there a way to simplify this?

EDIT: Added XSD snippet of Assertion

<element name="Assertion" type="saml:AssertionType"/>
<complexType name="AssertionType">
<sequence>
<element ref="saml:Issuer"/>
<element ref="ds:Signature" minOccurs="0"/>
<element ref="saml:Subject" minOccurs="0"/>
<element ref="saml:Conditions" minOccurs="0"/>
<element ref="saml:Advice" minOccurs="0"/>
<choice minOccurs="0" maxOccurs="unbounded">
<element ref="saml:Statement"/>
<element ref="saml:AuthnStatement"/>
<element ref="saml:AuthzDecisionStatement"/>
<element ref="saml:AttributeStatement"/>
</choice>
</sequence>
<attribute name="Version" type="string" use="required"/>
<attribute name="ID" type="ID" use="required"/>
<attribute name="IssueInstant" type="dateTime" use="required"/>
</complexType>

This generates AssertionType Object.

SAML Assertions are of complex type "AssertionType", but the element name is "Assertion". The <Assertion> element generated by OpenSaml should be just fine.

The element is defined in section 2.3.3 in the SAML core spec .

Try to use an external binding file when generating the classes from the XSD with JAXB. See this topic (I guess the second answer of it is what you're looking for): JAXB: How to change XJC-generated classes names when attr type is specified in XSD?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM