Creating SAML attributes in SAML tokens

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.

关于此任务

Using WebSphere® Application Server, you can create SAML attributes using the SAML token library APIs. The SAML attributes are added to a CredentialConfig object, which is used to generate a SAML token. The API also provides a function that extracts SAML attributes from an existing SAML token and processes the attributes.

To create a SAML token containing SAML attributes, perform the following steps:

过程

  1. Initialize a com.ibm.wsspi.wssecurity.saml.data.SAMLAttribute object. This creates a SAML attribute based on an address, for example:
    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");
  2. 使用 SAMLTokenFactory 来创建包含 SAML 属性的 CredentialConfig 对象。此方法需要 Java 安全性许可权 wssapi.SAMLTokenFactory.newCredentialConfig。
    1. 创建 com.ibm.wsspi.wssecurity.saml.config.CredentialConfig 对象并设置有效的主体名称。
    2. 创建 SAML 属性。
    3. 创建 SAML 属性的列表,并将该 SAML 属性添加到该列表。
    4. 将 SAML 属性列表添加到 CredentialConfig 对象。
    请参阅以下示例:
    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);
  3. 将 CredentialConfig 指定为参数时,请使用 com.ibm.websphere.wssecurity.wssapi.token.SAMLTokenFactory newSAMLToken 方法来创建包含这些属性的 SAML 令牌。 此步骤假设已创建了 RequesterConfig reqData 对象和 ProviderConfig samlIssuerCfg 对象。有关这些对象的更多信息,请参阅关于 RequesterConfig 和 ProviderConfig 的内容。
    1. 获取 SAMLTokenFactory 的实例。
    2. 使用 newSAMLToken 方法从 SAMLTokenFactory 创建 SAML 令牌,例如:
      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);
  4. 可选: 从现有 SAML 令牌抽取 SAML 属性。此步骤对于从已接收到的 SAML 令牌抽取 SAML 属性非常有用。已接收到 SAML 声明并且需要处理该声明中所包含的属性时,您可以使用此步骤。
    1. 将令牌用作参数来调用 getSAMLAttributes() 方法以获取令牌中的 SAML 属性列表。 此方法需要 Java 安全性许可权 wssapi.SAMLToken.getSAMLAttributes。
    2. 对列表应用迭代器。
    3. 迭代整个列表并执行应用程序所需的任何其他处理。
    请参阅以下示例:
    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();
    
       }

指示主题类型的图标 任务主题



时间戳记图标 最近一次更新时间: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_managesamlattribs
文件名:twbs_managesamlattribs.html