Package com.vmware.connection
Class SsoConnection
- java.lang.Object
-
- com.vmware.connection.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSsoConnection.SSOLoginExceptionthrown when a login has failed for a reasonclassSsoConnection.SSOLogoutExceptionthrown on logout when something fails
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringcertFileNameYou may optionally specify the system property sso.cert.file=/fully/qualified/path to load your SSL cert from a file.java.lang.StringpkeyFileNameYou may optionally specify the system property sso.pkey.file=/fully/qualified/path to load your SSL private key from a file.static java.lang.StringSSO_URL
-
Constructor Summary
Constructors Constructor Description SsoConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Connectionconnect()Connectiondisconnect()properly disconnect the connection and set stale objects to "null" to help the garbage collector in resource constrained environments.java.lang.StringgetDefaultSsoUrl()Generates a default SSO URL to use if none was supplied on the command line.java.util.MapgetHeaders()the cached headers gleaned from the last connection atttemptjava.lang.StringgetHost()java.lang.StringgetPassword()java.lang.IntegergetPort()com.vmware.vim25.ServiceContentgetServiceContent()java.lang.StringgetServiceInstanceName()com.vmware.vim25.ManagedObjectReferencegetServiceInstanceReference()A service instance reference used to boot strap the clientjava.net.URLgetSsoUrl()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.StringgetUrl()java.net.URLgetURL()gets the URL used for this connectionjava.lang.StringgetUsername()com.vmware.vim25.UserSessiongetUserSession()com.vmware.vim25.VimPortTypegetVimPort()com.vmware.vim25.VimServicegetVimService()booleanisConnected()returns true if the connection is open, and hasn't timed out.voidloadUserCert()Load a cached key and cert from the file system if no X509Certificate is present on the file system, calls "generate"org.w3c.dom.Elementlogin()returns the token used for login to SSOvoidsetPassword(java.lang.String password)com.vmware.vim25.VimServicesetupVimService(org.w3c.dom.Element token, com.vmware.sso.client.soaphandlers.SSOHeaderHandler... handlers)sets up a VIM service registering handlers and handler resolvers.voidsetUrl(java.lang.String url)voidsetUsername(java.lang.String username)
-
-
-
Field Detail
-
SSO_URL
public static final java.lang.String SSO_URL
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
getSsoUrl
public java.net.URL getSsoUrl() throws java.net.MalformedURLExceptionWill 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 propertiessso.hostsso.portandsso.pathto 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/STSServicewhich may not be correct.- Returns:
- the URL to the SSO server to try
-
setUrl
public void setUrl(java.lang.String url)
- Specified by:
setUrlin interfaceConnection
-
getUrl
public java.lang.String getUrl()
- Specified by:
getUrlin interfaceConnection
-
getHost
public java.lang.String getHost()
- Specified by:
getHostin interfaceConnection
-
getPort
public java.lang.Integer getPort()
- Specified by:
getPortin interfaceConnection
-
setUsername
public void setUsername(java.lang.String username)
- Specified by:
setUsernamein interfaceConnection
-
getUsername
public java.lang.String getUsername()
- Specified by:
getUsernamein interfaceConnection
-
setPassword
public void setPassword(java.lang.String password)
- Specified by:
setPasswordin interfaceConnection
-
getPassword
public java.lang.String getPassword()
- Specified by:
getPasswordin interfaceConnection
-
getVimService
public com.vmware.vim25.VimService getVimService()
- Specified by:
getVimServicein interfaceConnection
-
getVimPort
public com.vmware.vim25.VimPortType getVimPort()
- Specified by:
getVimPortin interfaceConnection
-
getServiceContent
public com.vmware.vim25.ServiceContent getServiceContent()
- Specified by:
getServiceContentin interfaceConnection
-
getUserSession
public com.vmware.vim25.UserSession getUserSession()
- Specified by:
getUserSessionin interfaceConnection
-
getServiceInstanceName
public java.lang.String getServiceInstanceName()
- Specified by:
getServiceInstanceNamein interfaceConnection
-
getHeaders
public java.util.Map getHeaders()
the cached headers gleaned from the last connection atttempt- Specified by:
getHeadersin interfaceConnection- Returns:
-
getServiceInstanceReference
public com.vmware.vim25.ManagedObjectReference getServiceInstanceReference()
A service instance reference used to boot strap the client- Specified by:
getServiceInstanceReferencein interfaceConnection- 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 tokenhandlers- - arbitrary number of handlers- Returns:
- a properly configured VimService object
- See Also:
VimService
-
connect
public Connection connect()
- Specified by:
connectin interfaceConnection
-
loadUserCert
public void loadUserCert() throws java.lang.ExceptionLoad 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:
isConnectedin interfaceConnection- 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:
disconnectin interfaceConnection- Returns:
-
getURL
public java.net.URL getURL()
gets the URL used for this connection- Specified by:
getURLin interfaceConnection- Returns:
-
-