API を使用した属性の追加および既存の SAML トークンの再署名

SAML ライブラリー API を使用して、暗号化されていない SAML トークンに対して属性の追加や属性の削除を行い、その SAML トークンに署名または再署名することができます。SAML トークン・オブジェクトを変更するアクションが実行される際に、そのオブジェクトにデジタル署名が既に存在すれば、常にその既存のデジタル署名は削除されます。

このタスクについて

以下の手順では、既存の SAMLToken オブジェクトを変更し、その後トークンに新しいデジタル署名を適用する方法について説明します。このタスクでは、既存の SAMLToken オブジェクトを取得する方法を示していません。既存の SAMLToken オブジェクトは、LoginModule 共有状態によってインバウンド SOAP から取得するか、基本セキュリティー・サブジェクトによって SAML Web SSO から取得するか、トラスト・クライアントを使用する STS、または SAML API で作成された自己発行トークンから取得することができます。

SAML API が構成オブジェクトを初期化する際に、SamlIssuerConfig.properties から構成を取得します。 SamlIssuerConfig.properties の設定を使用するか、それらをオーバーライドするかを選択できます。この手順では、このファイル内のすべての設定をオーバーライドする方法を説明します。

手順

  1. 既存の SAML トークンのクローンを作成します
    import java.util.ArrayList;
    import org.apache.axiom.om.OMElement;
    import com.ibm.websphere.wssecurity.wssapi.token.SAMLToken;
    import com.ibm.websphere.wssecurity.wssapi.token.SAMLTokenFactory;
    import com.ibm.wsspi.wssecurity.saml.config.ProviderConfig;
    import com.ibm.wsspi.wssecurity.saml.config.RequesterConfig;
    import com.ibm.wsspi.wssecurity.saml.data.SAMLAttribute;
    import com.ibm.wsspi.wssecurity.wssapi.OMStructure;
    ....
    
    //someSAMLToken is the existing SAMLToken object
    
    SAMLTokenFactory samlFactory = null;
    
    //initialize the desired SAML token factory
    //samlFactory = SAMLTokenFactory.getInstance(SAMLTokenFactory.WssSamlV11Token11);
    samlFactory = SAMLTokenFactory.getInstance(SAMLTokenFactory.WssSamlV20Token11);
    
    //clone the existing SAMLToken object if desired.
    SAMLToken mySamlToken = factory.newSAMLToken(someSamlToken);
  2. トークンに属性を追加するか、トークンから属性を削除します
    //add a single attribute
    SAMLAttribute sattribute1 = new SAMLAttribute("Purchases", new String[] {"TooMany"},  null, null, null, null);
    mySamlToken.addAttribute(sattribute1);
    
    //after this first addAttribute, there will not be a digital signature in the
    //token's XML.  Doing a token modification invalidated the signature.
    
    //add a list of attributes
    SAMLAttribute sattribute2 = new SAMLAttribute("Address", new String[] {"Austin, Texas"},null,null,"IBM NameFormat","IBM FriendlyName");
    SAMLAttribute sattribute3 = new SAMLAttribute("Membership",new String[] {"Blue team", "Green Team"},null,null,null,null );
    
    ArrayList al = new ArrayList();
    al.add(sattribute2);
    al.add(sattribute3);
    
    mySamlToken.addAttribute(al);
    
    //delete an attribute
    mySamlToken.deleteAttribute(sattribute3);
    ....
  3. SAML トークンに再署名します。
    RequesterConfig reqData = null;
    
    //initialize the desired requester config
    //reqData = samlFactory.newSenderVouchesTokenGenerateConfig();
    reqData = samlFactory.newBearerTokenGenerateConfig();
    
    //initialize the provider config object with an issuer name
    ProviderConfig samlIssuerCfg = samlFactory.newDefaultProviderConfig("myIssuer");
    
    //Or preserve the existing issuer by setting the issuer URI to null
    //samlIssuerCfg.setIssuerURI(null);
    
    //set the keystore information for use with digital signature in the provider config object
    KeyStoreConfig ksc = samlFactory.newKeyStoreConfig( "jks", "/myx509.ks", "myx509");
    samlIssuerCfg.setKeyStoreConfig(ksc);
    
    //set the key information for use with digital signature in the provider config object
    KeyInformationConfig kic = samlFactory.newKeyInformationConfig("mySignAlias", "password", "CN=ME");
    samlIssuerCfg.setKeyInformationConfig(kic);
    
    //create a new SAMLToken object that is a signed clone of the input token
    SAMLToken myNewSamlToken = samlFactory.newSAMLToken(mySamlToken,reqData,samlIssuerCfg);
  4. SAML トークン XML を検査して、変更を確認します
    //get the SAML Assertion element
    OMElement samlElement = ((OMStructure) myNewSamlToken.getXML()).getNode();
    
    //convert the element to a String
    String xmlString = samlElement.toString();

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_addingattributesandresigningexistingSAMLtokens
ファイル名:twbs_addingattributesandresigningexistingSAMLtokens.html