How can we define a dynamic role based on user organizational unit in Active Directory ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can we define a dynamic role based on user organizational unit in Active Directory ?

Created a dynamic role in CyberArk identity based on provided example to filter on organizational unit in AD

if (User.UserType == 'AD') { try { DN = User.Get('distinguishedname'); username = User.Username; trace('UserType: ' + User.UserType); trace('DN: ' + DN); result = DN.search(/OU=XXX,...,DC=company,DC=com/i); trace('Results are in: ' + result); return (result > 0); ...

Seems to work, unfortunately not for all users, some have an empty DN, some have a value, in Test User I get:

 

  • broken user:

UserType: AD

DN: null

  • working user:

UserType: AD

DN: CN=name,OU=XXX,OU=YYYY,DC=company,DC=com

 

And of course the broken users are eventually not members of the dynamic role.

 

 

 

1 accepted solution

Accepted Solutions

L4 Transporter

Try this

 

DN = User.Properties.Properties['distinguishedName'];

trace('User: '+ DN);

result = DN.search(/OU=EARTH/i);

trace ('Results are in: '+ result);

if (result > 0) { return true;}

else {

return false;

}

 

 

Source: https://community.cyberark.com/s/article/CyberArk-Identity-Dynamic-Roles-by-OU?

View solution in original post

5 REPLIES 5

L4 Transporter

Try this

 

DN = User.Properties.Properties['distinguishedName'];

trace('User: '+ DN);

result = DN.search(/OU=EARTH/i);

trace ('Results are in: '+ result);

if (result > 0) { return true;}

else {

return false;

}

 

 

Source: https://community.cyberark.com/s/article/CyberArk-Identity-Dynamic-Roles-by-OU?

Interesting, User.Get and User.Properties.Properties[] return a different result:

 

Field_Content_versions_oct20__068Ht00000VfVoGIAV.pngDN from properties: CN=user,OU=...

DN from User.Get: null

 

The properties.properties syntax triggers a warning but returns the right value, the User.Get returns null

 

Note that the User.Get('distinguishedname') syntax is used in the "Include By Organization.js" sample inside CyberArk identity administration portal.

L4 Transporter

The false warning is a bug. Does that mean properties.properties worked?

Yes the User.Properties.Properties syntax seems to work fine, I updated my dynamic roles accordingly.

 

Thus:

- User.Get provided in sample rule is not reliable (working on some users, not on others)

- User.Properties.Properties is the right way, just ignore the false warning bug

 

Thank you for your help.

It worked fine last week, now I get an error:

 

An error occurred on distinguishedname script execution - The given key was not present in the dictionary. at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key) at dynamicIndexerSetter(Marshaller , JsInstance , JsInstance ) at Jint.ExecutionVisitor.Visit(Indexer indexer) at Jint.ExecutionVisitor.Visit(MemberExpression expression) at Jint.ExecutionVisitor.Visit(AssignmentExpression statement) at Jint.ExecutionVisitor.Visit(BlockStatement statement) at Jint.ExecutionVisitor.Visit(TryStatement statement)

 

  • 1 accepted solution
  • 87 Views
  • 5 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!