Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
// Add the username
context.token.addAttribute("name", context.session.username);
// Add each group - will end up as an array of string in the token.
if (context.session.userGroups != null) {
  for(int i = 0; i < context.session.userGroups.length; i++) {
	context.token.addAttribute("group", context.session.userGroups[i]);
  }
}

Creating

...

New Tokens Programmatically

To create a new token, call:

Code Block
JSONObject json = new JSONObject();
json.put("tokenname", "liberty1");
json.put("additionalattribute", "available to the create script");

String result = Agent.getInstance().newToken(sessionId, json.toString()); // result is now a JSON string with two attributes; token and expiration

JSONObject resultObject = new JSONObject(result);
String generatedToken = resultObject.get("token");
long expiresAt = resultObject.get("expiration"); // Time this expires at, in milliseconds since 1/1 1970, GMT.

Programmatically

...

Authenticating Using a

...

Token

Normally, you would use theĀ Ceptor Gateway and configure the LTPA Authentication plugin (seeĀ Location - Authentication ) but to do it programmatically, you can call this:

...