Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.
lhazlewood edited this page Aug 13, 2012 · 33 revisions

Stormpath Java SDK

The Stormpath Java SDK allows any JVM-based application to easily use the Stormpath cloud Identity Management service for all authentication and access control needs.

When you make SDK method calls, the calls are translated into HTTPS requests to the Stormpath REST+JSON API. The Stormpath Java SDK therefore provides a clean object-oriented paradigm natural to JVM developers and alleviates the need to know how to make REST+JSON requests. Any JVM-based programming language can use the Stormpath Java SDK (e.g. Java, Groovy, Scala, Clojure, Jython, JRuby, etc.)

Usage

  1. Add the Stormpath Java SDK .jars to your application using Maven, Ant+Ivy, Grails, SBT or whatever Maven Repository-compatible tool you prefer:

     <dependency>
         <groupId>com.stormpath.sdk</groupId>
         <artifactId>stormpath-sdk-api</artifactId>
         <version>0.4.0</version>
     </dependency>
     <dependency>
         <groupId>com.stormpath.sdk</groupId>
         <artifactId>stormpath-sdk-httpclient</artifactId>
         <version>0.4.0</version>
         <scope>runtime</scope>
     </dependency>
    
  2. Ensure you have an API Key so your application can communicate with Stormpath. Store your API Key file somewhere secure (readable only by you), for example:

     /home/myhomedir/.stormpath/apiKey.properties
    

    This file's contents should contain the following name/value pairs (using your own values of course):

     $ cat /home/myhomedir/.stormpath/apiKey.properties
     
     apiKey.id = YOURAPIKEYIDHEREREPLACEME
     apiKey.secret = YoUrReAlLyLongSecretValueHereReplaceMeWithYourValue
    

    Also change the file permissions to ensure only you can read the file:

     $ chmod go-rw /home/myhomedir/.stormpath/apiKey.properties
    
  3. Configure your application to create a Stormpath SDK Client instance based on your API Key. The Client instance is your starting point for all operations with the Stormpath service. For example:

     import com.stormpath.sdk.client.*;
     ...
     
     String path = System.getProperty("user.home") + "/.stormpath/apiKey.properties";
     Client client = new ClientBuilder().setApiKeyFileLocation(path).build();
    
  4. Use the Client instance to interact with your tenant data, such as Applications, Directories, and Accounts:

     Tenant tenant = client.getCurrentTenant();
     
     ApplicationList applications = tenant.getApplications();
     
     for (Application application : applications) {
         System.out.println("Application " + application.getName());
     }
     
     DirectoryList directories = tenant.getDirectories();
     
     for (Directory directory : directories) {
         System.out.println("Directory " + directory.getName());
     }