Using LoginByToken
The code fragment in this section sets up the message handlers and calls the LoginByToken method. The following sequence describes the steps and shows the corresponding objects and methods.
1
Create a new HeaderHandlerResolver. Then set the message security handlers for cookie insertion and for inserting the SAML token and credentials in the SOAP header.
The following examples shows Java code that calls the LoginByToken method.
Example: Using LoginByToken
/*
* Create a handler resolver and add the handlers.
*/
HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
handlerResolver.addHandler(new TimeStampHandler());
handlerResolver.addHandler(new SamlTokenHandler(token));
handlerResolver.addHandler(new HeaderCookieHandler(cookie));
handlerResolver.addHandler(new WsSecuritySignatureAssertionHandler(
userCert.getPrivateKey(),
userCert.getUserCert(),
Utils .getNodeProperty(token, "ID")));
vimService.setHandlerResolver(handlerResolver);
 
/*
* Get the Vim port; this call clears the request context.
*/
vimPort = vimService.getVimPort();
 
/*
* Retrieve the request context and set the server URL.
*/
Map<String, Object> ctxt = ((BindingProvider) vimPort) .getRequestContext();
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, vcServerUrl);
ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
 
/*
* Call LoginByToken.
*/
UserSession us = vimPort.loginByToken( serviceContent.getSessionManager(), null);