Add Users To a Group

Adds a batch of users to an existing group in Access Control using an ANSI or UTF-8 encoded CSV file that was uploaded to the environment. Use the Upload REST API to upload the file. The file should be deleted after the API executes. The file format is as follows:

User Login
jdoe
john.doe@example.com

Note: The user is added to the group only if both these conditions are met:

  • User login IDs included in the file exist in the identity domain that services the environment
  • The user is assigned to a pre-defined role in the identity domain

Additionally, the file should not contain the login ID of the user running this command.

This API should be run only by a service administrator in the identity domain where users are to be added to the group.

The API is asynchronous and returns the Job ID. Use the job status URI to determine whether the assignment of users to the group is complete. The presence of status -1 in the response indicates that the addition of users to a group is in progress. Any non-zero status except -1 indicates failure of adding users.

This REST API is version v1.

Table 8-14 Tasks for Add Users to Group

Task Request REST Resource
Add users to group PUT /interop/rest/security/<api_version>/groups
Add users to group status GET /interop/rest/security/<api_version>/jobs/<jobId>

REST Resource

POST /interop/rest/security/<api_version>/groups

Supported Media Types: application/json

Parameters:

The following table summarizes the request parameters.

Table 8-15 Parameters

Name Description Type Required Default
api_version Specific API version Path Yes None
jobtype The string should have the value ADD_USERS_TO_GROUP. This value denotes that the users are being added to the group. Form Yes None
filename

The name of the uploaded ANSI or UTF-8 encoded CSV file containing the users to add, such as addUsersToGroup.csv.

The file must have been uploaded already using the Upload REST API. The CSV file should not include the account of the user who executes this command.

File format example:

User Login
FirstName1.LastName1@email.com 
FirstName2.LastName2
Form Yes None
groupname The name of group to which the users must be added. This group must be a pre-existing group. Form Yes None

Response

Supported Media Types: application/json

Parameters:

Table 8-16 Parameters

Name Description
details In the case of errors, details are published with the error string
status See Migration Status Codes
links Detailed information about the link
href Links to API call or status API
action The HTTP call type
rel Possible values: self or Job Status. If the value is set to Job Status, you can use the href to get the status of the recreate service
data Parameters as key value pairs passed in the request
items Details about the resource
links Details of the first URL to be requested to get the job details; rel is "Job Details"

Examples of Response Body in JSON format.

Example 1, when job is in progress

{
  "links": [
    {
      "rel": "self",
      "href": "https://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/groups",
      "data": {
        "jobType": "ADD_USERS_TO_GROUP",
        "filename": "<fileName>",
        "groupName": "<groupName>",
      },
      "action": "GET"
    },
    {
      "rel": "Job Status",
      "href": "https://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/jobs/<jobId>",
      "data": null,
      "action": "GET"
    }
  ],
  "details": null,
  "status": -1,
  "items": null
}

Example 2, when job completes with errors:

{
  "links": [
    {
      "rel": "self",
      "href": "https://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/jobs/<jobID>",
      "data": null,
      "action": "GET"
    }
  ],
  "details": "Failed to add users to group. File <fileName> is not found. Please provide a valid file name.",
  "status": 1,
  "items": null
}

Example 3, when job completes without errors:

{
  "links": [
    {
      "rel": "self",
      "href": "https://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/jobs/<jobId>",
      "data": null,
      "action": "GET"
    }
  ],
  "details": "Processed - 3, Succeeded - 2, Failed - 1.",
  "status": 0,
  "items": null
}

Example 8-7 Java Sample Code

Prerequisites: json.jar

Common Functions: See: CSS Common Helper Functions for Java

public void addUsersToGroup(String fileName, String groupName) {
		try {
			String url = this.serverUrl + "/interop/rest/security/" + apiVersion + "/groups";
			Map<String, String> reqHeaders = new HashMap<String, String>();
			reqHeaders.put("Authorization", "Basic " + DatatypeConverter
					.printBase64Binary((this.userName + ":" + this.password).getBytes(Charset.defaultCharset())));

			Map<String, String> reqParams = new HashMap<String, String>();
			reqParams.put("filename", fileName);
			reqParams.put("jobtype", "ADD_USERS_TO_GROUP");
			reqParams.put("groupname", groupName);

			Map<String, String> restResult = CSSRESTHelper.callRestApi(new HashMap(), url, reqHeaders, reqParams,
					"PUT");
			String jobStatus = CSSRESTHelper.getCSSRESTJobCompletionStatus(restResult, reqHeaders);
			System.out.println(jobStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Example 8-8 Shell Script Sample Code

Prerequisites: jq (http://stedolan.github.io/jq/download/linux64/jq)

Common Functions: See CSS Common Helper Functions for cURL

funcAddUsersToGroup() {
	url="$SERVER_URL/interop/rest/security/$API_VERSION/groups"
	params="filename=$1&jobtype=ADD_USERS_TO_GROUP&groupname=$2"
	header="Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
	cssRESTAPI="AddUsersToGroup"
	statusMessage=$(funcCSSRESTHelper "PUT" "$url" "$header" "$USERNAME" "$PASSWORD" "$params" "$cssRESTAPI")
	echo $statusMessage
}
Example 8-15 Groovy Sample Code
Common Functions: See CSS Common Helper Functions for Groovy.

def addUsersToGroup(fileName, groupName) {

	String scenario = "Adding users in " + fileName + " to group " + groupName;
	String params = "jobtype=ADD_USERS_TO_GROUP&filename="+ fileName +"&groupname="+ groupName;
	def url = null;
	def response = null;
	try {
		url = new URL(serverUrl + "/interop/rest/security/" + apiVersion + "/groups");
	} catch (MalformedURLException e) {
		println "Please enter a valid URL"
		System.exit(0);
	}
	response = executeRequest(url, "PUT", params, "application/x-www-form-urlencoded");
	if (response != null) {
		getJobStatus(getUrlFromResponse(scenario, response, "Job Status"), "GET");
	}
}

Example 8-9 Groovy Sample Code

Common Functions: See CSS Common Helper Functions for Groovy

def addUsersToGroup(fileName, groupName) {

	String scenario = "Adding users in " + fileName + " to group " + groupName;
	String params = "jobtype=ADD_USERS_TO_GROUP&filename="+ fileName +"&groupname="+ groupName;
	def url = null;
	def response = null;
	try {
		url = new URL(serverUrl + "/interop/rest/security/" + apiVersion + "/groups");
	} catch (MalformedURLException e) {
		println "Please enter a valid URL"
		System.exit(0);
	}
	response = executeRequest(url, "PUT", params, "application/x-www-form-urlencoded");
	if (response != null) {
		getJobStatus(getUrlFromResponse(scenario, response, "Job Status"), "GET");
	}
}