This discussion is archived
8 Replies Latest reply: Aug 8, 2011 6:16 AM by 796440 RSS

URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"

880240 Newbie
Currently Being Moderated
Hi,

I am trying to get deleted users from Active Directory after a certain interval. Every time only the differences in the result will be shown. Also I need to get the value of the specific attribute called "sAMAccount" every time for each user(in the result).

I am using polling here.

*if (localCookie == null) {*
                    // Specify the DirSync Control
                    *Control[] ctls = new Control[] { new DirSyncControl() };*
                    ctx.setRequestControls(ctls);
               *} else {*
                    // Specify the DirSync Control with cookie
                    *Control[] ctls = { new DirSyncControl(1, Integer.MAX_VALUE, localCookie, true) };*
                    ctx.setRequestControls(ctls);
               *}*
...................
rspCtls = ctx.getResponseControls();
*if (rspCtls != null) {*
               *for (int i = 0; i < rspCtls.length; i++) {*
                    *if (rspCtls[i] instanceof DirSyncResponseControl) {*
                         *DirSyncResponseControl rspCtl = (DirSyncResponseControl) rspCtls;*
                         localCookie = rspCtl.getCookie();
                    *}*
               *}*
          *}*



The typical problem I am facing here is 2nd iteration onwards the result is not fetching the attribute "sAMAccount".

