Update 2019
Starting with Adaxes 2019.1, you can use the Create an Active Directory object action in your business rules, scheduled tasks and custom commands. For details, have a look at the following tutorial: https://www.adaxes.com/tutorials_ActiveDirectoryManagement_CreateMultipleAdObjectsInOneOperation.htm.
Original
Hello,
Is there a way to have a business rule create multiple groups or users? I have a security model that creates 4 groups for a new work project. There is a Project Owner group, a Read/Write access group, a Read Only group and a No Access group.
I'd love to be able to add this to the Self Service portal. I would ask for the Project name, then create the 4x groups based on our naming convention. However, the current Business Rules don't allow for creating new objects, users, groups, etc.
Whenever you need to create new objects in Business Rules, you can always resort to PowerShell scripts. To implement the scenario with project groups, you can create a Home Page Action available on the Web Interface home page. When a user clicks on the Action, they will be presented with only 1 field, where they are supposed to enter the project name.
To pass the project name to the script, the Action will store the entered project name in one of attributes of the users' own accounts. A Business Rule triggered after modifying the attribute will create the groups based on the entered project name. To pass the entered project name, you can use one of Adaxes virtual attributes that can store text (string) values, for example, CustomAttributetext1. They are not stored in AD, but can be used the same as any other attributes of AD objects. To implement such a solution, you will need to:
- Create a Home Page Action so that users can input a project name.
- Configure a Business Rule to create the groups based on the project name.
- [Optionally] Give the attribute your own display name.
i. Create a Home Page Action
To enable users to input a project name, you need to create a Home Page Action that allows them to edit a certain attribute of their own accounts. The attribute will be used to pass the project name to the script. For information on how to create such a Home Page Action, see section Modify Object in the following tutorial: http://www.adaxes.com/tutorials_WebInte ... htm#modify. Use the section as a guide.
- On Step 1 of the section, select Modify User.
- Since users are going to modify their own accounts via this Home Page Action, on Step 3 of the section, select Always perform for the current user.
- Also, you need to customize the form used by the Home Page Action. On the form, you need to leave only one field that will be used to input the project name. For detailed instructions, see Step 4 of the section.
ii. Configure a Business Rule
To configure a Business Rule to create the necessary groups:
-
Create a new Business Rule.
-
On the 2nd step of the Create Business Rule wizard, select User and After Updating a User.
-
On the 3rd step, add the Run a program or PowerShell script action and paste the following script in the Script field.
$ouDN = "OU=Groups,OU=Projects,DC=example,DC=com" # TODO: modify me
$propertyName = "adm-CustomAttributeText1" # TODO: modify me
[Softerra.Adaxes.Interop.Adsi.ADS_GROUP_TYPE_ENUM]$groupType = "ADS_GROUP_TYPE_GLOBAL_GROUP, ADS_GROUP_TYPE_SECURITY_ENABLED" # TODO: modify me
# Function to create groups
function CreateGroup($ouDN, $name, $description, $displayName, $sAMAccountName, $groupType)
{
$ou = $Context.BindToObjectByDN($ouDN)
$group = $ou.Create("group", "CN=$name")
$group.Put("description", $description)
$group.Put("displayName", $displayName)
$group.Put("sAMAccountName", $sAMAccountName)
$group.Put("groupType", [int]$groupType)
$group.Put("managedBy", $ownerDN)
$group.SetInfo()
$groupSid = $group.Get("objectSid")
}
# Get project name
$value = $Context.Initiator.UserAdsObject.Get($propertyName)
# Create group for Project Owners
$groupReviewersSid = CreateGroup $ouDN "$value - Project Owners"`
"$value - Project Owners" "$value - Project Owners"`
"$value-PO" $groupType
# Create group for Read/Write access
$groupReviewersSid = CreateGroup $ouDN "$value - RW Access"`
"$value - RW Access" "$value - RW Access"`
"$value-RW" $groupType
# Create group for Read-Only access
$groupReviewersSid = CreateGroup $ouDN "$value - RO Access"`
"$value - RO Access" "$value - RO Access"`
"$value-RO" $groupType
# Create group for No access users
$groupReviewersSid = CreateGroup $ouDN "$value - Access Denied"`
"$value - Access Denied" "$value - Access Denied"`
"$value-NA" $groupType
# Clear the custom attribute
$Context.Initiator.UserAdsObject.Put($propertyName, $NULL)
$Context.Initiator.UserAdsObject.SetInfo()
-
In the script, modify the following to match your requirements:
- $ouDN - specifies the Distinguished Name (DN) of the OU where the groups will be created,
- $propertyName - specifies the LDAP name of the property that will be used to pass the project name to the script,
- $groupType - specifies the group type. For a complete list of the possible values, see ADS_GROUP_TYPE_ENUM.
-
Enter a short description for the script and click OK.
-
Now, you need to specify when the script will be run. For this purpose, you need to add conditions. Right-click the action that you've just added and click Add Condition.
-
Select the If <property> changed condition type.
-
Specify If CustomAttributeText1 has changed, where CustomAttributeText1 is the name of the property that will be used to pass the project name.
-
Click OK.
-
Right-click the action and click Add Condition again.
-
Select the If <property> <relation> <value> condition type.
-
Specify If CustomAttributeText1 is not empty, where CustomAttributeText1 is the name of the property that will be used to pass the project name.
-
Click OK.
-
Finish creation of the Business Rule.
iii. Give the property your own display name (optional)
Since a name like CustomAttributeText1 will not tell much to your users about the function and the meaning of the field, you'll probably want to give it your own name. For information on how to do that, see the following help article: http://www.adaxes.com/help/?HowDoI.Mana ... Names.html.