Custom Data is one of the standout features of Stormpath’s authentication and user management API. It allows you to store up to 10 megabytes of unstructured (JSON) data alongside any Stormpath resource. This can be any manner of application-specific user data; our clients use it for everything from custom profile fields to authorization roles, or even references to external data.

Custom Data is backed by a custom-bult microservices architecture that indexes every data element you store on an Account. This makes searching that data blazingly fast. The typical processing time is less than 50 milliseconds, even under load.

Custom Data in Java

The Stormpath Java SDK provides rich support for the Stormpath REST API, and the Custom Data feature is no exception. In this post, I’ll show you how to use the Java SDK to store and search user profile data with a few simple lines of code!

Start off by following the Java quickstart to get a sample application connected to Stormpath.

Storing and Updating Custom Data

When you create (or update) an Account, use the CustomData property to add any data you want to the Account:

If you want to remove some previously-stored data, you can use the Remove method:

Retrieving Custom Data

Getting the Custom Data for an Account is easy. If you’ve already retrieved the Account, use the getCustomData method to grab the Custom Data:

In order to perform queries, you’ll need to know your Stormpath Directory href. You can find this by logging into the Stormpath Admin Console and finding the Application you created in the Quickstart:

Custom Data Search for .NET

Click on Account Stores on the left side and open up the Directory that was created for the Application. The href is displayed on the page:

Custom Data Search in .NET

In your code, you can retrieve the Directory resource using the Java SDK:

Now that you have a reference to the Directory, you can create queries that search the Accounts in that Directory. As a refresher, you can query against any of the built-in Account fields:

There’s another form that a search can take that uses a map of query params:

Searching against a value saved in Custom Data is similarly easy, although currently it is only supported in the map form of search:

Note that string matching is case-insensitive in the Stormpath API, so the case of the search term doesn’t matter.

There’s a lot more you can do with Custom Data in Stormpath! We have full feature documentation available in our Product Guide.

What about my Spring Boot applications?

While these examples focused on the Stormpath Java SDK, the same objects and features are available in the official Stormpath Spring Boot integration packages!

You can get access to the Stormpath Client through autowiring: @Autowired Client client to access the relevant Stormpath SDK objects from inside a controller. There are a number of examples to get you started in the Spring Boot Tutorial documentation.

Questions? Leave a comment here, or hit me up on Twitter @afitnerd!