Jetspeed 2
  1. Jetspeed 2
  2. JS2-1031

Ldap AttributeBasedRelationDAO class gets NullPointerException when trying to create a relation between two ldap entities

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: 2.2.1
    • Component/s: LDAP
    • Labels:
      None
    • Environment:
      Windows XP, JRE 1.6.0.11, Tomcat 6.0.18, Apache DS 1.0.2

      Description

      AttributeBasedRelationDAO class gets NullPointerException when trying to create a relation between two ldap entities. StackTrace is as follows:

      -----------------------------------------------------------------------------------------------------------------------------
      SEVERE: Servlet.service() for servlet JetspeedContainer threw exception
      java.lang.NullPointerException
      at org.apache.jetspeed.security.mapping.ldap.dao.impl.AttributeBasedRelationDAO.internalAddRelation(AttributeBasedRelationDAO.java:165)
      at org.apache.jetspeed.security.mapping.ldap.dao.impl.AttributeBasedRelationDAO.addRelation(AttributeBasedRelationDAO.java:230)
      at org.apache.jetspeed.security.mapping.ldap.dao.DefaultLDAPEntityManager.addRelation(DefaultLDAPEntityManager.java:88)
      at org.apache.jetspeed.security.spi.impl.JetspeedPrincipalLdapAssociationStorageManager.addAssociation(JetspeedPrincipalLdapAssociationStorageManager.java:56)
      ...more
      -----------------------------------------------------------------------------------------------------------------------------

      To fix the problem AttributeBasedRelationDAO class line 164 (internalAddRelation method body) should be changed from:
      --------------------------------------------
      if(relationAttribute == null)

      { fromEntity.setAttribute(this.relationAttribute,new ArrayList<String>()); }

      --------------------------------------------
      to:
      --------------------------------------------
      if (relationAttribute == null)

      { fromEntity.setAttribute(this.relationAttribute, new ArrayList<String>()); relationAttribute = fromEntity.getAttribute(this.relationAttribute); }

      --------------------------------------------

      Just setting the attribute leaves relationAttribute NULL, causing the NPE.

        Activity

        Hide
        Ate Douma added a comment -

        Fixed by adding a new method Entity.getAttribute(String name, boolean create) which can automatically add an attribute of the right type (multi or single value).

        Show
        Ate Douma added a comment - Fixed by adding a new method Entity.getAttribute(String name, boolean create) which can automatically add an attribute of the right type (multi or single value).
        Hide
        Aysegul Aydin Isiktekin added a comment -

        Suggested solution to the problem fixes the problem for only multi-valued attributes since if the attribute is not a multi-valued attribute setAttribute method returns without setting the attribute. So for fixing the problem I have written this:

        --------------------------------------------
        if (relationAttribute == null)
        {
        fromEntity.setAttribute(this.relationAttribute, new ArrayList<String>());
        relationAttribute = fromEntity.getAttribute(this.relationAttribute);
        if(relationAttribute == null)

        { fromEntity.setAttribute(this.relationAttribute, attrValue); relationAttribute = fromEntity.getAttribute(this.relationAttribute); }

        }
        --------------------------------------------

        It's not a good solution so maybe you should consider a better solution. I need LDAP integration to continue the implementation of our project so i choose quick-and-dirty

        Show
        Aysegul Aydin Isiktekin added a comment - Suggested solution to the problem fixes the problem for only multi-valued attributes since if the attribute is not a multi-valued attribute setAttribute method returns without setting the attribute. So for fixing the problem I have written this: -------------------------------------------- if (relationAttribute == null) { fromEntity.setAttribute(this.relationAttribute, new ArrayList<String>()); relationAttribute = fromEntity.getAttribute(this.relationAttribute); if(relationAttribute == null) { fromEntity.setAttribute(this.relationAttribute, attrValue); relationAttribute = fromEntity.getAttribute(this.relationAttribute); } } -------------------------------------------- It's not a good solution so maybe you should consider a better solution. I need LDAP integration to continue the implementation of our project so i choose quick-and-dirty

          People

          • Assignee:
            Ate Douma
            Reporter:
            Aysegul Aydin Isiktekin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development