Java Client

From Swivel Knowledgebase
Jump to: navigation, search


Introduction

This document describes the Swivel client library for Java applications.

The current version of the client library can be downloaded from here.


Using the Library

Full documentation of the library is ongoing. Meanwhile, here are some examples of using the library:


Requesting a TURing image

The following code snippet will return a random security string as a TURing image:

       PINsafeRequest req = new PINsafeRequest("https://swivel:8443/proxy");
       req.singleChannelImageByUsername("user");
       if (req.send()) {
       	byte[] imageBytes = req.getResponseBytes();
       	// imageBytes returns the TURing image as a JPG,
       	// or if animation is enabled, an animated GIF.
       }

Requesting a Dual Channel Message

The following code snippet will request a security string to be sent to the user's designated device:

       PINsafeRequest req = new PINsafeRequest("https://swivel:8443/proxy");
       req.dualChannelMessageByUsername("user");
       if (req.send()) {
       	byte[] confirmBytes = req.getResponseBytes();
       	// imageBytes returns the confirmation image as a JPG.
       	// This is only required if you wish to display this to the user.
       }


Authenticating a User

The following code snippet will authenticate a user given the username and one-time code. It is assumed that the user has no Swivel password. If Swivel passwords are used, specify the entered password as the second argument to the login method. The authentication URL must be to pinsafe on port 8080.

       // The first argument to the constructor is the PINsafe URL.
       // The second argument is the agent secret.
       AgentXmlRequest req = new AgentXmlRequest("https://swivel:8080/pinsafe", "secret");
       // setIgnoreSSLErrors(true) will ignore SSL certificate errors.
       req.setIgnoreSSLErrors(true);
       req.login(user, "", otc);
       if (req.send()) {
       	boolean authenticated = req.actionSucceeded();
       }