Class LoginByTokenSample


  • public class LoginByTokenSample
    extends java.lang.Object
    Sample program demonstrating the usage of the new LoginByToken method, introduced to authenticate the client using the SAML token obtained from the SSO server. This sample illustrates the usage of both Bearer token as well as the HolderOfKey token for authenticating to a vCenter server
     Usage:
     run.bat com.vmware.vsphere.samples.LoginByTokenSample [sso url] [username] [password] [vCenter url]
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.vmware.vim25.ManagedObjectReference SVC_INST_REF  
      static com.vmware.vim25.VimPortType vimPort  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void getCurrentTime()
      This method retrieves the current time from the server and prints it.
      static java.lang.String loginUsingSAMLToken​(org.w3c.dom.Element token, java.lang.String vcServerUrl, java.security.PrivateKey privateKey, java.security.cert.X509Certificate publicCert)
      This method invokes the loginByToken method for authentication.
      static void logout()
      Disconnects the user session.
      static void main​(java.lang.String[] args)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • vimPort

        public static com.vmware.vim25.VimPortType vimPort
      • SVC_INST_REF

        public static com.vmware.vim25.ManagedObjectReference SVC_INST_REF
    • Constructor Detail

      • LoginByTokenSample

        public LoginByTokenSample()
    • Method Detail

      • getCurrentTime

        public static void getCurrentTime()
        This method retrieves the current time from the server and prints it.
      • loginUsingSAMLToken

        public static java.lang.String loginUsingSAMLToken​(org.w3c.dom.Element token,
                                                           java.lang.String vcServerUrl,
                                                           java.security.PrivateKey privateKey,
                                                           java.security.cert.X509Certificate publicCert)
                                                    throws com.vmware.vim25.RuntimeFaultFaultMsg,
                                                           com.vmware.vim25.InvalidLocaleFaultMsg,
                                                           com.vmware.vim25.InvalidLoginFaultMsg
        This method invokes the loginByToken method for authentication. Once this method is called the established session is authenticated and operations can be performed on the connected vCenter server
        Parameters:
        token - Element representing the SAML token that needs to be used for the authentication
        vcServerUrl - The vCenter server url that needs to be connected
        privateKey - PrivateKey of the user. Only required when using HoK token to login
        publicCert - X509Certificate certificate of the user. Only required when using HoK token to login
        Returns:
        String authenticated session cookie used by the connection
        Throws:
        com.vmware.vim25.RuntimeFaultFaultMsg
        com.vmware.vim25.InvalidLocaleFaultMsg
        com.vmware.vim25.InvalidLoginFaultMsg
      • logout

        public static void logout()
                           throws com.vmware.vim25.RuntimeFaultFaultMsg
        Disconnects the user session.
        Throws:
        com.vmware.vim25.RuntimeFaultFaultMsg
      • main

        public static void main​(java.lang.String[] args)
                         throws javax.xml.datatype.DatatypeConfigurationException,
                                com.vmware.vim25.RuntimeFaultFaultMsg,
                                com.vmware.vim25.InvalidLocaleFaultMsg,
                                com.vmware.vim25.InvalidLoginFaultMsg
        Throws:
        javax.xml.datatype.DatatypeConfigurationException
        com.vmware.vim25.RuntimeFaultFaultMsg
        com.vmware.vim25.InvalidLocaleFaultMsg
        com.vmware.vim25.InvalidLoginFaultMsg