Example: Acquiring a vCenter Single Sign On Token – Sending the Request
STSService stsPort = stsService.getSTSServicePort();
RequestSecurityTokenType tokenType = new RequestSecurityTokenType();
LifetimeType lifetime = new LifetimeType();
DatatypeFactory dtFactory = DatatypeFactory.newInstance();
GregorianCalendar cal = new GregorianCalendar( TimeZone.getTimeZone("GMT"));
XMLGregorianCalendar xmlCalendar = dtFactory .newXMLGregorianCalendar(cal);
AttributedDateTime created = new AttributedDateTime();
created.setValue(xmlCalendar.toXMLFormat());
AttributedDateTime expires = new AttributedDateTime();
xmlCalendar.add(dtFactory.newDuration(30 * 60 * 1000));
expires.setValue(xmlCalendar.toXMLFormat());
lifetime.setCreated(created);
lifetime.setExpires(expires);
tokenType.setTokenType("urn:oasis:names:tc:SAML:2.0:assertion");
tokenType .setRequestType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue");
tokenType.setLifetime(lifetime);
tokenType .setKeyType("http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey");
tokenType .setSignatureAlgorithm("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256");
RenewingType renewing = new RenewingType();
renewing.setAllow(Boolean.TRUE);
renewing.setOK(Boolean.FALSE); // WS-Trust Profile: MUST be set to false
tokenType.setRenewing(renewing);
/* Get the request context and set the endpoint address. */
Map<String, Object> reqContext = ((BindingProvider) stsPort) .getRequestContext();
reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, args[0]);
* Use the STS port to invoke the "issue" method to acquire the token
RequestSecurityTokenResponseCollectionType issueResponse = stsPort .issue(tokenType);
* Handle the response - extract the SAML token from the response. The response type
RequestSecurityTokenResponseType rstResponse = issueResponse .getRequestSecurityTokenResponse();
RequestedSecurityTokenType requestedSecurityToken = rstResponse .getRequestedSecurityToken();