Creating a SAML bearer token using the API
Use the SAML library API to create a SAML bearer token.
About this task
This library allows you to create a SAML bearer token. You can use the SAML library API to create required SAML configuration objects, then use those configuration objects to generate a bearer SAML token.
Procedure
Example
Use this sample code to create a SAML version 1.1 bearer token from the
subject:
SAMLTokenFactory samlFactory = SAMLTokenFactory.getInstance(SAMLTokenFactory.WssSamlV11Token11)
RequesterConfig reqData = samlFactory.newBearerTokenGenerateConfig();
ProviderConfig samlIssuerCfg = samlFactory.newDefaultProviderConfig(“WebSphere Server”);
Subject subject = com.ibm.websphere.security.auth.WSSubject.getRunAsSubject();
SAMLToken samlToken = samlFactory.newSAMLToken(subject, reqData, samlIssuerCfg);
Use this sample code to create a SAML version 1.1 bearer token without using the
subject:
SAMLTokenFactory samlFactory = SAMLTokenFactory.getInstance(SAMLTokenFactory.WssSamlV11Token11);
RequesterConfig reqData = samlFactory.newBearerTokenGenerateConfig();
reqData.setAuthenticationMethod("Password"); //Authentication method for Assertion
ProviderConfig samlIssuerCfg = samlFactory.newDefaultProviderConfig(Self issuer);
CredentialConfig cred = samlFactory.newCredentialConfig ();
cred.setRequesterNameID("Alice"); // SAML NameIdentifier
//SAML attributes:
SAMLAttribute attribute = new SAMLAttribute
("email" /* Name*/, new String[] {"joe@websphere"}
/*Attribute Values in String*/,null
/*Attribute Values in XML */, "WebSphere" /* Namespace*/, "email" /* format*/, "joe" /*Friendly_name */);
ArrayList<SAMLAttribute> al = new ArrayList<SAMLAttribute>();
al.add(attribute);
attribute = new SAMLAttribute("Membership", new String[] {"Super users", "My team"}, null, null, null, null );
al.add(attribute);
cred.setSAMLAttributes(al);
SAMLToken samlToken = samlFactory.newSAMLToken(cred, reqData, samlIssuerCfg);