Service Management

Creating a Service

To create a Service Profile, you will need to invoke the createService method. The createService method takes five arguments which are the name, description, icon image URL, webhook callback URL, and the active flag. It returns a UUID which will be the Service ID for all further interactions regarding the Service that was just created.

Example:

UUID id;
try {
    id = client.createService("My Unique Service Name", "My Service Description",
    URI.create("https://my.com/icon.png"), URI.create("https://my.com/launchkey-callback"), true);
}
catch(BaseException e) {
    //error handling
}

Get a Service

To get a single Service Profile, you will need to invoke the getService method. The getService method takes a single argument which is the Service ID.

Example:

Service service;
try {
    service = client.getService(serviceId);
}
catch(BaseException e) {
    //error handling
}
System.out.println("  " + service.getId() + ":");
System.out.println("    Name:    " + session.getName());
System.out.println("    Desc:    " + session.getDescription());
System.out.println("    Icon:    " + session.getIcon());
System.out.println("    Created: " + session.getCallbackURL());
System.out.println("    Active:  " + session.isActive());

Get All Services

To get a list of all Service Profile items, you will need to invoke the getAllServices method. The getAllServices method does not takes any arguments.

Example:

List<Service> services;
try {
    services = client.getAllServices();
}
catch(BaseException e) {
    //error handling
}

for (Service service : services) {
    System.out.println("  " + service.getId() + ":");
    System.out.println("    Name:    " + session.getName());
    System.out.println("    Desc:    " + session.getDescription());
    System.out.println("    Icon:    " + session.getIcon());
    System.out.println("    Created: " + session.getCallbackURL());
    System.out.println("    Active:  " + session.isActive());
}

Get a List of Services

To get a list of specific Service Profile items, you will need to invoke the getServices method. The getServices method takes a single argument which is a list of Service IDs.

Example:

List<Service> services;
try {
    services = client.getServices(serviceIds);
}
catch(BaseException e) {
    //error handling
}

for (Service service : services) {
    System.out.println("  " + service.getId() + ":");
    System.out.println("    Name:    " + session.getName());
    System.out.println("    Desc:    " + session.getDescription());
    System.out.println("    Icon:    " + session.getIcon());
    System.out.println("    Created: " + session.getCallbackURL());
    System.out.println("    Active:  " + session.isActive());
}

Updating a Service

To update a Service Profile items, you will need to invoke the updateService method. The updateService method takes five arguments which are the Service ID, description, icon image URL, webhook callback URL, and the active flag. It has no return.

Example:

try {
    client.updateService(serviceId, "My Service Description",
    URI.create("https://my.com/icon.png"), URI.create("https://my.com/launchkey-callback"), true);
}
catch(BaseException e) {
    //error handling
}

Removing a Service

A Service cannot be removed via the LaunchKey API. You can update the Service to be inactive via the LaunchKey API. However, the only way to remove a Service is via the Admin Center.

Pubic Key Management

Add a Public Key

To add a Pubic Key to a Service Profile, you will need to invoke the addServicePublicKey method. The addServicePublicKey method takes four arguments which are the Service ID, Public Key, active flag, and the date in which the public key will expire. It returns a Key ID which will be Key ID for all further interactions regarding the Public Key that was just created.

Note

Supplying null for the expiration date will prevent the Public Key from expiring.

Update a Public Key

To update a Pubic Key for a Service Profile, you will need to invoke the updateServicePublicKey method. The updateServicePublicKey method takes four arguments which are the Service ID, Key ID, active flag, and the date in which the public key will expire. It returns no value.

Example:

try {
    client.updateServicePublicKey(serviceId, KeyId, false, null);
}
catch(BaseException e) {
    //error handling
}

Remove a Public Key

To remove a Pubic Key from a Service Profile, you will need to invoke the removeServicePublicKey method. The removeServicePublicKey method takes two arguments which are the Service ID and Key ID. It returns no value.

Note

Every entity must have at least one Public Key. As such, you cannot remove the last Public Key for an entity. However, you can deactivate any Public Key by setting the active flag to false.

