User Tools

Site Tools


developers:examples:java:client-api-basic

This is an old revision of the document!


Basic authentication example using Java SDK Client API

See all Java Examples

Try it out

Get sources and binaries on GitHub

How to install this example

In the following chapter, typical examples of using the ADUCID® Client API are provided, particularly user authentication.

A typical example of using ADUCID® Client API includes the following steps:

  1. Creating an authentication session in AIM for the requested operation. The redirect URL with identifier authId, and optionally bindingId and/or bindingKey identifiers, is returned. Then sending redirect to provided redirect URL, by which the PEIG authentication handshake is initiated (the AIM-Proxy component can be used for this action).
  2. <font 11.0pt/11;;inherit;;inherit>Returning credentials (authId, authKey) back to the application and verifying credentials supplied from PEIG.</font>

Example of Starting Authentication Session (step 1)

When authenticating a user, an authentication session must first be created on the AIM server. This is done by the startAuthenticationSession operation of the AducidAdvancedClient object. It is necessary to provide a return URL as an operation input parameter. The startAuthenticationSession operation returns URL, where to redirect to start PEIG authentication handshake.

This page starts authentication request. As a parameter of startAuthenticationSession method we provide URL with final page where authentication is evaluated:

public void authenticate(HttpServletResponse response) throws AducidClientException {
  AducidAdvancedClient client = new AducidAdvancedClient("http://localhost:8080/AIM/services/R4");
  String redirectUrl = client.startAuthenticationSession("http://returnToMyApplicationURL");
  response.sendRedirect(redirectUrl);
}

If calling of the startAuthenticationSession is successful, no exception is thrown.

Example of Verifying Authentication Session (step 2)

If authentication has been finished (for example, when the AIM proxy redirects control back to the application, by using the endpoint defined in the returnUrl value that was set in step 1), credentials can be verified by calling the getResult method of the AducidAdvancedClient object. Remember, authKey value doesn't need to be defined, so make it optional as getResult operation input. The getResult operation returns GetPSLAttributesResponse as an object representing authentication data. The most important values are UDI as a unique user identifier (GetPSLAttributesResponse.getUserDatabaseIndex()) and authKey as a new authentication key (GetPSLAttributesResponse.getAuthKey()). If you want to call Client API methods requiring authId and authKey pair on input, you must use that new authentication key instead of the original one.

protected GetPSLAttributesResponse authenticateCheck(String authId, String authKey) throws AducidClientException {
  AducidAdvancedClient client = new AducidAdvancedClient("http://localhost:8080/AIM/services/R4");
  GetPSLAttributesResponse authData = client.getResult(authId, authKey);
  // example of method call with verified authentication key
  List<PersonalObjectAttribute> personalObjectAttributeList = client.read(authData.getAuthId(), authData.getAuthKey(), "ADUCID_USER");
  return authData;
}

If calling of the getResult is successful, no exception is thrown.

developers/examples/java/client-api-basic.1564654431.txt.gz · Last modified: 2019/08/01 10:13 by tjotov