2 Replies Latest reply on Nov 25, 2011 11:19 AM by bram666

    Seam security: hashcode implementation's

    bram666

      Ola,


      I've been playing with seam security and a active direcotry with database identity storage and notice the following 'bug' when using the 'FallbackIdentityStoreRepository'


      Due to the fact that the hashCode implementations of the IdentityObject's do not return the same result for objects with the same name, type and id the findIdentityObject return results with double entries. The objects are equal though.


      The merging of the identityobjects is done with a hashset (eg line 713 in FallbackIdentityStoreRepository).


      Easy fix is to use the 'SimpleIdentityObject' implementation that comes with picketlink in stead of the seam one (going to test that now) or change the hashcode implementation.


      regards,


      Bram


      PS
      any ideas about the rule's of equals and hashcode of the different implementations of puicketlink? so if i write my own implementations i don't get the same problems? or is this a bug that is a result of a quick/dirty way of merging the different repositories?




      implementations:
      org.picketlink.idm.impl.types.SimpleIdentityObject


         public int hashCode()
         {
            int result = name != null ? name.hashCode() : 0;
            result = 31 * result + (type != null ? type.hashCode() : 0);
            return result;
         }
      



      org.picketlink.idm.impl.model.ldap.LDAPIdentityObjectImpl



         public int hashCode()
         {
            int result = id != null ? id.hashCode() : 0;
            result = 31 * result + (type != null ? type.hashCode() : 0);
            return result;
         }
      



      and the seam security one:
      org.jboss.seam.security.management.IdentityObjectImpl




          public int hashCode() {
              int hash = 0;
              if (id != null) hash ^= (id.hashCode() * 17);
              hash ^= (name.hashCode() * 29) ^ (type.hashCode() * 37);
              return hash;
          }