Announcement Announcement Module
Collapse
No announcement yet.
After searching usind a DN the Context.getDn() is empty Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • After searching usind a DN the Context.getDn() is empty

    I have a method for looking up a group based on the dn passed in as a key:

    Code:
    public LDAPGroup getGroup(String key) {
    		LDAPGroup group=null;
    		Name dnKey = new DistinguishedName(key);
    		List returnList = ldapTemplate.search(dnKey ,"objectClass=*", getContextMapper());
    		if(returnList.size()>0) {
    			group = (LDAPGroup)(LDAPGroup)returnList.iterator().next();
    		} else {
    			return null;
    		}
    		getMembersDetails(returnList);
    		
    		return group;
    		
    	}
    in my context mapper I am calling the getDN() method, buut the result is empty, when done iwth a normal query this is fine. I can only assume that it has something to do with me using the dn as the base for the search?

    here is the method in the contructor of the context mapper:

    Code:
        public LDAPGroup(DirContextAdapter ctx) throws NamingException {
            hashMap = new HashMap();
            int i=0;
            HashMap membersMap = new HashMap();
            NamingEnumeration nePerson = ctx.getAttributes().getAll();
            NamingEnumeration memberList = null;
             
            while (nePerson.hasMoreElements()) {
                Attribute attribute = (Attribute) nePerson.nextElement();
                String value;
                if (attribute.get() == null) {
                    value = "";
                    hashMap.put(attribute.getID().toLowerCase(), value);
                } else {
                	if(attribute.getID().equalsIgnoreCase("uniquemember")) {
                		memberList = (NamingEnumeration)attribute.getAll(); 		
                	} else {
                		String name=attribute.getID().toLowerCase();
                		value = value = attribute.get().toString();
                		hashMap.put(attribute.getID().toLowerCase(), value);
                	}
                } 
            }
    		
    -->>		setDn(ctx.getDn().toString()); <<--
                   while(memberList.hasMoreElements()) {
            	String dn = (String)memberList.nextElement();
            	//membersMap.put(dn,getMembersDetails(getUIDFromDN(dn),getOFromDN(dn)));
            	
    			membersMap.put(dn,dn);
    		}     
            hashMap.put("uniquemember", membersMap);
    
        }
    Last edited by ma_crice; Jun 5th, 2007, 10:38 AM.

  • #2
    First of all, please use the 'code' tags and format the code properly when posting code. It makes it so much easier to read the code.

    Basically, it seems like you're trying to do a lookup, not a search. For that purpose you should use one of the lookup() methods in LdapTemplate. Using the lookup method you should get the expected DN from get getDn() method.

    In a search, you will get the DN relative to the search base from the getDn() method of DirContextAdapter, i.e. if it is the same node that was used as base you will get an empty DN. To get the full DN of the entry, use the getNameInNamespace() method.

    Also, you can use the DirContextAdapter much more efficiently than in your sample. For example, to get a hold of all values of a single attribute you should use the getStringAttributes() method, which will return the attribute values as a String array. That will save you from a log of Attribute technicalities.

    Comment

    Working...
    X