Example:

try {
    client.removeServicePublicKey(serviceId, KeyId);
}
catch(BaseException e) {
    //error handling
}

Policy Management

Creating a Policy Object

A Policy can be based on a number of authorization factors or by requiring individual types of authorization factors. Examples of various scenarios follow.

Require a Number of Authorization Factors:

ServicePolicy policy = new ServicePolicy(2, null);

Require Specific Authorization Factors (Knowledge and Inherence) and JailBreak protection:

boolean requireKnowledge = true;
boolean requireInherence = true;
boolean requirePossession = false;
boolean jailbreakProtection = true;

ServicePolicy policy = new ServicePolicy(requireKnowledge, requireInherence, requirePossession, jailbreakProtection);

Add locations to the policy:

ServicePolicy policy = new ServicePolicy(2, null);
policy.addLocations(Arrays.asList(
    new ServicePolicy.Location("Portland", 1000.0, 45.522187, -122.676291),
    new ServicePolicy.Location("Las Vegas", 500.0, 36.120779,  -115.156437)
));

Add time fences to the policy:

ServicePolicy policy = new ServicePolicy(2, null);
policy.addTimeFences(Arrays.asList(
    new ServicePolicy.TimeFence(
        "Weekdays 9-5",
        Arrays.asList(DAY.MONDAY, DAY.TUESDAY, DAY.WEDNESDAY, DAY.THURSDAY, DAY.FRIDAY),
        9, 0, 17, 0, TimeZone.getTimeZone("America/Los_Angeles")),
    new ServicePolicy.TimeFence(
        "Weekends 12-4", Arrays.asList(DAY.SATURDAY, DAY.SUNDAY),
        12, 0, 16, 0, TimeZone.getTimeZone("America/Los_Angeles")),
));

Set the Policy

To set the Policy for a Service, you will need to invoke the setServicePolicy method. The setServicePolicy method takes two arguments which are Service ID and Policy. It returns no value.

Example:

try {
    client.setServicePolicy(serviceId, policy);
}
catch(BaseException e) {
    //error handling
}

Get the Policy

To get the Policy for a Service, you will need to invoke the getServicePolicy method. The getServicePolicy method takes one arguments which is the Service ID. It returns the Policy and null if no Policy exists.

Example:

try {
    ServicePolicy policy = client.getServicePolicy(serviceId);
}
catch(BaseException e) {
    //error handling
}
if (policy == null) {
    System.out.println("No policy");
} else {
    System.out.println("Required Factors:     " + policy.getRequiredFactors());
    System.out.println("Inherence Required:   " + policy.isInherenceFactorRequired());
    System.out.println("Knowledge Required:   " + policy.isKnowledgeFactorRequired());
    System.out.println("Possession Required:  " + policy.isPossessionFactorRequired());
    System.out.println("Jailbreak Protection: " + policy.isJailBreakProtectionEnabled());
    System.out.println("Geofence Locations:");
    for (ServicePolicy.Location location : policy.getLocations()) {
        System.out.println("  " + location.getName() + ":");
        System.out.println("    Latitude:  " + location.getLatitude());
        System.out.println("    Longitude: " + location.getLongitude());
        System.out.println("    Radius:    " + location.getRadius());
    }
    System.out.println("Time Fences:");
    for (ServicePolicy.TimeFence timeFence : policy.getTimeFences()) {
        System.out.println("  " + timeFence.getName() + ":");
        System.out.println("    Days:  " + timeFence.getDays());
        System.out.println("    Start: " + timeFence.getStartHour() + ":" + timeFence.getStartMinute());
        System.out.println("    End:   " + timeFence.getEndHour() + ":" + timeFence.getEndMinute());
        System.out.println("    TZ:    " + timeFence.getTimeZone());
    }
}

Remove the Policy

To remove the Policy for a Service, you will need to invoke the removeServicePolicy method. The removeServicePolicy method takes a single arguments which is the Service ID. It returns no value.

Example:

try {
    client.removeServicePolicy(serviceId);
}
catch(BaseException e) {
    //error handling
}

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×