4

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.

avinash chavan
  • 729
  • 2
  • 11
  • 27

2 Answers2

3

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.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
  • Since i am using saml:Assertion element in my XSD, my request requires me to set AssertionType Object. I tried searching if there is a way to conver Assertion Object to AssetionType. Or does it allow me to set Assertion Object where it expects AssertionType? – avinash chavan Dec 29 '15 at 03:50
  • Yes, you should be able to set an assertion object (with element name assertion), as the type of that is AssertionType. The element name does not need to be the same as the type of the element. – Anders Abel Jan 05 '16 at 22:06
  • I didnt find any way to set Assertion inside AssertionType and vice-versa. Could you please elaborate or provide me an example if you can for more clarity? – avinash chavan Jan 06 '16 at 10:16
  • The `` element is of type `AssertionType`. You should be able to just use the OpenSAML-generated `` directly in the `` element. – Anders Abel Jan 06 '16 at 10:19
  • My generated class from the XSD requires an object of Type AssertionType for the Assertion setter. so i get an error asking me to either change the setter to type AssertionType or cast assertion to AssertionType. – avinash chavan Jan 06 '16 at 10:24
  • 1
    Looks like you have an issue with a class of type AssertionType generated from the XSD, and OpenSAML creating another class with the same name. You'll have to do some work to bridge those two. – Anders Abel Jan 06 '16 at 10:28
  • is there a way to have SAML Assertion inside the Body of a request(SOAP)? If yes then how should i go about it from here? – avinash chavan Jan 06 '16 at 11:31
0

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?

Community
  • 1
  • 1
Baderous
  • 1,069
  • 1
  • 11
  • 32
  • Is there any way to convert(unmarshall) XML to the Generated Java classes? I am using wsdl2code plugin of Axis2. – avinash chavan Jan 13 '16 at 08:14
  • I tried to generate Java classes from the saml-schema-assertion-2.0.xsd using xjc (JAXB) with a custom binding for every single class and in fact I was able to generate the classes without the "Type" suffix. I then tried to use OpenSAML 2.6.4 to create an assertion using those classes but it turns out that is not possible because, albeit having the same name, they are from different types. So I think you'll need to do the mapping. – Baderous Jan 15 '16 at 09:17