Please suggest the possible reason and solution.
  • 1. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    796440 Guru
    Currently Being Moderated
    Just FYI, as soon as I saw the word "urgent", I decided not to even look at the actual question.

    Your time management issues are your own, and are not relevant to any question here. Nobody wants to hear about them. Marking your question as urgent tends to make people not want to help you. It may or may not hurt, but it is 100% guaranteed not to help get your question answered any faster.
  • 2. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    EJP Guru
    Currently Being Moderated
    Show the code where you do the polling.
  • 3. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    880240 Newbie
    Currently Being Moderated
    Hi,

    *"The typical problem I am facing here is 2nd iteration onwards the result is not fetching the attribute "sAMAccount".*

    *Please suggest the possible reason and solution."*

    jverd:* I think you have missed the last 2 lines of the post and that is the problem I am facing. This is not a time management issue I have posted. Please suggest any solution if you can.

    EJP:* I am just using Java Scheduling (java.util.Timer) for recurring searches. And 2nd iteration onwards I am using the cookie retrieved from the DirSyncResponseControl of the previous iteration for DirSyncControl (new DirSyncControl(1, Integer.MAX_VALUE, localCookie, true)) to get the differential.

    The problem I am facing is regarding the AD attribute *'sAMAccount'*. On the 1st iteration I am able to get the attribute *'sAMAccount'* for the deleted users. But 2nd iteration onwards the attribute *'sAMAccount'* is not there in the search result.

    I am not sure but it may be the case that as 2nd iteration onwards we are asking for the differential using the cookie from the previous iteration, only the changed attributes are being fetched. Please confirm if I am assuming it right or wrong.

    In both the cases I seek your suggestion to overcome the problem. I need to have the value of the attribute *'sAMAccount'* of deleted users for every iteration.

    Regards,
    Deb
  • 4. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    EJP Guru
    Currently Being Moderated
    So are you going to show the code where you the polling? by which I mean the stuff elided by ... above?
  • 5. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    880240 Newbie
    Currently Being Moderated
    String searchBase = "DC=test,DC=com";
    String searchString = "(&(objectClass=user)(|(givenName=*)(isDeleted=TRUE)))";
    
    String url = "ldap://jbaitest.test.com:389";
    String initCntxtFact = "com.sun.jndi.ldap.LdapCtxFactory";
    String login= "CN=Administrator,CN=Users,DC=TEST,DC=COM";
    String passwd = "welcome@1";
    
    byte[] localCookie = AdPolling.getCookie();
    
    
    try {
        
    
        Hashtable<String, String> env = new Hashtable<String, String>();
    
        env.put(Context.INITIAL_CONTEXT_FACTORY, initCntxtFact);
        env.put(Context.SECURITY_AUTHENTICATION, AdConstant.SECURITY_AUTH_TYPE_SIMPLE);
        env.put(Context.SECURITY_PRINCIPAL, login);
        env.put(Context.SECURITY_CREDENTIALS, passwd);
        env.put(Context.PROVIDER_URL, url);
    
        LdapContext ctx = new InitialLdapContext(env, null);
        SearchControls searchCtls = new SearchControls();
    
        String returnedAtts[] = null;
        searchCtls.setReturningAttributes(returnedAtts);
        searchCtls.setReturningObjFlag(true);
        
        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    
        if (localCookie == null) {
            Control[] ctls = new Control[] { new DirSyncControl() };
            ctx.setRequestControls(ctls);
        } else {
         // Specify the DirSync Control with cookie
         Control[] ctls = { new DirSyncControl(1, Integer.MAX_VALUE, localCookie, true) };
         ctx.setRequestControls(ctls);
        }
    
        NamingEnumeration enumSearchResult = ctx.search(searchBase, searchString, searchCtls);
        AdRestClientConnector adRestCon = populateUsers(enumSearchResult); // Method to get the different  attribute values
    
        rspCtls = ctx.getResponseControls();
    
        if (rspCtls != null) {
    
         for (int i = 0; i < rspCtls.length; i++) {
             if (rspCtls[i] instanceof DirSyncResponseControl) {
              DirSyncResponseControl rspCtl = (DirSyncResponseControl) rspCtls;
              localCookie = rspCtl.getCookie();
    AdPolling.setCookie(localCookie);
         }
    }
    }


    } catch (NamingException e) {
         log.error(AdConstant.ERROR_SEARCHING_DIR_PROBLEM + e);
    } catch (Exception e) {
         log.error(AdConstant.ERROR_SEARCHING_DIR_PROBLEM + e);
    }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  • 6. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    796440 Guru
    Currently Being Moderated
    877237 wrote:
    jverd:* I think you have missed the last 2 lines of the post and that is the problem I am facing.
    I think you missed the part where you said I won't even bother reading any of your question because of the word "urgent." And even if you hadn't marked it urgent, I wouldn't have bothered reading all that annoying bold garbage.
    This is not a time management issue I have posted.
    You marked it as urgent, so you're either lying, or you have a time management problem that you are trying to force onto the forum. That would be inappropriate, as this forum is for solving technical Java problems, not time management problems. Either way, I'm not interested.
  • 7. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    880240 Newbie
    Currently Being Moderated
    jverd:_
    No body is interested to know whether a question posted in the forum is of your interest or not. If you don't want to post helpful reply just don't reply!!!

    I thought it is a professional forum where people would like to know what are the challenges others are facing rather than criticizing or showing attitude to others.

    I must say this is the most un-professionalism I can expect from some one who has been tagged as 'Guru' by the forum.
  • 8. Re: URGENT! I need help on LDAP - Finding deleted users Attribute "sAMAccount"
    796440 Guru
    Currently Being Moderated
    Deb2011 wrote:
    jverd:_
    No body is interested to know whether a question posted in the forum is of your interest or not.
    False. Most people who post here would be interested to know whether people are interested in their question, and would want to do what's necessary to get more people interested in it. Then there are the handful who think that this forum is their own personal servant and that they can just demand whatever they want and people here will have no choice but to give it to them.
    If you don't want to post helpful reply just don't reply!!!
    Not your call. I'll post whatever I want for whatever reasons I want.

    However, you're missing the point that my post was helpful. I gave you advice that will help you get more people interested in reading your post and helping you. If you want to ignore that advice because your feelings got hurt, that's your choice, and your loss.
    I thought it is a professional forum where people would like to know what are the challenges others are facing rather than criticizing or showing attitude to others.

    I must say this is the most un-professionalism I can expect from some one who has been tagged as 'Guru' by the forum.
    Perhaps you could try actually reading what I wrote, and understanding its meaning, rather than looking for ways to get personally offended.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points