Note that there are some explanatory texts on larger screens.

plurals
  1. POconnect Java to Active Directory
    primarykey
    data
    text
    <p>I try to connect to Active Directory with my Java code, but I get this error message :</p> <pre><code>Début du test Active Directory Search error: javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C0904DC, comment: AcceptSecurityContext error, data 52e, v1db1 </code></pre> <p>I use JNDI,the DIGEST-MD5 authentication method and no encryption method this is my code:</p> <pre><code>public class TestAD { static DirContext ldapContext; public static void main (String[] args) throws NamingException { try { System.out.println("Début du test Active Directory"); Hashtable&lt;String, String&gt; ldapEnv = new Hashtable&lt;String, String&gt;(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); ldapEnv.put(Context.PROVIDER_URL, "ldap://societe.fr:389"); ldapEnv.put(Context.SECURITY_AUTHENTICATION, "DIGEST-MD5"); ldapEnv.put("java.naming.security.sasl.realm","myRealm"); ldapEnv.put("javax.security.sasl.qop", "auth"); ldapEnv.put("javax.security.sasl.strength","high"); ldapEnv.put(Context.SECURITY_PRINCIPAL, "dn:cn=administrateur,ou=users,o=societe.fr"); ldapEnv.put(Context.SECURITY_CREDENTIALS,"myPassword"); ldapContext = new InitialDirContext(ldapEnv); // Create the search controls SearchControls searchCtls = new SearchControls(); // Specify the attributes to return String returnedAtts[]={"sn","givenName", "samAccountName"}; searchCtls.setReturningAttributes(returnedAtts); // Specify the search scope searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); // specify the LDAP search filter String searchFilter = "(&amp;(objectClass=user))"; // Specify the Base for the search String searchBase = "dc=societe,dc=fr"; // initialize counter to total the results int totalResults = 0; // Search for objects using the filter NamingEnumeration&lt;SearchResult&gt; answer = ldapContext.search(searchBase, searchFilter, searchCtls); // Loop through the search results while (answer.hasMoreElements()) { SearchResult sr = (SearchResult)answer.next(); totalResults++; System.out.println("&gt;&gt;&gt;" + sr.getName()); Attributes attrs = sr.getAttributes(); System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;" + attrs.get("samAccountName")); } System.out.println("Total results: " + totalResults); ldapContext.close(); } catch (Exception e) { System.out.println(" Search error: " + e); e.printStackTrace(); System.exit(-1); } } } </code></pre> <p>P.S.:I can connect to my Active Directory with the same parameter with Apache Directory Studio</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload