簡體   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