Like what you see? Have a play with our trial version.

Error rendering macro 'rw-search'

null

Versions Compared

Key

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

Yellowfin supports a multi-tenant structure through the creation of Client Organizations. You can read about Client Organizations here.

A common integration scenario is to create new clients programmatically. This could be valid in a SaaS scenario where a new client has been onboarded.  The specific code that handles this in the host application could be modified to also create a corresponding Yellowfin Client Organization at the same time. 

...

A new Client Organization can be created using the POST /api/orgs end-pointCreate Org. This end-point accepts the following payload:

Code Block
{

  "clientRefId": "CLIENT5",

  "name": "Client 5",

  "defaultTimezone": "AUSTRALIA/SYDNEY",

  "customStylePath": "client5stylePath"

}

The clientRefId attribute is the primary identifier for the new tenant. The name attribute is the display name for the new tenant. The defaultTimezone attribute specifies the timezone for the new tenant, but this is not mandatory. A tenant will inherit the primary organization’s timezone if this is not set. The customStylePath defines a directory where custom styles and images will be stored for this tenant. This is not mandatory.

The following code examples create a new Client Organization:.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;
import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
 * Create a new Client Organization using the Yellowfin REST API
 */
public class CreateClientOrg {
    public static void main(String[] args) throws Exception {

        String host = ""http://localhost:8080/Yellowfin"";
        String restUsername = ""admin@yellowfin.com.au"";
        String restPassword = ""test"";

        String newTenantName = ""New Client"";
        String newTenantCode = ""NEWCLIENT"";

        String token = generateToken(host, restUsername, restPassword);

        String createTenantPayload =
                ""{"" +
                        ""  \""clientRefId\"": \"""" + newTenantCode + ""\"","" +
                        ""  \""name\"": \"""" + newTenantName + ""\"","" +
                        ""  \""defaultTimezone\"": \""AUSTRALIA/SYDNEY\"","" +
                        ""  \""customStylePath\"": \""newClientStylePath\"" "" +
                        ""}"";

        System.out.println(""Payload: "" + createTenantPayload);

        Content c = Request.post(host + ""/api/orgs"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(createTenantPayload, null)
                .execute().returnContent();

        System.out.print(c.asString());

    }



    /*
     *  This function generates an access token for a user that will grant them access to
     *  call REST API endpoints.
     */

    public static String generateToken(String host, String username, String password) throws IOException {

        Content c = Request.post(host + ""/api/refresh-tokens"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");

        if (accessToken!=null) {
            System.out.println(""Access Token: "" + accessToken);
        } else {
            System.out.println(""Token not retrieved successfully"");
            System.exit(-1);
        }
        return accessToken.getAsString();

    }

}

...

These examples list all tenants from the Yellowfin instance:.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;
import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
 * List Client Organizations using the Yellowfin REST API
 */
public class ListClientOrgs {
    public static void main(String[] args) throws Exception {

        String host = ""http://localhost:8080/Yellowfin"";
        String restUsername = ""admin@yellowfin.com.au"";
        String restPassword = ""test"";

        String token = generateToken(host, restUsername, restPassword);

        Content c = Request.get(host + ""/api/orgs"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        System.out.print(c.asString());

    }


    /*
     *  This function generates an access token for a user that will grant them access to
     *  call REST API endpoints.
     */

    public static String generateToken(String host, String username, String password) throws IOException {

        Content c = Request.post(host + ""/api/refresh-tokens"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");

        if (accessToken!=null) {
            System.out.println(""Access Token: "" + accessToken);
        } else {
            System.out.println(""Token not retrieved successfully"");
            System.exit(-1);
        }
        return accessToken.getAsString();

    }

}

...

The required payload for the POST /api/orgs/{tenantId}/user-access end-point is:

Code Block
{

   "userId": {userIpId}

}

Where {userIpId} is the integer identifier for a user.

The following code examples grant access to a client organization (identified by its clientOrgRef code) to a user (identified by their username):.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;
import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
 * Add a User access to a Tenant using the Yellowfin REST API
 */
public class AddUserToClientOrg {
    public static void main(String[] args) throws Exception {

        System.out.print(""Add a User to a Tenant"");

        String host = ""http://localhost:8080/Yellowfin"";
        String restUsername = ""admin@yellowfin.com.au"";
        String restPassword = ""test"";

        String usernameOfUserToAddtoTenant = ""user1@yellowfin.com.au"";
        String tenantClientReferenceId = ""NEWCLIENT"";

        String token = generateToken(host, restUsername, restPassword);

        Integer tenantId = retrieveTenantIpIdForTenantName(host, token, tenantClientReferenceId);
        Integer userIpId = retrieveUserIpIdForUsername(host, token, usernameOfUserToAddtoTenant);

        String addUserToClientPayload = "" { \""userId\"": "" + userIpId + "" }"";

        System.out.println(""Tenant Id: "" + tenantId);
        System.out.println(""User IpId: "" + userIpId);
        System.out.println(""PayLoad: "" + addUserToClientPayload);

        Content c = Request.post(host + ""/api/orgs/"" + tenantId + ""/user-access"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(addUserToClientPayload, null)
                .execute().returnContent();

        System.out.print(c.asString());

    }
    /*
     *  This function fetches a user's integer id for a given username
     */

    public static Integer retrieveUserIpIdForUsername(String host, String token, String userName) throws IOException {

        Content c = Request.get(host + ""/api/rpc/users/user-details-by-username/"" + userName)
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong()+ "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement userIpJsonAttribute = jsonObject.get(""userId"");
        Integer userIpId = userIpJsonAttribute.getAsInt();

        return userIpId;

    }

    /*
     *  This function fetches a client organization's integer id for a given clientRefCode
     */

    public static Integer retrieveTenantIpIdForTenantName(String host, String token, String tenantCode) throws IOException {

        Content c = Request.get(host + ""/api/orgs"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement tenantList = jsonObject.get(""items"");
        JsonArray tenants = tenantList.getAsJsonArray();

        for (int i=0; i < tenants.size(); i++ ) {
            JsonObject tenant = tenants.getAsJsonArray().get(i).getAsJsonObject();
            if (!tenant.has(""clientRefId"")) continue;
            if (tenantCode.equals(tenant.get(""clientRefId"").getAsString())) return tenant.get(""ipOrg"").getAsInt();
        }

        System.out.println(""Tenant could not be found for code:"" + tenantCode);
        System.exit(-1);

        return null;
    }


    /*
     *  This function generates an access token for a user that will grant them access to
     *  call REST API endpoints.
     */

    public static String generateToken(String host, String username, String password) throws IOException {

        Content c = Request.post(host + ""/api/refresh-tokens"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");

        if (accessToken!=null) {
            System.out.println(""Access Token: "" + accessToken);
        } else {
            System.out.println(""Token not retrieved successfully"");
            System.exit(-1);
        }
        return accessToken.getAsString();

    }

}

...

The following code examples revoke access from a client organization (identified by its clientOrgRef code) for a user (identified by their username):.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;
import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
 * Add a User access to a Tenant using the Yellowfin REST API
 */
public class RemoveUserFromClientOrg {
    public static void main(String[] args) throws Exception {

        System.out.print(""Revoke Access to Tenant for User"");

        String host = ""http://localhost:8080/Yellowfin"";
        String restUsername = ""admin@yellowfin.com.au"";
        String restPassword = ""test"";

        String usernameOfUserToRemoveFromTenant = ""user1@yellowfin.com.au"";
        String tenantClientReferenceId = ""NEWCLIENT"";

        String token = generateToken(host, restUsername, restPassword);

        Integer tenantId = retrieveTenantIpIdForTenantName(host, token, tenantClientReferenceId);
        Integer userIpId = retrieveUserIpIdForUsername(host, token, usernameOfUserToRemoveFromTenant);


        System.out.println(""Tenant Id: "" + tenantId);
        System.out.println(""User IpId: "" + userIpId);

        Content c = Request.delete(host + ""/api/orgs/"" + tenantId + ""/user-access/"" + userIpId)
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        System.out.print(c.asString());

    }
    /*
     *  This function fetches a user's integer id for a given username
     */

    public static Integer retrieveUserIpIdForUsername(String host, String token, String userName) throws IOException {

        Content c = Request.get(host + ""/api/rpc/users/user-details-by-username/"" + userName)
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong()+ "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement userIpJsonAttribute = jsonObject.get(""userId"");
        Integer userIpId = userIpJsonAttribute.getAsInt();

        return userIpId;

    }

    /*
     *  This function fetches a client organization's integer id for a given clientRefCode
     */

    public static Integer retrieveTenantIpIdForTenantName(String host, String token, String tenantCode) throws IOException {

        Content c = Request.get(host + ""/api/orgs"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement groupList = jsonObject.get(""items"");
        JsonArray groups = groupList.getAsJsonArray();

        for (int i=0; i < groups.size(); i++ ) {
            JsonObject group = groups.getAsJsonArray().get(i).getAsJsonObject();
            if (!group.has(""clientRefId"")) continue;
            if (tenantCode.equals(group.get(""clientRefId"").getAsString())) return group.get(""ipOrg"").getAsInt();
        }

        System.out.println(""Tenant could not be found for code:"" + tenantCode);
        System.exit(-1);

        return null;
    }


    /*
     *  This function generates an access token for a user that will grant them access to
     *  call REST API endpoints.
     */

    public static String generateToken(String host, String username, String password) throws IOException {

        Content c = Request.post(host + ""/api/refresh-tokens"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");

        if (accessToken!=null) {
            System.out.println(""Access Token: "" + accessToken);
        } else {
            System.out.println(""Token not retrieved successfully"");
            System.exit(-1);
        }
        return accessToken.getAsString();

    }

}

...

The following code examples list the users who have access to a specific client organization (identified by its clientOrgRef code):.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;


import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
* List Users who have access to a Tenant using the Yellowfin REST API
*/
public class ListUserAccessToClientOrg {
   public static void main(String[] args) throws Exception {
     
     	System.out.print(""List Users who have Access to Tenant"");
   	
	    	String host = ""http://localhost/yellowfinHead"";
	    	String restUsername = ""admin@yellowfin.com.au"";
	    	String restPassword = ""test"";
	    	
	    	String tenantClientReferenceId = ""NEWCLIENT"";
	    	
	    	String token = generateToken(host, restUsername, restPassword);
		    	
	    	Integer tenantId = retrieveTenantIpIdForTenantName(host, token, tenantClientReferenceId);
	    	System.out.println(""Tenant Id: "" + tenantId);
	    	
	    	Content c = Request.get(host + ""/api/orgs/"" + tenantId + ""/user-access"")
	  	    		.addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
	  	    		.addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
	  	    		.addHeader(""Content-Type"", ""application/json"")
	  	        .execute().returnContent();
	  	    	
   	    JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
   	    JsonElement userList = jsonObject.get(""items"");
	    JsonArray users = userList.getAsJsonArray();
	   
	    System.out.println(users.size() + "" user(s) have access to tenant "" + tenantClientReferenceId);
	   
	    for (int i=0; i < users.size(); i++ ) {
	    		JsonObject user = users.getAsJsonArray().get(i).getAsJsonObject();
	    		System.out.println(""User "" + user.get(""userId"").getAsInt() + "": "" + user.get(""name"").getAsString());
	    }
	   
   }
   /*
    *  This function fetches a client organization's integer id for a given clientRefCode
    */
  
   public static Integer retrieveTenantIpIdForTenantName(String host, String token, String tenantCode) throws IOException {
   	
     	Content c = Request.get(host + ""/api/orgs"")
 	    		.addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
 	    		.addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
 	    		.addHeader(""Content-Type"", ""application/json"")
 	        .execute().returnContent();
 	    	
   	    JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
   	    JsonElement groupList = jsonObject.get(""items"");
	    JsonArray groups = groupList.getAsJsonArray();
	   
	    for (int i=0; i < groups.size(); i++ ) {
	    		JsonObject group = groups.getAsJsonArray().get(i).getAsJsonObject();
	    		if (!group.has(""clientRefId"")) continue;
	    		if (tenantCode.equals(group.get(""clientRefId"").getAsString())) return group.get(""ipOrg"").getAsInt();
	    }
	   
	   System.out.println(""Tenant could not be found for code:"" + tenantCode);
	   System.exit(-1);
	
	   return null;
   }
  
  
   /*
    *  This function generates an access token for a user that will grant them access to
    *  call REST API endpoints.
    */
  
   public static String generateToken(String host, String username, String password) throws IOException {
   	
   	  	Content c = Request.post(host + ""/api/refresh-tokens"")
 	    		.addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
 	    		.addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
 	    		.addHeader(""Content-Type"", ""application/json"")
 	    		.bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
 	        .execute().returnContent();
 	    	
 	    JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
 	    JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");
 	   
 	    if (accessToken!=null) {
 	    		System.out.println(""Access Token: "" + accessToken);
 	    } else {
 	    		System.out.println(""Token not retrieved successfully"");
 	    		System.exit(-1);
 	    }
 	    return accessToken.getAsString();
   	
   } 
}

...

The following code examples delete a specific client organization (identified by its clientOrgRef code):.

Code Block
languagejava
titleJava
collapsetrue
package rest.code.examples;
import java.io.IOException;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
 * Delete a Client Org using the Yellowfin REST API
 */
public class DeleteClientOrg {
    public static void main(String[] args) throws Exception {

        System.out.print(""Delete a Tenant"");

        String host = ""http://localhost:8080/Yellowfin"";
        String restUsername = ""admin@yellowfin.com.au"";
        String restPassword = ""test"";

        String tenantClientReferenceId = ""NEWCLIENT"";

        String token = generateToken(host, restUsername, restPassword);

        Integer tenantId = retrieveTenantIpIdForTenantName(host, token, tenantClientReferenceId);

        System.out.println(""Tenant Id: "" + tenantId);

        Content c = Request.delete(host + ""/api/orgs/"" + tenantId)
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        System.out.print(c.asString());

    }

    /*
     *  This function fetches a client organization's integer id for a given clientRefCode
     */

    public static Integer retrieveTenantIpIdForTenantName(String host, String token, String tenantCode) throws IOException {

        Content c = Request.get(host + ""/api/orgs"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong() + "", token="" + token)
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement groupList = jsonObject.get(""items"");
        JsonArray groups = groupList.getAsJsonArray();

        for (int i=0; i < groups.size(); i++ ) {
            JsonObject group = groups.getAsJsonArray().get(i).getAsJsonObject();
            if (!group.has(""clientRefId"")) continue;
            if (tenantCode.equals(group.get(""clientRefId"").getAsString())) return group.get(""ipOrg"").getAsInt();
        }

        System.out.println(""Tenant could not be found for code:"" + tenantCode);
        System.exit(-1);

        return null;
    }


    /*
     *  This function generates an access token for a user that will grant them access to
     *  call REST API endpoints.
     */

    public static String generateToken(String host, String username, String password) throws IOException {

        Content c = Request.post(host + ""/api/refresh-tokens"")
                .addHeader(""Authorization"", ""YELLOWFIN ts="" + System.currentTimeMillis() + "" , nonce="" + new Random().nextLong())
                .addHeader(""Accept"", ""application/vnd.yellowfin.api-v1+json"")
                .addHeader(""Content-Type"", ""application/json"")
                .bodyString(""{ \""userName\"": \""""+ username + ""\"",\""password\"": \""""+ password + ""\""}"", null)
                .execute().returnContent();

        JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
        JsonElement accessToken = jsonObject.getAsJsonObject(""_embedded"").getAsJsonObject(""accessToken"").get(""securityToken"");

        if (accessToken!=null) {
            System.out.println(""Access Token: "" + accessToken);
        } else {
            System.out.println(""Token not retrieved successfully"");
            System.exit(-1);
        }
        return accessToken.getAsString();

    }

}

...