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

  • Problem Accessing AttributeDeffinition

    Hi I have recently been working on our Directory and have been trying to increase the features. One of the areas I am working is LDAP Group management. I am currently working on the code to lookup people to groups but have come accross a problem when trying to get the AttributeDeffinitions from the attributes that I have in my naming enumeration. What I am trying to do is check if the Attribute I have is a multi-value or single. For the time being I am assuming a value based on a given name is a multiple value, but this means that my code has to be very specific. the code in my Context Mapper calls a bean that has a contructor that will iterate through the Naming Enumeration and set the values Here is the code for the constructor:

    public LDAPGroup(NamingEnumeration nePerson) throws NamingException {
    hashMap = new HashMap();
    int i=0;
    HashMap membersMap = new HashMap();
    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 {
    Hashtable m = attribute.getAttributeDefinition().getEnvironment( );
    for(Iterator itr = m.keySet().iterator();itr.hasNext() {
    String key =(String)itr.next();
    System.out.println("Key: "+key+" - Value: "+m.get(key));
    }
    if(attribute.getID().equalsIgnoreCase("uniquemembe r")) {
    memberList = (NamingEnumeration)attribute.getAll();
    } else {
    value = attribute.get().toString();
    hashMap.put(attribute.getID().toLowerCase(), value);
    }
    }
    }
    while(memberList.hasMoreElements()) {
    String dn = (String)memberList.nextElement();
    //membersMap.put(dn,getMembersDetails(getUIDFromDN(d n),getOFromDN(dn)));

    membersMap.put(dn,dn);
    }
    hashMap.put("uniquemember", membersMap);

    }

    The line that breaks is: Hashtable m = attribute.getAttributeDefinition().getEnvironment( );

    This gives me the following stacktrace:

    [20/04/07 09:40:13:773 BST] 628efecf SystemOut O [County Directory] ERROR [Servlet.Engine.Transports : 2] GroupDaoImpl.mapFromContext(207) | mapFromContext(Object) - exception ignored
    javax.naming.NamingException: problem generating object using object factory. Root exception is
    org.springframework.ldap.BadLdapGrammarException: Failed to parse DN; nested exception is org.springframework.ldap.support.TokenMgrError: Lexical error at line 1, column 5. Encountered: ":" (58), after : ""
    org.springframework.ldap.support.TokenMgrError: Lexical error at line 1, column 5. Encountered: ":" (58), after : ""
    at org.springframework.ldap.support.DnParserImplToken Manager.getNextToken(DnParserImplTokenManager.java :693)
    at org.springframework.ldap.support.DnParserImpl.jj_c onsume_token(DnParserImpl.java:223)
    at org.springframework.ldap.support.DnParserImpl.Spac edEquals(DnParserImpl.java:118)
    at org.springframework.ldap.support.DnParserImpl.attr ibuteTypeAndValue(DnParserImpl.java:98)
    at org.springframework.ldap.support.DnParserImpl.rdn( DnParserImpl.java:62)
    at org.springframework.ldap.support.DnParserImpl.dn(D nParserImpl.java:27)
    at org.springframework.ldap.support.DistinguishedName .parse(DistinguishedName.java:130)
    at org.springframework.ldap.support.DistinguishedName .<init>(DistinguishedName.java:89)
    at org.springframework.ldap.support.DirContextAdapter .<init>(DirContextAdapter.java:131)

    Also on a slightly different note, does anyone know if there is a way to retrieve the DN from the Attribute?

  • #2
    Resolution to this?

    Were you able to sort this one out?

    We have seen this same error and have been struggling with figuring out why. One of our customers has this problem, however we can not replicate the issue.

    Comment


    • #3
      Still no joy

      I still haven't managed to solve this issue. What LDAP Server Implementation is your customer using. I had a suspicion that it might be to do with the functionality not being abalable in a standard way in the implementation I am using, but have'nt been able to find any documentation to support this idea. What information are you wanting to get from the AttributeDefinition?

      Comment


      • #4
        This seems to have something to do with DefaultDirObjectFactory, which evidently (this is nothing I've ever tried myself) intercepts when you try to get your Attribute definition. That's logical as the return value of getAttributeDefinition() is a DirContext, which would prompt the LDAP provider to invoke DirObjectFactory to get the actual instance to return.

        The problem is that DefaultDirObjectFactory isn't designed to work with anything else than ordinary nodes in the LDAP tree, nodes that have a Distinguished Name as identifier. It seems that the Name of the DirContext returned by getAttributeDefinition() is not a DistinguishedName, which is what causes the code to crash.

        As I see it there's probably two solutions to this problem.

        One is that you disable the DirObjectFactory stuff (AbstractContextSource#setDirObjectFactory()), which will prevent you from working effectively with ContextMappers as the objects supplied to these will no longer be DirContextAdapters.

        The other solution would be that you make your own DirObjectFactory implementation to make this work, e.g. one that wraps DefaultDirObjectFactory and checks first if there's something particular with the DirContest instance (and more specifically - the name of that instance), and passes the responsibility on to the DefaultDirObjectFactory if it's a normal case.

        If you happen to come up with something useful and would like to share, we'd probably be most interested.

        Cheers,

        Comment


        • #5
          Please see this post for future details:
          http://forum.springframework.org/showthread.php?t=39132

          Comment

          Working...
          X