SampleCodeAuthAndDisco

From OpenLiberty.org Wiki

Jump to: navigation, search

SAMPLE CODE: Bootstrap Into ID-WSF - in two steps

The following code uses the WSCUtilities class. This assumes that you have downloaded the source code and have it available in your java IDE (follow the instructions here: 5 Step Start).

STEP 1: Set Some Default Authentication Service Values

First we set some static values that the Authentication Service Client will need.

NOTE: This code is included in the "ClientLibTest.java" class which is in the org.openliberty.wsc.test package included in the source repo.

// Setup for the AS
OpenLibertyBootstrap.setAuthenticationServiceUrl(SERVICE_URL);
OpenLibertyBootstrap.setAuthUsername(USERNAME);
OpenLibertyBootstrap.setAuthPassword(PASSWORD);            
SSLUtilities.loadX509Certificate(PATH_TO_CERT);

STEP 2: Authenticate & Discovery Bootstrap

Now we call utility methods to:

  • Authenticate with the AS and get a Discovery Service Boostrap EPR (Disco EPR)
  • Use the Disco EPR to query for the discovery service
// Get an Endpoint Reference for the Discovery Service, using PLAIN authentication
EndpointReference discoEPR = WSCUtilities.boostrapDiscoveryEPRFromDefaultAS(AuthenticationService.AuthMechanism.PLAIN);

// Query the discovery service for the Discovery Service (Self referential test)
DiscoveryService discoveryService = (DiscoveryService)WSCUtilities.clientForDiscoveryEPR(discoEPR, DiscoveryService.WSFServiceType.DISCOVERY_SERVICE);
Personal tools