【问题标题】:Nexus 3 | How to create (external) users using Nexus 3 APIs?连结 3 |如何使用 Nexus 3 API 创建(外部)用户?
【发布时间】:2019-05-29 03:22:14
【问题描述】:

我正在尝试使用 Nexus 3 API 在 Nexus 3 上创建外部用户。以下是详细信息: 使用:http://localhost:8081/nexus3/service/rest/v1/script

发布 Groovy 脚本
{
    "name": "d8b3baeb-628a-43cc-9a9c-9a156f399e2",
    "type": "groovy",
    "content": "security.addUser('q018246a', '', '', '', true, 'd8b3baeb-628a-43cc-9a9c-9a156f399ae2', ['abc_test_role Developer Role']);"
}

运行脚本使用:http://localhost:8081/nexus3/service/rest/v1/script/d8b3baeb-628a-43cc-9a9c-9a156f399e2/run

回复:

{
    "name": "d8b3baeb-628a-43cc-9a9c-9a156f399e2",
    "result": "User{userId='q018246a', firstName='', lastName='', source='default'}"
}

通过邮递员,一切正常,用户被创建。但是通过应用程序服务器它提供Bad request

尴尬的行为是,它让我使用带有空白first_name, last_name, email, password 的邮递员脚本创建用户,但 UI 上需要所有这些参数。

另一件事,它显示sourcedefault 但我如何确保sourceLDAP

【问题讨论】:

    标签: nexus nexus3


    【解决方案1】:

    我假设您正在尝试映射 LDAP 用户?如果是这样,这将起作用:

    import org.sonatype.nexus.security.role.RoleIdentifier;
    import org.sonatype.nexus.security.user.User;
    
    String userId = 'someuser';
    String newRoleId = 'nx-admin'
    
    User user = security.securitySystem.getUser(userId, 'LDAP')
    
    if(user != null) {
        RoleIdentifier newRole = new RoleIdentifier('default', newRoleId);
        user.addRole(newRole)
        security.securitySystem.setUsersRoles(user.getUserId(), 'LDAP', user.getRoles());
    } else {
        log.warn("No user with ID of $userId found.")
    }
    

    【讨论】:

    • 这适用于现有的 LDAP 用户。我正在尝试在 LAP 领域下添加一个新用户。
    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 2021-03-19
    相关资源
    最近更新 更多