To access user-related information, we have to use an identity-related URL, that is, /identity/users
. Now, we will use the identity service. Perform the following steps to archive the identity service:
createUser
method in the Process_Deployment
class through which we will pass the details of the user as follows:public static JSONObject createUser() throws JSONException, IOException { String uri = REST_URI + "/identity/users"; JSONObject my_data = new JSONObject(); my_data.put("id", "irshad"); my_data.put("firstName", "Irshad"); my_data.put("lastName", "Mansuri"); my_data.put("email", "[email protected]"); my_data.put("password", "irshad"); Representation response = getClientResource(uri).post(my_data); JSONObject object = new JSONObject(response.getText()); if (object != null) { return object; } return null; }
id
for the update. The URL for the update is /identity/users/{userId}
, as shown in the following code:public static JSONObject updateUser(String id) throws JSONException, IOException { String uri = REST_URI + "/identity/users/" + id; JSONObject my_data = new JSONObject(); my_data.put("email", "[email protected]"); Representation response = getClientResource(uri).put(my_data); JSONObject object = new JSONObject(response.getText()); if (object != null) { return object; } return null; }
deleteUser
method. We will add the following method to archive the delete functionality:public static void deleteUser(String id) throws JSONException, IOException { String uri = REST_URI + "/identity/users/" + id; Representation response = getClientResource(uri).delete(MediaType.ALL); }
/identity/groups
.createGroup
method to create a group in the repository, which will contain information regarding the group, as shown in the following code:public static JSONObject createGroup() throws JSONException, IOException { String uri = REST_URI + "/identity/groups"; JSONObject my_data = new JSONObject(); my_data.put("id", "attunegroup"); my_data.put("name", "Attune Group"); my_data.put("type", "security-role"); Representation response = getClientResource(uri).post(my_data); JSONObject object = new JSONObject(response.getText()); if (object != null) { return object; } return null; }
addGroupMember
method where we will provide the group ID as the parameter in which we want to add users, as follows:public static JSONObject addGroupMember(String id) throws JSONException, IOException { String uri = REST_URI + "/identity/groups/" + id + "/members"; JSONObject my_data = new JSONObject(); my_data.put("userId", "irshad"); Representation response = getClientResource(uri).post(my_data); JSONObject object = new JSONObject(response.getText()); if (object != null) { return object; } return null; }
groupID
as well as userId
values that we want to delete, as shown in the following code:public static void deleteGroupMember(String groupId, String userId) throws JSONException, IOException { String uri = REST_URI + "/identity/groups/" + groupId + "/members/" + userId; Representation response = getClientResource(uri).delete(MediaType.ALL); }