Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230900

Re: SSO Auth for Java REST calls

$
0
0

Hi Sam,

 

There is no need to update to 5.1U1. Here is a sample showing code how to call a REST API in SSO mode

 

public void ssoExample() throws URISyntaxException, IOException {  URI ssoUri = new URI("https://10.23.32.208:7444/ims/STSService");  URI vcoUri = new URI("https://10.23.118.186:8281/api");  long lifeTimeSeconds = 24 * 60 * 60; // 24 hours  String user = "root";  String password = "vmware";  // Obtain a session  VcoSessionFactory sessionFactory = createSessionFactory(vcoUri);  SsoAuthenticator authenticator = new SsoAuthenticator(ssoUri, sessionFactory, lifeTimeSeconds);  Authentication auth = authenticator.createSsoAuthentication(user, password);  VcoSession session = sessionFactory.newSession(auth);  WorkflowService workflowService = new WorkflowService(session);  Workflow workflow = workflowService.getWorkflow("123"); // provide a real workflow ID here  if (workflow != null) {  System.out.println("workflow found");  } else {  System.out.println("workflow not found");  }
}
// Create insecure session factory (skip certificate validation)
private VcoSessionFactory createSessionFactory(URI vcoUri) throws URISyntaxException {  return new DefaultVcoSessionFactory(vcoUri) {  @Override  protected HostnameVerifier newHostnameVerifier() {  return newUnsecureHostnameVerifier();  }  @Override  protected SSLContext newSSLContext() throws KeyManagementException, NoSuchAlgorithmException {  return newUnsecureSSLContext();  }  };
}

 

Hope this helps,

 

-Ilian


Viewing all articles
Browse latest Browse all 230900

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>