Inserindo Atributos SAML Usando WSS APIs
É possível inserir atributos customizados no tokens SAML emitidos automaticamente usando o modelo de programação Java™ API for XML-Based Web Services (JAX-WS) e o Web Services Security APIs (WSS APIs).
Antes de Iniciar
Essa tarefa assume que você é familiarizado com o modelo de programação JAX-WS, as interfaces API WSS, os conceitos de SAML, e o uso dos conjuntos de política para configurar e administrar as configurações dos serviços da Web.
Conclua as ações a seguir antes de iniciar essa tarefa:
- Consulte a propagação de tokens de acesso SAML emitidos automaticamente usando WSS APIs.
- Consulte a propagação de tokens sender-vouches SAML emitidos automaticamente usando WSS APIs com proteção de nível de mensagem.
- Consulte a propagação de tokens sender-vouches SAML emitidos automaticamente usando WSS APIs com proteção de nível de transporte SSL.
- Consulte a propagação de tokens holder-of-key SAML emitidos automaticamente com a chave simétrica usando WSS APIs.
- Consulte a propagação de tokens holder-of-key SAML emitidos automaticamente com a chave assimétrica usando WSS APIs.
Sobre Esta Tarefa
Procedimento
Insira atributos customizados quando criar tokens de segurança SAML, por
exemplo:
import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken;
import com.ibm.websphere.wssecurity.callbackhandler.SAMLGenerateCallbackHandler;
import com.ibm.websphere.wssecurity.wssapi.token.SAMLToken;
import com.ibm.wsspi.wssecurity.core.token.config.WSSConstants;
import com.ibm.wsspi.wssecurity.saml.config.SamlConstants;
import com.ibm.wsspi.wssecurity.saml.data.SAMLAttribute;
WSSFactory factory = WSSFactory.getInstance();
HashMap<Object, Object> map = new HashMap<Object, Object>();
map.put(SamlConstants.CONFIRMATION_METHOD, "Bearer");
map.put(SamlConstants.Token_REQUEST, "issue");
map.put(SamlConstants.TOKEN_TYPE, WSSConstants.SAML.SAML20_VALUE_TYPE);
map.put(SamlConstants.SAML_NAME_IDENTIFIER, "Alice");
map.put(SamlConstants.SIGNATURE_REQUIRED, "true");
ArrayList<SAMLAttribute> al = new ArrayList<SAMLAttribute>();
String groups[] = {"IBMer", "Texan"};
SAMLAttribute sattribute = new SAMLAttribute("Membership", groups, null,null, null, null);
al.add(sattribute);
String gender[] = {"Female"};
sattribute = new SAMLAttribute("Gender", gender, null,null, null, null);
al.add(sattribute);
map.put(SamlConstants.SAML_ATTRIBUTES, al);
SAMLGenerateCallbackHandler callbackHandler = new
SAMLGenerateCallbackHandler(map);
SecurityToken samlToken = factory.newSecurityToken(SAMLToken.class, callbackHandler,
"system.wss.generate.saml");
Resultados
Atributos customizados foram inseridos em um token de segurança SAML.
Exemplo
<saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"
Version="2.0"
ID="_E62A1CA3C2F21D9A9B1287772824570"
IssueInstant="2010-10-22T18:40:24.531Z">
<saml2:Issuer>example.com</samls2:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
...
</ds:Signature>
<saml2:Subject>
<saml2:NameID>Alice</saml2:NameID>
<saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"></saml2:SubjectConfirmation>
</saml2:Subject>
<saml2:Conditions NotBefore="2010-10-22T18:40:24.531Z"
NotOnOrAfter="2010-10-22T19:40:24.531Z">
</saml2:Conditions>
<saml2:AttributeStatement>
<saml2:Attribute Name="Membership">
<saml2:AttributeValue>IBMer</saml2:AttributeValue>
<saml2:AttributeValue>Texan</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="Gender">
<saml2:AttributeValue>Female</saml2:AttributeValue>
</saml2:Attribute>
</saml2:AttributeStatement>
</saml2:Assertion>