使用 API 创建 SAML 不记名令牌
使用 SAML 库 API 来创建 SAML 不记名令牌。
关于此任务
此库允许您创建 SAML 不记名令牌。 您可以使用 SAML 库 API 来创建所需的 SAML 配置对象,然后使用这些配置对象来生成不记名 SAML 令牌。
过程
示例
使用此样本代码从主体集创建 SAML v1.1 不记名令牌:
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 v1.1 不记名令牌而不使用该主体集:
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);