T_T_T
T_T_T

Reputation: 3

Nexus Repo Manager - How to get roles based on Repo name?

I am try to list out all roles currently have access to Nexus repo A.

Upvotes: 0

Views: 411

Answers (1)

rseddon
rseddon

Reputation: 5318

There isn't a lookup in repo manager that goes in that direction. But you could write a groovy script that traverses the role/privilege tree, and get the information that way.

Here's a simple script that should help get you going in the right direction:

allRoles = security.getSecuritySystem().listRoles()
allPrivileges = security.getSecuritySystem().listPrivileges()


log.info("\n  ---------------------------- \n Listing Roles and Privileges \n" +
        "  ---------------------------- ")
roleSize = allRoles.size()
log.info("Roles found: $roleSize")
for (r in allRoles) {
    log.info("Role --> RoleId: $r.roleId, Name: $r.name, Source: $r.source")

    log.info("Role --> RoleId: $r.roleId, Name: $r.name, Source: $r.source")
    for(p in r.privileges) {
        rolePrivilege = allPrivileges.find { it.id == (p) }
        if (rolePrivilege) {
            log.info("Privilege for role '$r.name' --> Id: $rolePrivilege.id, Name: $rolePrivilege.name, Desc: $rolePrivilege.description")
        }
    }
}

You could run this in "system/tasks" in the admin UI by creating an "admin - execute script" task, or as a REST API as described here:

https://help.sonatype.com/display/NXRM3/Script+API

I'd also strongly recommend setting up an IDE environment for script development, with that you can use code completion, and browse directly into the Nexus source code from your scripts:

https://support.sonatype.com/hc/en-us/articles/115015812727-Nexus-3-Groovy-Script-development-environment-setup

Upvotes: 1

Related Questions