繁体   English   中英

com.sun.jndi.ldap.LdapAttribute objectGUID 编码错误

[英]com.sun.jndi.ldap.LdapAttribute objectGUID wrong encoding

我正在尝试使用 Groovy 对 AD 进行 LDAP 搜索,检索以下属性:'sn'、'givenName'、'sAMAccountName'、'memberOf'、'objectGUID'。 除了objectGUID,一切都显示得很好。

Code for LDAP Search: 
import javax.naming.directory.*

// base OU for our search
GRP_OU = 'OU=cust,DC=example,DC=com'

mkCtx = {param = [:] ->
  new InitialDirContext(
    (Hashtable)param.collect { k, v ->
      [InitialDirContext[k], v.toString()]
    }.collectEntries()
  )
}

mkCtx(PROVIDER_URL: "ldap://example.com:389",
  INITIAL_CONTEXT_FACTORY: 'com.sun.jndi.ldap.LdapCtxFactory',
  SECURITY_AUTHENTICATION: 'simple',
  SECURITY_PRINCIPAL: "CN=user,DC=example,DC=com",
  SECURITY_CREDENTIALS: 'password',
).search(
  GRP_OU, '(&(mail=ldaptest@example.de)(memberof=group,DC=example,DC=com))', new SearchControls([searchScope: SearchControls.SUBTREE_SCOPE])
).collect { entry ->
    def attributes = ['sn', 'givenName', 'sAMAccountName', 'memberOf', 'objectGUID']
    def newlst = []
    newlst = attributes.collect { entry.attributes.get(it) }
    println(newlst[0].toString().tokenize(': ')[1])
    println(newlst[1].toString().tokenize(': ')[1])
    println(newlst[2].toString().tokenize(': ')[1])
    println(newlst[3].toString().tokenize(': ')[1])
    println(newlst[4].toString().tokenize(': ')[1])
}

它提供了以下 output:

LDAPTest
LDAPTest
ldaptest
CN=user,OU=group,DC=example,DC=com
S�A|P2K��k6@(�

我已经在没有toString().tokenize() function 的情况下对其进行了测试,但结果相同。

如何将 objetGUID 解析为可读字符串(例如 objectGUID:x0880xx89-xxxx-xxxx-xxxx-181969abcd8a)

提前致谢!

byte guidBytes[] = entry.attributes.get("objectGUID")
def guid = guidBytes.encodeHex().toString().replaceAll('^(.{8})(.{4})(.{4})(.{4})', '$1-$2-$3-$4-')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM