CyberArk Identity Java SDK User Management Quick Start Guide

Before you get started

Before you begin this guide, make sure you have the following:

  • CyberArk Identity Tenant
    • To start fresh, create your own CyberArk Free Trial account.
  • CyberArk Identity Java SDK library can be obtained from the downloaded GitHub repository with the path ./spring-boot/libs/Authorization-1.0-SNAPSHOT.jar
    • Add the jar file dependency in your project pom.xml file.
<dependency>
			<groupId>com.cyberark.identity</groupId>
			<artifactId>OIDC</artifactId>
			<scope>system</scope>
			<version>1.0-SNAPSHOT</version>
			<systemPath>${project.basedir}/libs/Authorization-1.0-SNAPSHOT.jar</systemPath>
</dependency>

Introduction

This SDK provides an integration with CyberArk Identity User Management which brings the ease of managing users.

Configure User Management Instance

  • Import the SDK as specified in the Before you get started section
  • Create UserManagement object instance by providing the CyberArk Identity Application URL.
// import
import com.cyberark.client.UserManagement;

UserManagement userMgmt = new UserManagement(tenantURL);
  • After the userMgmt instance is created, you can follow any one of these based on the application use case:
    • Sign-up with Captcha - In this approach, the user sends google re-captcha token for the verification.
    • Sign-up with Bearer Token - In this approach, the user sends bearer token generated through OAuth client credentials flow.
    • Update user profile - It helps to update user profile in the user directory.

References

For more information on the SDK, follow the reference guide CyberArk Identity Java SDK reference.

Sign-up with Captcha

Creates a Sign-up request to create user in the CyberArk Identity cloud directory by passing Google Re Captcha Token for verification.

try {
      SignUpResponse result = userManagement.signUpWithCaptcha("YOUR_RECAPTCHA_TOKEN")
          .setUserName("sample user")
          .setDisplayName("sample username")
          .setPassword("xxxxxx")
          .setEmail("[email protected]")
          .setMobileNumber("xxxx")
          .execute();
 } catch (IdentityException e) {
      //Something happened
 }
{
   "Result":{
      "RoleIntegrationResult":{
         "success":true,
         "Message":"The role xxxxxxx is assigned to the user."
      },
      "UserId":"xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx",
      "ConsentIntegrationResult":{
         "IsIntegrationResponseReceived":true,
         "IntegrationResponse":{
            "Receipt":"-pM1-iVFKGeAztyGf-DpFQBKSGKjd_GG4oML5IFslPgtIc3sKQ"
         }
      }
   },
   "success":true
}

Sign-up with Bearer Token

Creates a Sign-up request using Bearer Token as Authorization header.

try {
     Map<String, Object> attributes = new HashMap<>();
     attributes.put("Mail", "YOUR_EMAIL");
     attributes.put("MobileNumber", "YOUR_MOBILE_NUMBER");
     attributes.put("DisplayName", "user display name");

     SignUpResponse result = userManagement.signUpWithBearerToken("YOUR_BEARER_TOKEN")
         .setPassword("xxxxxx")
         .setEmail("[email protected]")
         .setAdditionalAttributes(attributes)
         .execute();
} catch (IdentityException e) {
     //Something happened
}
{
   "Result":{
      "RoleIntegrationResult":{
         "success":true,
         "Message":"The role xxxxxxx is assigned to the user."
      },
      "UserId":"xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx",
      "ConsentIntegrationResult":{
         "IsIntegrationResponseReceived":true,
         "IntegrationResponse":{
            "Receipt":"-pM1-iVFKGeAztyGf-DpFQBKSGKjd_GG4oML5IFslPgtIc3sKQ"
         }
      }
   },
   "success":true
}

Following the above steps, you should be able to create users into your application.

Update user profile

The modified user details will be updated using this method by passing Bearer Token as Authorization header and user attributes in a java.util.Map.

try {
     Map<String, Object> attributes = new HashMap<>();
     attributes.put("Mail", "YOUR_EMAIL");
     attributes.put("MobileNumber", "YOUR_MOBILE_NUMBER");
     attributes.put("DisplayName", "YOUR DISPLAY NAME");
     SignUpResponse signUpResponse = userManagement.updateProfile("YOUR_BEARER_TOKEN", userJson).execute();
} catch (IdentityException e) {
     //Something happened
}