OpenWGA 7.0 - OpenWGA Concepts and Features

Design and development » Service APIs

Retrieving a service API

You can retrieve service API objects from TMLScript or from the OpenWGA Server API.

In TMLScript use method WGA.service() which directly returns a service object. You need to give the Java interface of the service as parameter, which you reference in TMLScript via the "Packages" global object (see Accessing Java and the WGAPI to learn why). For example, retrieving the service API for looking up hashing passwords whose service API interface is "de.innovationgate.utils.security.HashingService":

var hashingService = WGA.service(Packages.de.innovationgate.utils.security.HashingService);

The returned object is a Java object which extends/implements the service class given. You can call its methods, again using the techniques described in Accessing Java and the WGAPI

For example to hash a password using interface de.innovationgate.utils.security.HashingService you need first to call method generateSalt() to create a salt and then call createHash() on the bytes of the password string plus the salt to create the hash. This can be done the following way in TMLScript:

var salt = hashingService.generateSalt();

var hashedPwd = hashingService.createHash(javaObject(password).getBytes("UTF-8"), salt);


In Java you have the object de.innovationgate.wga.server.api.WGA of the OpenWGA Server API which has an identical method service(). Here it looks almost equal:

import de.innovationgate.utils.security.HashingService;

import de.innovationgate.wga.server.api.WGA;

import de.innovationgate.webgate.api.WGException;

import de.innovationgate.utils.security.HashingException;

import java.io.UnsupportedEncodingException;


...


public String hashPassword(String password) throws WGException, HashingException, UnsupportedEncodingException {

  WGA wga = WGA.get();

  HashingService hashingService = wga.service(HashingService.class);

  Object salt = hashingService.generateSalt();

  return hashingService.createHash(password.getBytes("UTF-8"), salt);

}