This example is based on the code in the ExternalPscSsoWorkflow.java sample.

Note

For a complete and up-to-date version of the sample code, see the vSphere Automation SDK Java samples 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);