API を使用した SAML bearer トークンの作成
SAML ライブラリー API を使用して、SAML bearer トークンを作成します。
このタスクについて
このライブラリーを使用して、SAML bearer トークンを作成できます。 必要な SAML 構成オブジェクトを SAML ライブラリー API を 使用して作成し、それらの構成オブジェクトを使用して bearer SAML トークンを作成することができます。
手順
例
SAML バージョン 1.1 bearer トークン
をサブジェクトから作成するには、次のサンプル・コードを使用します。
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);
サブジェクトを使用せずに SAML バージョン 1.1 bearer トークン
を作成するには、次のサンプル・コードを使用します。
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);