Using the SAML runtime API, you can create SAML tokens containing SAML attributes. You can also extract the SAML attributes from an existing SAML token.
To create a SAML token containing SAML attributes, perform the following steps:
SAMLAttribute sattribute =
new SAMLAttribute("urn:oid:2.5.4.20", //Name
new String[] {" any address"}, //Attribute Values
null, /*XML Attributes empty on this example*/
"urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500", //NameSpace
"urn:oasis:names:tc:SAML:2.0:attrname-format:uri", //format
"Address");
SAMLTokenFactory samlFactory =
SAMLTokenFactory.getInstance("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0");//samlTokenType
CredentialConfig credentialConfig = samlFactory.newCredentialConfig();
credentialConfig.setRequesterNameID("any name");
SAMLAttribute sattribute =
new SAMLAttribute("urn:oid:2.5.4.20", //Name
new String[] {" any address"}, //Attribute Values
null, /*XML Attributes empty on this example*/
"urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500", //NameSpace
"urn:oasis:names:tc:SAML:2.0:attrname-format:uri", //format
"Address");
ArrayList<SAMLAttribute> al = new ArrayList<SAMLAttribute>();
al.add(sattribute);
credentialConfig.setSAMLAttributes(al);
SAMLTokenFactory samlFactory =
SAMLTokenFactory.getInstance("http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1");
SAMLToken aSamlToken = samlFactory.newSAMLToken(credentialConfig, reqData, samlIssuerCfg);
List<SAMLAttribute> aList = aSAMLToken.getSAMLAttributes();
java.util.Iterator<SAMLAttribute> i = aList.iterator();
while(i.hasNext()){
SAMLAttribute anAttribute = i.next();
//do something with namespace
String namespace = anAttribute.getAttributeNamespace();
//do something with name
String name = anAttribute.getName();
//do something with friendly name
String friendlyName = anAttribute.getFriendlyName();
//process sring attribute values
String[] stringAttributeValues = anAttribute.getStringAttributeValue();
//process XML attribute values
XMLStructure[] xmlAttributeValues = (XMLStructure[]) anAttribute.getXMLAttributeValue();
}