Write an OpenToken as a WSC
The OpenToken Agent API provides access to functionality for writing an OpenToken as a WSC to include in an Issue request to the PingFederate STS.
Java Sample Code
The writeToken method of the Agent class takes an org.apache.commons.collections.MultiMap collection of attributes and encodes them into an OpenToken.
The collection of attributes must contain a key named “subject” for a valid token to be generated. |
If any errors are encountered while creating the token, a TokenException is thrown.
The code snippet below demonstrates generating an OpenToken and using the PingFederate STS Java Client SDK to send the OpenToken to the PingFederate STS:
// Configure the Opentoken agent AgentConfiguration agentConfiguration = new AgentConfiguration(); agentConfiguration.setPassword("2Federate"); agentConfiguration.setCipherSuite(Token.CIPHER_SUITE_AES128CBC); // Instantiate the OpenToken agent Agent agent = new Agent(agentConfiguration); // Set OpenToken attributes MultiMap values = new MultiValueMap(); values.put(Agent.TOKEN_SUBJECT, "joe"); values.put("foo", "bar"); String tokenData = agent.writeToken(values); // Configure STS Client STSClientConfiguration idpStsConfig = new STSClientConfiguration(); idpStsConfig.setAppliesTo("http://sp.domain.com"); idpStsConfig.setStsEndpoint("https://idp.domain.com:9031/idp/sts.wst"); idpStsConfig.setInTokenType(TokenType.BINARY); idpStsConfig.setInTokenValueType(TokenType.OPENTOKEN); // Instantiate STS Client STSClient idpStsClient = new STSClient(idpStsConfig); // Send RST Issue request to STS Element samlToken = idpStsClient.issueToken(tokenData);