简体   繁体   中英

Generate SAML response/assertion in java

I am working on idp-initated authentication. I want to generate SAML response to be sent to SalesForce. I have necessary values to be set in the response from metadata. Please tell me openSAML classes to use in order to generate response/assertion.

If you are looking to create SAML Assertions and want some convenience methods that will help you deal with the OpenSAML library, you can take a look at WSS4J's SAML2ComponentBuilder. This is used extensively in Apache CXF and other Java service stacks.

Creating an assertion is as easy as:

        //Create assertion
    Assertion assertion = SAML2ComponentBuilder.createAssertion();

    //create issuer
    Issuer issuer = SAML2ComponentBuilder.createIssuer(issuerString);
    assertion.setIssuer(issuer);

You can obviously set all the values described above and there is an 'AssertionWrapper' provided that assists in digitally signing the assertion:

assertionWrapper.signAssertion( alias, password, signatureCrypto, false, defaultCanonicalizationAlgorithm, defaultRSASignatureAlgorithm);

It is worth looking into if you are having difficultly dealing directly with the OpenSAML library.

Thanks, Yogesh

Following are the main classes that will be used.

Assertion
Signature
SubjectConfirmationData
NameID
Subject
Conditions
Audience
AuthnContextClassRef
AuthnStatement

see this for openSAML libraries link

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