Class SsoConnection

  • All Implemented Interfaces:
    Connection

    public class SsoConnection
    extends java.lang.Object
    implements Connection
    Demonstrates SSO with vCenter's SSO service. This only demonstrates HolderOfKey based logins.
    See Also:
    AcquireHoKTokenByUserCredentialSample
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String certFileName
      You may optionally specify the system property sso.cert.file=/fully/qualified/path to load your SSL cert from a file.
      java.lang.String pkeyFileName
      You may optionally specify the system property sso.pkey.file=/fully/qualified/path to load your SSL private key from a file.
      static java.lang.String SSO_URL  
    • Constructor Summary

      Constructors 
      Constructor Description
      SsoConnection()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Connection connect()  
      Connection disconnect()
      properly disconnect the connection and set stale objects to "null" to help the garbage collector in resource constrained environments.
      java.lang.String getDefaultSsoUrl()
      Generates a default SSO URL to use if none was supplied on the command line.
      java.util.Map getHeaders()
      the cached headers gleaned from the last connection atttempt
      java.lang.String getHost()  
      java.lang.String getPassword()  
      java.lang.Integer getPort()  
      com.vmware.vim25.ServiceContent getServiceContent()  
      java.lang.String getServiceInstanceName()  
      com.vmware.vim25.ManagedObjectReference getServiceInstanceReference()
      A service instance reference used to boot strap the client
      java.net.URL getSsoUrl()
      Will attempt to return the SSO URL you set from the command line, if you forgot or didn't set one it will call getDefaultSsoUrl to attempt to calculate what the URL should have been.
      java.lang.String getUrl()  
      java.net.URL getURL()
      gets the URL used for this connection
      java.lang.String getUsername()  
      com.vmware.vim25.UserSession getUserSession()  
      com.vmware.vim25.VimPortType getVimPort()  
      com.vmware.vim25.VimService getVimService()  
      boolean isConnected()
      returns true if the connection is open, and hasn't timed out.
      void loadUserCert()
      Load a cached key and cert from the file system if no X509Certificate is present on the file system, calls "generate"
      org.w3c.dom.Element login()
      returns the token used for login to SSO
      void setPassword​(java.lang.String password)  
      com.vmware.vim25.VimService setupVimService​(org.w3c.dom.Element token, com.vmware.sso.client.soaphandlers.SSOHeaderHandler... handlers)
      sets up a VIM service registering handlers and handler resolvers.
      void setUrl​(java.lang.String url)  
      void setUsername​(java.lang.String username)  
      • Methods inherited from class java.lang.Object

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

      • pkeyFileName

        public final java.lang.String pkeyFileName
        You may optionally specify the system property sso.pkey.file=/fully/qualified/path to load your SSL private key from a file.
        See Also:
        SecurityUtil
      • certFileName

        public final java.lang.String certFileName
        You may optionally specify the system property sso.cert.file=/fully/qualified/path to load your SSL cert from a file.
        See Also:
        SecurityUtil
    • Constructor Detail

      • SsoConnection

        public SsoConnection()
    • Method Detail

      • getSsoUrl

        public java.net.URL getSsoUrl()
                               throws java.net.MalformedURLException
        Will attempt to return the SSO URL you set from the command line, if you forgot or didn't set one it will call getDefaultSsoUrl to attempt to calculate what the URL should have been.
        Returns:
        the URL for the SSO services
        Throws:
        java.net.MalformedURLException
      • getDefaultSsoUrl

        public java.lang.String getDefaultSsoUrl()
        Generates a default SSO URL to use if none was supplied on the command line. This will attempt to use the system properties sso.host sso.port and sso.path to construct a URL for the SSO server. These properties are all optional.

        If no value is set sso.host will default to the url of the WS server (assuming SSO and WS are hosted on the same IP)

        If no value is set sso.port will default to 7444

        If no value is set, sso.path will default to /ims/STSService which may not be correct.

        Returns:
        the URL to the SSO server to try
      • setUrl

        public void setUrl​(java.lang.String url)
        Specified by:
        setUrl in interface Connection
      • getUrl

        public java.lang.String getUrl()
        Specified by:
        getUrl in interface Connection
      • getHost

        public java.lang.String getHost()
        Specified by:
        getHost in interface Connection
      • getPort

        public java.lang.Integer getPort()
        Specified by:
        getPort in interface Connection
      • setUsername

        public void setUsername​(java.lang.String username)
        Specified by:
        setUsername in interface Connection
      • getUsername

        public java.lang.String getUsername()
        Specified by:
        getUsername in interface Connection
      • setPassword

        public void setPassword​(java.lang.String password)
        Specified by:
        setPassword in interface Connection
      • getPassword

        public java.lang.String getPassword()
        Specified by:
        getPassword in interface Connection
      • getVimService

        public com.vmware.vim25.VimService getVimService()
        Specified by:
        getVimService in interface Connection
      • getVimPort

        public com.vmware.vim25.VimPortType getVimPort()
        Specified by:
        getVimPort in interface Connection
      • getServiceContent

        public com.vmware.vim25.ServiceContent getServiceContent()
        Specified by:
        getServiceContent in interface Connection
      • getUserSession

        public com.vmware.vim25.UserSession getUserSession()
        Specified by:
        getUserSession in interface Connection
      • getHeaders

        public java.util.Map getHeaders()
        the cached headers gleaned from the last connection atttempt
        Specified by:
        getHeaders in interface Connection
        Returns:
      • getServiceInstanceReference

        public com.vmware.vim25.ManagedObjectReference getServiceInstanceReference()
        A service instance reference used to boot strap the client

        Specified by:
        getServiceInstanceReference in interface Connection
        Returns:
        the top level ServiceInstanceReference
      • login

        public org.w3c.dom.Element login()
        returns the token used for login to SSO
        Returns:
        token to use for Single Sign On security
      • setupVimService

        public com.vmware.vim25.VimService setupVimService​(org.w3c.dom.Element token,
                                                           com.vmware.sso.client.soaphandlers.SSOHeaderHandler... handlers)
        sets up a VIM service registering handlers and handler resolvers. Takes an arbitrary number of handlers.
        Parameters:
        token - - service token
        handlers - - arbitrary number of handlers
        Returns:
        a properly configured VimService object
        See Also:
        VimService
      • loadUserCert

        public void loadUserCert()
                          throws java.lang.Exception
        Load a cached key and cert from the file system if no X509Certificate is present on the file system, calls "generate"
        Throws:
        java.lang.Exception
      • isConnected

        public boolean isConnected()
        returns true if the connection is open, and hasn't timed out. Connections time-out every 30 minutes.
        Specified by:
        isConnected in interface Connection
        Returns:
        true if a good, non-stale connection
      • disconnect

        public Connection disconnect()
        properly disconnect the connection and set stale objects to "null" to help the garbage collector in resource constrained environments.
        Specified by:
        disconnect in interface Connection
        Returns:
      • getURL

        public java.net.URL getURL()
        gets the URL used for this connection
        Specified by:
        getURL in interface Connection
        Returns: