【发布时间】:2015-03-20 14:07:46
【问题描述】:
我目前正在构建自己的 Openidm 连接器,以使用基于 ScriptedRest2DJ 示例的 Groovy 框架连接器来配置外部系统。
我正在实现 searchScript.groovy 文件以在目标系统上搜索资源(用户),并且我想在我的请求中传递源系统的当前用户 UID。
这里是 SearchScript.groovy 源代码:
import groovyx.net.http.RESTClient
import org.apache.http.client.HttpClient
import org.forgerock.openicf.connectors.scriptedrest.ScriptedRESTConfiguration
import org.forgerock.openicf.misc.scriptedcommon.OperationType
import org.identityconnectors.common.logging.Log
import org.identityconnectors.framework.common.objects.Attribute
import org.identityconnectors.framework.common.objects.AttributeUtil
import org.identityconnectors.framework.common.objects.Name
import org.identityconnectors.framework.common.objects.ObjectClass
import org.identityconnectors.framework.common.objects.OperationOptions
import org.identityconnectors.framework.common.objects.SearchResult
import org.identityconnectors.framework.common.objects.Uid
import org.identityconnectors.framework.common.objects.filter.Filter
import org.identityconnectors.framework.common.objects.AttributesAccessor
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON;
// imports used for CREST based REST APIs
import org.forgerock.openicf.misc.crest.CRESTFilterVisitor
import org.forgerock.openicf.misc.crest.VisitorParameter
def operation = operation as OperationType
def configuration = configuration as ScriptedRESTConfiguration
def httpClient = connection as HttpClient
def connection = customizedConnection as RESTClient
def filter = filter as Filter
def log = log as Log
def objectClass = objectClass as ObjectClass
def options = options as OperationOptions
def resultHandler = handler
log.info("Entering " + operation + " Script")
switch (objectClass) {
case ObjectClass.ACCOUNT:
// Search for a specific user in Alfresco
// http://docs.alfresco.com/community/references/RESTful-PersonPersonGet.html
def searchResult = connection.request(GET, JSON) { req ->
uri.path = 'people'
headers.Accept = 'application/json'
response.success = { resp, json ->
json.people.each() { value ->
resultHandler {
uid value.userName
id value.userName
attribute 'email', value?.email
attribute 'lastName', value?.lastName
attribute 'userName', value?.userName
attribute 'firstName', value?.firstName
attribute 'enabled', value?.enabled
//attribute ('groups', *(value?.groups))
}
}
json
}
}
return new SearchResult(null, -1) // no remaining results
}
您如何访问脚本中的源值?我已经测试了 Uid、Id、Name、... 没有成功。
感谢您的帮助
【问题讨论】:
-
您是否尝试访问请求中指定的 id 值(即 system/scriptedrest/account/${id}),或者您是否尝试返回从 REST 调用中读取的 id到远程系统?
-
在启动数据协调(手动或自动)时,我的连接器会直接调用 SearchScript。我不使用 REST API 启动此脚本,因此我对这些参数一无所知,但是是的,我想检索源帐户的名称/ID 值,而不是在目标系统上。
-
您能否使用当前 SearchScript.groovy 代码的示例部分更新您的帖子,尤其是进行 REST 调用和处理响应的部分?
-
我刚刚发布了正在运行的源代码,但它会从 Alfresco CMS 中检索所有用户。这是正确的做法吗?