# List of roles (all roles)

**URL:** <https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036>\
**Category:** Ignition\
**Created:** [August 12, 2016, 8:07pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036 "2016-08-12T20:07:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrandonSHill](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brandonshill/32/6805_2.png) [@BrandonSHill](https://forum.inductiveautomation.com/u/BrandonSHill)\
**Post date:** [August 12, 2016, 8:07pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/1 "2016-08-12T20:07:21Z")

</div>

Is there a way to get a list of all roles on the gateway under the a specified user source? Not just a specific user, but all roles? Working on building out a tree view that is stored all in the DB and creating an administration screen for it. But needing to be able to pull a list of roles to finish it out.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 12, 2016, 8:11pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/2 "2016-08-12T20:11:41Z")

</div>

Like this? [docs.inductiveautomation.com:84 … r.getRoles](https://docs.inductiveautomation.com:8443/display/DOC/system.user.getRoles)

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [July 10, 2020, 5:58pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/3 "2020-07-10T17:58:56Z")

</div>

Is it possible to return a list of roles(not Ignition created roles) per user from an Active Directory user source? If I use a system.security.getRoles() and the Gateway User Source is set to the desired source is the only way to return these values. Is there any other way of accessing roles(not Ignition created) from an Active Directory user source that is not set as the Gateway User Source?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 10, 2020, 6:07pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/4 "2020-07-10T18:07:53Z")

</div>

You can achieve this with system.user.getUsers()  
You’ll specify the user data source (ex. ‘AD User Source’) and from there you can getRoles() for a specific user or all users.  
[https://docs.inductiveautomation.com/display/DOC80/system.user.getUser](https://docs.inductiveautomation.com/display/DOC80/system.user.getUser)  
[https://docs.inductiveautomation.com/display/DOC80/system.user.getUsers](https://docs.inductiveautomation.com/display/DOC80/system.user.getUsers)

Edit Example, this will print the role for the currently logged in user:

```auto
userName = system.security.getUsername()
user = system.user.getUser("AD User Source", userName)
print user.getRoles()

```

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [July 10, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/5 "2020-07-10T18:49:09Z")

</div>

This definitely works to return the Ignition added User Information. Maybe a better question would be, how am I returning Microsoft AD(LDAP) related information when using system.security.getRoles()?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 10, 2020, 6:55pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/6 "2020-07-10T18:55:12Z")

</div>

> [@hachjessed](#):
>
> This definitely works to return the Ignition added User Information.

I'm not following.

system.security.getRoles() returns my AD roles no problems.

If you have multiple user sources in your gateway and your projects default user source is NOT the AD user source then system.security.getRoles() will not work. You'll need to make use of system.user.getUser()/Users()

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 10, 2020, 7:26pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/7 "2020-07-10T19:26:06Z")

</div>

> [@hachjessed](#):
>
> Is it possible to return a list of roles(not Ignition created roles) per user from an Active Directory user source?

Here's an example that should do just that:

```auto
users = system.user.getUsers('MY AD USERSOURCE NAME')
for user in users:
	print user.get('username'), user.getRoles()

```

Please change "MY AD USERSOURCE NAME" to match your AD user source name.

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [July 10, 2020, 7:27pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/8 "2020-07-10T19:27:39Z")

</div>

Let me try another explanation.  
The User Source I am attempting to access has no users or roles added.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0b5be230698d8238574c51291eefe3ac47916873.png)  
When I use the system.security.getRoles() function I return a tuple of string values, which are our companies AD groups that the user is a member of. These are the values I am looking for, but I would like to know why/how these values are being accessed and how to replicate this if the Gateway User Source is not set to the User Source I’m looking to getRoles from.

---

<div class="post-metadata">

**Author:** ![hachjessed](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@hachjessed](https://forum.inductiveautomation.com/u/hachjessed)\
**Post date:** [July 10, 2020, 7:37pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/9 "2020-07-10T19:37:23Z")

</div>

This returns no results with ADUSERSOURCE1. If I use a ADUSERSOURCE2 that contains Ignition created users and roles, it does return these usernames and roles.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 10, 2020, 7:51pm UTC](https://forum.inductiveautomation.com/t/list-of-roles-all-roles/12036/10 "2020-07-10T19:51:08Z")

</div>

Sounds like your **Active Directory Properties** and/or **LDAP Settings** are not correctly setup for your environment?  
By configuring your **Active Directory Properties** and/or **LDAP Settings** to retrieve your AD users the above script would print each user and roles.
