If you've already followed the Getting Started With Okta document from Stormpath then you should already have a Spring Boot application where users can login.
However if you try to interogate the system e.g. for all accounts you'll quickly find out that most of the methods provided by Application, such as getAccounts(), throw UnsupportedOperationException.
Another way to get at this data is via the Okta Java SDK.
By default this SDK uses a different mechanism to pickup the Okta API token etc. to the one used by the Okta compatible version of the Stormpath Spring Boot SDK.
The rest of this short gist covers pulling in the necessary Okta Java SDK dependencies and then configuring it using the values that are already available if you've gotten the Stormpath spring-boot-default example up and running against Okta.
For the spring-boot-default example you needed to setup the following environment variables:
STORMPATH_CLIENT_BASEURLOKTA_APPLICATION_IDOKTA_API_TOKEN
You can also set these values via your application.properties as stormpath.client.baseUrl, okta.application.id and okta.api.token respectively.
Either way we will access the Okta API token and the base URL values below in order to create an Okta Client instance.
First you need to add the following in the <properties> section of your pom:
<okta.version>0.6.0</okta.version>
Where 0.6.0 is the latest Okta SDK version on Maven Central.
Then in the dependencies> section add:
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-api</artifactId>
<version>${okta.version}</version>
</dependency>
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-impl</artifactId>
<version>${okta.version}</version>
</dependency>
<dependency>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-httpclient</artifactId>
<version>${okta.version}</version>
<scope>runtime</scope>
</dependency>
Note: the dependencies section of the Okta SDK README suggests adding the okta-sdk-impl with scope runtime. However later we need the okta-sdk-impl class DefaultClientBuilder at compile time in order to build an Okta Client instance with the properties that are already available to us via Spring from the existing Stormpath Okta setup.
Then in your bean creation logic you can create an Okta Client instance like so:
@Bean
Client client(@Value("${okta.api.token}") String apiToken, @Value("${stormpath.client.baseUrl}") String baseUrl) {
DefaultClientBuilder builder = new DefaultClientBuilder();
builder.setClientCredentials(new TokenClientCredentials(apiToken));
builder.setBaseUrlResolver(new DefaultBaseUrlResolver(baseUrl));
return builder.build();
}
Then wherever you need this instance you can autowire it like so:
@Autowired
private Client client;
And then use it like so in your code to e.g. retrieve all users:
for (User user : client.listUsers()) {
System.err.println(user);
}