Home > Java, Technical > Generating JAXB classes for SAML 2.0

Generating JAXB classes for SAML 2.0

Recently, I ran into a situation of generating JAXB classes for SAML 2.0 schema. So writing up my experience here.

Before starting make sure that you have the following.

1. JDK 1.6 or higher

2. SAML 2.0 schema files downloaded to your machine

If you computer is connected to internet, you doesn’t have to download the dependent schema.  xjc (JDK command for generating JAXB classes) will automatically download for you. Otherwise please download the schema manually from other computer and copy it to your computer. These are the dependent schemas:

a. xenc-schema.xsd (http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/xenc-schema.xsd)

b. xml.xsd (http://www.w3.org/2001/xml.xsd)

c. xmldsig-core-schema.xsd (http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd)

Assuming that dependent schema were downloaded manually, please follow this procedure to generate the classes.

1. Copy the dependent schema file into same directory where SAML 2.0 schema files exist.

2. Correct the dependent schema files path in SAML 2.0 schema files to point to local directory

Below schema files in SAML 2.0 refer to dependent schema

a. saml-schema-assertion-2.0.xsd

b. saml-schema-metadata-2.0.xsd

c. saml-schema-protocol-2.0.xsd

Open those schema files and check all import tags with the name spaces of dependent files. Correct its “schemaLocation”  attribute to point to local directory.

3. Run xjc to generate classes.

Run the below command from the xsd folder to generate classes for all SAML schemas.

xjc .

See help of JAXB & xjc documentation for customization &  more  information about generating classes.

We are done. Enjoy 🙂

  1. May 15, 2013 at 8:22 pm

    Thanks for your blog
    I am getting the following error.
    [ERROR] ‘RSAKeyValueType’ is already defined
    line 318 of http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: