2013-11-24 99 views
1

我在Java中創建了一個Active Directory(winserver 2012)LDAP身份驗證器,在這種情況下,當AD用戶名包含dost(。)時,身份驗證失敗,例外:如果用戶名包含點(。),Active Directory LDAP身份驗證失敗

javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C0904F8, comment: AcceptSecurityContext error, data 52e, v23f0 

如果用戶名不包含dot,則認證。工作正常。

有代碼:

private DirContext getDirContext(String username, String password) { 

    ... 

    Hashtable<String, String> env = new Hashtable<>(); 

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
    env.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5"); 
    env.put(Context.PROVIDER_URL, "LDAP://server.test.local:389"); 
    env.put(Context.SECURITY_PRINCIPAL, "test.user"); 
    env.put(Context.SECURITY_CREDENTIALS, "password"); 
    env.put(Context.REFERRAL, "follow"); 
    env.put("java.naming.ldap.attributes.binary", "objectGUID objectSid"); 

    DirContext ctx; 

    try { 
     ctx = new InitialLdapContext(env, null); 
    } catch (NamingException ex) { 
     getLogger().log(Level.WARNING, 
       "ACTIVE DIRECTORY - AUTHENTICATION ERROR: " + ex); 
    } 

    return ctx; 
} 

我試圖取代圓點%2E,我試圖完整的用戶名([email protected]),但這些並沒有解決我的問題。

有沒有人有任何想法?謝謝。

+0

我認爲你需要添加域(即:DOMAIN \\ +用戶) 參見:http://stackoverflow.com/questions/16570222/how-to-authenticate-against- active-directory-via-ldap-over-tls – jjhavokk

+0

Context.SECURITY_PRINCIPAL不需要斷言,例如'cn = test.user'嗎? –

+0

它沒有cn =的作品,但我會檢查它,並與域/明天。 – user2938801

回答

1

Context.SECURITY_PRINCIPAL必須是您使用的上下文中的有效主體名稱。 (在你的情況下,LDAP - AD)

因此,完全限定的DN或userPrincipalName或or domain \ samaccountname應該可以工作。 我們已經把一些JNDI samples

+0

我嘗試了用戶名中沒有點的跟蹤類型:cn = testuser,ou = User,dc = test,dc = local - 不起作用,TEST \\ testuser - 不起作用,[email protected] - 不起作用。所以我不知道爲什麼,但它現在適用於以防萬一,當我給「測試用戶」。 – user2938801

+0

服務器端可能有問題嗎? – user2938801

+0

「49 \t 52e ERROR_LOGON_FAILURE \t當用戶名有效但密碼/憑證無效時返回。錯誤代碼也是intresting,因爲密碼是正確的,當我使用「testuser」SECURITY_PRINCIPAL。 – user2938801

相關問題