// Get the account requests for the AD application
List accRequest = plan.getAccountRequests(“ACTIVE-DIRETORY-APPLICATION”);
String identityName = plan.getIdentity().getName();
// Defining list to hold the group DNs
List currentADGroups = new ArrayList();
// Add hardcoded group DNs
currentADGroups.add(“CN=Accounting,OU=FID_Groups,OU=FID_DATA,DC=test,DC=com”);
currentADGroups.add(“CN=HR-Dept,OU=FID_Groups,OU=FID_DATA,DC=test,DC=com”);
// Iterateing through all account requests
for (AccountRequest accountRequest : accRequest)
{
// Createing single AttributeRequest to add multiple groups
AttributeRequest groupAttributeRequest = new AttributeRequest("memberOf", Operation.Add, currentADGroups);
// Adding attribute request to the account request
accountRequest.add(groupAttributeRequest);
System.out.println("Added AD groups to user " + identityName + ": " + currentADGroups);
I wanted to share a method that worked for me. I’m currently reading the group from a custom object, just so you’re aware. I modified this code to make it easier to set up in the code as well.
List<String> entitlementList = new ArrayList<>();
entitlementList.add("Group1");
entitlementList.add("Group2");
if (entitlementList != null && !entitlementList.isEmpty()) {
for (String entitlement : entitlementList) {
accountRequestObj.add(new AttributeRequest("memberOf", ProvisioningPlan.Operation.Add, entitlement));
}
}
Hope this helps! let me know how it worked for you.