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

  • Problem obtaining certain attributes.

    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:

    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 and javax.naming.ldap api's and was successfully extracting this attribute. Here is the code I used for this:

     private DirContext drctx;
    	private Hashtable env;
    	LdapContext ldctx;
    	public LdapUtil() {
    		this.env = new Hashtable();
    		env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
    		env.put(Context.SECURITY_CREDENTIALS, "blahblah");
    		env	.put(Context.PROVIDER_URL,
    	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;
    		} 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, 06: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.


    • #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 methods or to the methods (I'm using LdapOperations)? From what I can see the 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:

      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) {
      		return user;
      my context mapper:
      private class LdapUserContextMapper implements ContextMapper {
      		public Object mapFromContext(Object ctx){
      			DirContextAdapter context = (DirContextAdapter)ctx;
      			LdapUserBean user = new LdapUserBean();
      			/** 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, 05:18 PM.


      • #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).


        • #5
          Thanks Rasky, You are brilliant!

          I changed:

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

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

          thanks again