title: NamingListener not supported in Active Directory?
body: <p>I'm trying to run:</p>
  
  <pre><code>    Map&lt;String, String&gt; environmentProperties = new HashMap&lt;String, String&gt;();
      environmentProperties.put("java.naming.security.authentication", "simple");
      environmentProperties.put("java.naming.ldap.attributes.binary", "tokenGroups objectSid");
  
      LdapContextSource contextSource = new LdapContextSource();
      contextSource.setAnonymousReadOnly(false);
      contextSource.setPooled(false);
  
      contextSource.setUserDn("CN=Administrator,CN=Users,DC=someDomain,DC=com");
      contextSource.setPassword("password");
  
      contextSource.setUrls(new String[]{"ldap://url.goes.here"});
      contextSource.setBaseEnvironmentProperties(environmentProperties);
      contextSource.setDirObjectFactory(null);
      contextSource.afterPropertiesSet();
  
      final SearchControls searchControls = new SearchControls();
      searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
  
      ContextExecutor contextExecutor = new ContextExecutor() {
         public Object executeWithContext(DirContext ctx) throws NamingException {
            EventDirContext ectx = (EventDirContext) ctx.lookup("CN=Users,,DC=someDomain,DC=com");
            ectx.addNamingListener("", "(cn=*)", searchControls, new LDAPChangeListener());
            return null;
         }
      };
  
  
      LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
      ldapTemplate.setIgnorePartialResultException(true);
  
      ldapTemplate.executeReadOnly(contextExecutor);
  </code></pre>
  
  <p>but, the first message my listener gets is:</p>
  
  <blockquote>
    <p>javax.naming.OperationNotSupportedException: [LDAP: error code 12 - 00000057: LdapErr: DSID-0C090753, comment: Error processing control, data 0, v1db1 ]; remaining name ''
        at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3127)
        at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3013)
        at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
        at com.sun.jndi.ldap.LdapNamingEnumeration.getNextBatch(LdapNamingEnumeration.java:129)</p>
  </blockquote>
  
  <p>I also ran this code I found <a href="http://www.forumeasy.com/forums/archive/ldappro/200703/p117381285598.html" rel="nofollow">here</a> that's supposed to verify that my AD supports persistent search, and the result was true.</p>
  
  <pre><code>static boolean isPersistentSearchSupported(LdapContext rootContext)
          throws NamingException {
      SearchResult rootDSE;
      NamingEnumeration searchResults;
      Attributes attrs;
      NamingEnumeration attrEnum;
      Attribute attr;
      NamingEnumeration values;
      String value;
      String[] attrNames = { "supportedControl" };
      SearchControls searchControls = new SearchControls();
  
      searchControls.setCountLimit(0); // 0 means no limit
      searchControls.setReturningAttributes(attrNames);
      searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
  
      // search for the rootDSE object
      searchResults = rootContext.search("", "(objectClass=*)",
              searchControls);
  
      while (searchResults.hasMore()) {
          rootDSE = (SearchResult) searchResults.next();
  
          attrs = rootDSE.getAttributes();
          attrEnum = attrs.getAll();
          while (attrEnum.hasMore()) {
              attr = (Attribute) attrEnum.next();
              values = attr.getAll();
              while (values.hasMore()) {
                  value = (String) values.next();
                  if (value.equals("1.2.840.113556.1.4.528"))
                      return true;
              }
          }
      }
      return false;
  }
  </code></pre>
  
  <p>what do I need to do to start getting events from AD?</p>