【问题标题】:Nexus3 Configure LDAP with APINexus3 使用 API 配置 LDAP
【发布时间】:2017-02-15 15:31:47
【问题描述】:

我目前正在尝试编写一个脚本来在我的 Nexus 3 实例上配置 LDAP。我查看了this 的帖子,遇到了一些错误,我认为只是我不太了解 Groovy。

这是我尝试过的。

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 脚本时,我得到:

      "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() 中,如下所示:

ldap = new JsonSlurper().parseText('{"host: localhost", "port: 389"}')

这会产生与上述相同的错误。

这里是一个来自 provision.sh 的 sn-p 是调用 addUpdateScript.groovy 脚本的地方。

#!/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

我是否使用了错误的类名? Ldap 配置。当我将它加载到 IntelliJ 中时,我发现了 ldapConfig 但它也不起作用。不知道如何深入研究 javadoc 以从库中获取更多详细信息。

【问题讨论】:

  • 那不是有效的json,试试; ldap = new JsonSlurper().parseText('{"host": "localhost", "port": 389}')
  • 啊,很好,我没看到。在此处进行更改是返回的内容。结果" : "org.codehaus.groovy.control.MultipleCompilationErrorsException: 启动失败:\nScript10.groovy: 10: 无法解析类 ldapConfiguration \n @ 第 10 行,第 3 列。
  • 确定你有new LdapConfiguration,而不是小写l作为第一个字母?
  • 就是这样。万分感谢。您不会碰巧知道用户过滤器的映射属性是什么?
  • 它是每个 javadoc 的 ldapFilter。 @tim_yates,如果您想发表评论作为答案,我会将其标记为已接受。再次感谢。

标签: groovy nexus


【解决方案1】:

我相信你有

new ldapConfiguration(

你需要的地方

new LdapConfiguration(

在脚本的第 10 行

【讨论】:

    猜你喜欢
    • 2022-11-12
    • 2015-03-16
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多