Java Example of Creating a
vSphere Automation
API Session with a SAML Token

This example is based on the code in the
ExternalPscSsoWorkflow.java
sample.
This example uses the steps that are described in the Create a vSphere Automation Session with a SAML Token
For a complete and up-to-date version of the Java sample code, see the
vsphere-automation-sdk-java
VMware repository at GitHub.
... this.stubFactory = createApiStubFactory(server, httpConfig); // Create a SAML security context using SAML bearer token SecurityContext samlSecurityContext = SecurityContextFactory.createSamlSecurityContext( samlBearerToken, null); // Create a stub configuration with SAML security context StubConfiguration stubConfig = new StubConfiguration(samlSecurityContext); // Create a session stub using the stub configuration. Session session = this.stubFactory.createStub(Session.class, stubConfig); // Log in and create a session char[] sessionId = session.create(); // Initialize a session security context from the generated session id SessionSecurityContext sessionSecurityContext = new SessionSecurityContext(sessionId); // Update the stub configuration to use the session id stubConfig.setSecurityContext(sessionSecurityContext); /* * Create a stub for the session service using the authenticated * session */ this.sessionSvc = this.stubFactory.createStub(Session.class, stubConfig); VM vmService = this.stubFactory.createStub(VM.class, stubConfig);