活动目录通知

Active Directory notifications

本文关键字:通知 活动      更新时间:2023-10-16

我看过微软文档中的这个例子,但无法在visual studio 2012中工作,在一个控制台项目下。https://msdn.microsoft.com/en-us/library/ms676877 (v = vs.85) . aspx

我是不是漏掉了什么?控制台应用程序是否正确。

我得到的错误是:

Error   1   error LNK2019: unresolved external symbol __imp__ldap_openW referenced in function "int __cdecl GetChangeNotifications(wchar_t *)" (?GetChangeNotifications@@YAHPA_W@Z) C:projectsAD_NotificationsAD_Change_NotificationsAD_Change_NotificationsAD_Change_Notifications.obj    AD_Change_Notifications

从我一直在阅读它的链接错误,这是有点明显,但它都在1个文件,所以我不明白我应该链接什么?

我在java中找到的最好的答案是下面引用的https://community.oracle.com/thread/1158217

/**
 * ldapnotify.java
 * December 2004
 * Sample JNDI application that uses AD LDAP Notification Control.
 * 
 **/
import java.util.Hashtable;
import java.util.Enumeration;
import javax.naming.*;
import javax.naming.ldap.*;
import com.sun.jndi.ldap.ctl.*;
import javax.naming.directory.*;
class NotifyControl implements Control {
     public byte[] getEncodedValue() {
             return new byte[] {};
     }
       public String getID() {
          return "1.2.840.113556.1.4.528";
     }
      public boolean isCritical() {
          return true;
     }
}
class ldapnotify {
     public static void main(String[] args) {
          Hashtable env = new Hashtable();
          String adminName = "CN=Administrator,CN=Users,DC=antipodes,DC=com";
          String adminPassword = "XXXXXXXX";
          String ldapURL = "ldap://mydc.antipodes.com:389";
          String searchBase = "DC=antipodes,DC=com";
          //For persistent search can only use objectClass=*
          String searchFilter = "(objectClass=*)";
               env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          //set security credentials, note using simple cleartext authentication
          env.put(Context.SECURITY_AUTHENTICATION,"simple");
          env.put(Context.SECURITY_PRINCIPAL,adminName);
          env.put(Context.SECURITY_CREDENTIALS,adminPassword);
          //connect to my domain controller
          env.put(Context.PROVIDER_URL,ldapURL);
          try {
               //bind to the domain controller
                  LdapContext ctx = new InitialLdapContext(env,null);
               // Create the search controls           
               SearchControls searchCtls = new SearchControls();
               //Specify the attributes to return
               String returnedAtts[] = null;
               searchCtls.setReturningAttributes(returnedAtts);
               //Specify the search scope
               searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                     //Specifiy the search time limit, in this case unlimited
               searchCtls.setTimeLimit(0);
               //Request the LDAP Persistent Search control
                     Control[] rqstCtls = new Control[]{new NotifyControl()};
                     ctx.setRequestControls(rqstCtls);
               //Now perform the search
               NamingEnumeration answer = ctx.search(searchBase,searchFilter,searchCtls);
                SearchResult sr;
                     Attributes attrs;
               //Continue waiting for changes....forever
               while(true) {
                    System.out.println("Waiting for changes..., press Ctrl C to exit");
                     sr = (SearchResult)answer.next();
                          System.out.println(">>>" + sr.getName());
                    //Print out the modified attributes
                    //instanceType and objectGUID are always returned
                    attrs = sr.getAttributes();
                    if (attrs != null) {
                         try {
                              for (NamingEnumeration ae = attrs.getAll();ae.hasMore();) {
                                   Attribute attr = (Attribute)ae.next();
                                   System.out.println("Attribute: " + attr.getID());
                                   for (NamingEnumeration e = attr.getAll();e.hasMore();System.out.println("   " + e.next().toString()));
                              }
                         } 
                         catch (NullPointerException e)     {
                              System.err.println("Problem listing attributes: " + e);
                         }
                    }
               }
              } 
          catch (NamingException e) {
                      System.err.println("LDAP Notifications failure. " + e);
              } 
       } 
}