Announcement Announcement Module
Collapse
No announcement yet.
Problem obtaining certain attributes. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem obtaining certain attributes.

    Hello,
    I am using a contextMapper to get attributes for a bean class called LdapUserBean. One of the attributes that I wish to get is an attribute called nsuniqueid which is just a Directory String that is unique to any given user. I am successfully getting other attributes ("mail", "cn", "uid") but when it comes to nsuniqueid I get a null value. I also noticed when I do this:

    Code:
    Attributes att = context.getAttributes();
    This also does not get the nsuniqueid attribute. I also tried using context.getObjectAttribute and that didn't work as well.

    Before I new about Spring-Ldap I was just using the javax.naming.directory and javax.naming.ldap api's and was successfully extracting this attribute. Here is the code I used for this:

    Code:
     private DirContext drctx;
    	private Hashtable env;
    	LdapContext ldctx;
    
    
    	public LdapUtil() {
    		this.env = new Hashtable();
    		env.put(Context.INITIAL_CONTEXT_FACTORY,
    						"com.sun.jndi.ldap.LdapCtxFactory");
    		env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
    		env.put(Context.SECURITY_CREDENTIALS, "blahblah");
    		env	.put(Context.PROVIDER_URL,
    						"ldap://persona.ed.usu.edu:389/ou=Individuals,ou=Agents,dc=ed,dc=usu,dc=edu");
    	}
    
    
    	public String getUniqueId(String user) {
    		String[] attrIDs = {"nsuniqueid"};
    		String lookup = "uid=" + user;
    		String uniqueId = "";
    		try {
    			drctx = new InitialDirContext(env);
    			Attributes att = drctx.getAttributes(lookup, attrIDs);
    			Object b = att.get("nsuniqueid").get();
    			uniqueId = (String) b;
    			drctx.close();
    		} catch (NamingException e) {
    			System.out.println("Lookup failed: " + e);
    		}
    		return uniqueId;
    	}
    Any advice or insights here would be helpful. thanks

    Tyler Perkins
    Last edited by tylerperkins; Mar 20th, 2010, 07:23 PM.

  • #2
    There are a couple of possibilities why this might happen. My first guess would be that the attribute you are trying to access is operational, which means that it will not be returned unless explicitly asked for. In that case you'll need to use one of the search methods that take the names of the attributes to return.

    The other possibility I can think of is that it might be an access problem due to limited read permissions. That seems much less likely though.

    Comment


    • #3
      Rasky wrote:

      In that case you'll need to use one of the search methods that take the names of the attributes to return.
      Are you referring to the DirContextAdapter.search methods or to the LdapOperations.search methods (I'm using LdapOperations)? From what I can see the DirContextAdapter.search methods have not been implemented yet.

      Should I be using LdapTemplate instead?

      I failed to show you in my first post the section of code where I am attempting to retrieve this attribute. Here it is:

      Code:
      public LdapUserBean getUserByUID(String uid) throws BatonException {
      		LdapUserBean user = null;
      		
      		try {
      			DistinguishedName dn = buildDN(uid);
      			user = (LdapUserBean) ldapOperations.lookup(dn, new LdapUserContextMapper());
      			
      		} catch (EntryNotFoundException e) {
      			System.out.println(e.toString());
      		}
      		return user;
      	}
      my context mapper:
      Code:
      private class LdapUserContextMapper implements ContextMapper {
      
      		public Object mapFromContext(Object ctx){
      			DirContextAdapter context = (DirContextAdapter)ctx;
      			
      			LdapUserBean user = new LdapUserBean();
      			user.setEmail(context.getStringAttribute("mail"));
      			user.setFullName(context.getStringAttribute("cn"));
      			user.setUid(context.getStringAttribute("uid"));
      			
      			/** Here is where I am trying to set the nsuniqueid attribute.**/
      			user.setUniqueId(/** nsuniqueid **/);
      			
      			return user;
      		}
      	}
      Tyler Perkins
      Last edited by tylerperkins; Jan 3rd, 2007, 06:18 PM.

      Comment


      • #4
        Sorry for being unclear. You should perform your search using one of the methods in LdapOperations/LdapTemplate that take attribute names as parameters (it's basically the same thing; LdapTemplate is the implementation of LdapOperations).

        Comment


        • #5
          Thanks Rasky, You are brilliant!

          I changed:

          Code:
          user = (LdapUserBean) ldapOperations.lookup(dn, new LdapUserContextMapper());
          to

          Code:
          user = (LdapUserBean) ldapOperations.lookup(dn, new String []{"uid", "cn", "nsuniqueid", "mail"}, new LdapUserContextMapper());
          and it worked wonderfully.

          thanks again

          Comment

          Working...
          X