首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nexus3使用API配置LDAP

Nexus3使用API配置LDAP
EN

Stack Overflow用户
提问于 2016-10-06 18:50:28
回答 1查看 3.1K关注 0票数 2

我目前正在尝试编写一个脚本,以便在我的Nexus 3实例上配置LDAP。我看了一下帖子,我遇到了一些错误,我想只是我没有很好地理解Groovy。

这是我试过的。

代码语言:javascript
复制
import org.sonatype.nexus.ldap.persist.*
import org.sonatype.nexus.ldap.persist.entity.*
import groovy.json.JsonSlurper

def ldap = new JsonSlurper().parseText(args)
def manager = container.lookup(LdapConfigurationManager.class.name)

manager.addLdapServerConfiguration(
  new LdapConfiguration(
    name: ldap.name,
    connection: new Connection(
      host: new Connection.Host(Connection.Protocol.ldap, ldap.host, ldap.port),
      maxIncidentsCount: 3,
      connectionRetryDelay: 300,
      connectionTimeout: 15,
      searchBase: 'dc=example,dc=com',
      authScheme: 'simple',
      systemPassword: 'systemPassword',
      systemUsername: 'systemUsername'
    ),
    mapping: new Mapping(
      ldapGroupsAsRoles: true,
      emailAddressAttribute: 'mail',
      userIdAttribute: 'sAMAccountName',
      userMemberOfAttribute: 'memberOf',
      userObjectClass: 'user',
      userPasswordAttribute: 'userPassword',
      userRealNameAttribute: 'cn',
      userBaseDn: '(memberof:1.2.840.113556.1.4.1941:=cn=Devs,ou=someOU,ou=anotherOU,dc=example,dc=com'
    )
  )
)

当我使用复杂脚本示例中提供的provision.sh脚本时,我得到:

代码语言:javascript
复制
      "name" : "ldapConfig",
      "result" : "org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:\n
Script8.groovy: 10: unable to resolve class ldapConfiguration \n 
@ line 10, column 3.\n    new ldapConfiguration(\n^\n\n1 error\n"

它真的困扰着我,它无法解决这门课.现在,我不知道如何为args提供JSON对象。相反,我尝试将JSON块直接放入JsonSlurper().parseText()中,如下所示:

代码语言:javascript
复制
ldap = new JsonSlurper().parseText('{"host: localhost", "port: 389"}')

这将产生与上面相同的错误。

下面是一个来自provision.sh的片段,它是调用addUpdateScript.groovy脚本的地方。

代码语言:javascript
复制
#!/bin/bash

# A simple example script that publishes a number of scripts to the Nexus Repository Manager
# and executes them.

# fail if anything errors
set -e
# fail if a function call is missing an argument
set -u

username=admin
password=admin123

# add the context if you are not using the root context
host=http://localhost:8081

    # add a script to the repository manager and run it
    function addAndRunScript {
      name=$1
      file=$2
      # using grape config that points to local Maven repo and Central Repository , default grape config fails on some downloads although artifacts are in Central
      # change the grapeConfig file to point to your repository manager, if you are already running one in your organization
      groovy -Dgroovy.grape.report.downloads=true -Dgrape.config=grapeConfig.xml addUpdatescript.groovy -u "$username" -p "$password" -n "$name" -f "$file" -h "$host"
      printf "\nPublished $file as $name\n\n"
      curl -v -X POST -u $username:$password --header "Content-Type: text/plain" "$host/service/siesta/rest/v1/script/$name/run"
      curl -v -X GET -u $username:$password "$host/service/siesta/rest/v1/script/$name"
      printf "\nSuccessfully executed $name script\n\n\n"
    }

    printf "Provisioning Integration API Scripts Starting \n\n" 
    printf "Publishing and executing on $host\n"

    addAndRunScript ldapConfig ldapConfig.groovy

我用错了类名吗?LdapConfiguration。当我将它加载到IntelliJ中时,我找到了ldapConfig,但它也没有工作。不知道如何深入javadoc以从库中获得更多细节。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-06 21:28:49

我相信你有

代码语言:javascript
复制
new ldapConfiguration(

你需要的地方

代码语言:javascript
复制
new LdapConfiguration(

在脚本的第10行

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39903588

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档