This document contains examples of typical use cases for the Single Sign-On API. These examples demonstrate calls to the SOAP interface and are provided as is.
Full API documentation is available here.
The following examples demonstrate calls to the Single Sign-On API in Java.
These examples assume the use of a generated XML web service client. To generate such a client, a tool such as wsdl2java can be used. A detailed description on this tool can be found on the Apache Web Services website, but all you will need to do is point it at your site's Single Sign-On API endpoint. A detailed description of how to generate a web service client is beyond the scope of this document.
// Instantiate the web service proxy
ISAMSSingleSignOnAPI service = new ISAMSSingleSignOnAPI();
// User to authenticate with
String username = "Testing";
// Corresponding password to authenticate with
String password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.authenticate(username, password);
String token = authenticationResponse.getMessage();
// Create a new LoginCustomer instance containing the new customer's details
LoginCustomer customer = new LoginCustomer();
customer.setEmail("[email protected]");
customer.setPassword("fourscoreand7");
customer.setFirstName("Abraham");
customer.setLastName("Lincoln");
customer.setInterestGroups(new String[] { "Emancipation" });
// Call the web service to create the customer
CustomerLoginResponse createResponse =
service.create(token, customer);
// Check for success and respond accordingly
if (createResponse.isSuccess()) {
System.out.printf("ID: %s", createResponse.getCustomer().getID());
// Output: "ID: Vsk6JBlJj3sNwKfGDY2w4w=="
} else {
System.out.printf("Failed to create customer %s", customer.getEmail());
}
// Instantiate the web service proxy ISAMSSingleSignOnAPI service = new ISAMSSingleSignOnAPI(); // User to authenticate with String username = "Testing"; // Corresponding password to authenticate with String password = "Sup94zex"; // Authenticate ApiResponse authenticationResponse = service.authenticate(username, password); String token = authenticationResponse.getMessage(); // Customer credentials String customerEmail = "[email protected]"; String customerPassword = "fourscoreand7"; // Call the web service to log the customer in CustomerLoginResponse loginResponse = service.login(token, customerEmail, customerPassword); // Check if the login succeeded if (loginResponse.isSuccess()) { // Customer details are correct and customer has been validated. System.out.println(loginResponse.getCustomer().getID()); // Output: "61Nw9xiBhidVuBxatswjwQ==" } else { // Incorrect customer login details. The login has failed System.out.println("Failed to log customer in."); }
// Instantiate the web service proxy
ISAMSSingleSignOnAPI service = new ISAMSSingleSignOnAPI();
// User to authenticate with
String username = "Testing";
// Corresponding password to authenticate with
String password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.authenticate(username, password);
String token = authenticationResponse.getMessage();
// An encrypted customer ID is required to retrieve a customer's details. This
// is obtained through the Create() or Login() methods.
String customerID = "qLOi5H8lZ5YiUIBCh0Nh2A==";
// Retrieve customer data from the web service
CustomerLoginResponse retrieveResponse =
service.retrieve(token, customerID);
// Process the retrieved customer details
LoginCustomer retrievedCustomer = retrieveResponse.getCustomer();
if (retrieveResponse.isSuccess()) {
System.out.printf("Email: %s", retrievedCustomer.getEmail());
System.out.printf("FirstName: %s", retrievedCustomer.getFirstName());
for (String interestGroup : retrievedCustomer.getInterestGroups()) {
System.out.printf(interestGroup);
}
} else {
System.out.printf("Failed to retrieve customer: %s.", customerID);
}
// Instantiate the web service proxy
ISAMSSingleSignOnAPI service = new ISAMSSingleSignOnAPI();
// User to authenticate with
String username = "Testing";
// Corresponding password to authenticate with
String password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.authenticate(username, password);
String token = authenticationResponse.getMessage();
// An encrypted customer ID is required to subscribe a customer to an
// interest group. This is obtained through the Create() or Login() methods
String customerID = "LlxPGvjw94VwY102vJW2nA==";
// Call web service to subscribe the customer to an interest group
CustomerLoginResponse response =
service.subscribe(token, customerID, "Amendments");
// Check for success and process result
if (response.isSuccess()) {
for (String interest : response.getCustomer().getInterestGroups()) {
System.out.println(interest);
}
} else {
System.out.println("Failed to subscribe to interest group.");
}
// Instantiate the web service proxy
ISAMSSingleSignOnAPI service = new ISAMSSingleSignOnAPI();
// User to authenticate with
String username = "Testing";
// Corresponding password to authenticate with
String password = "Sup94zex";
// Authenticate
ApiResponse authenticationResponse = service.authenticate(username, password);
String token = authenticationResponse.getMessage();
// An encrypted customer ID is required to unsubscribe a customer from an
// interest group. This is obtained through the Create() or Login() methods
String customerID = "gp+nkltxJ9tIn3hpj8ft/Q==";
// Call web service to unsubscribe the customer from an interest group
CustomerLoginResponse response =
service.unsubscribe(token, customerID, "Emancipation");
// Check for success and process result
if (response.isSuccess()) {
for (String interest : response.getCustomer().getInterestGroups()) {
System.out.println(interest);
}
} else {
System.out.println("Failed to unsubscribe from interest group.");
}