Uploaded image for project: 'Seam Security'
  1. Seam Security
  2. SEAMSECURITY-70

Calling RoleManager.removeRole(Roletype rt,User u, Group g) throws an NPE

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0.Beta1
    • Labels:
      None

      Description

      Hi,

      I tried to use the function removeRole(Roletype rt,User u, Group g) of the class RoleManagerImpl which throws me an NullPointerException.

      I have fixed the bug, which was in the class JPAIdentityStore in the method removeRelationship :

      public void removeRelationship(IdentityStoreInvocationContext ctx,
                                         IdentityObject fromIdentity, IdentityObject toIdentity,
                                         IdentityObjectRelationshipType relationshipType,
                                         String relationshipName) throws IdentityException {
              Property<?> fromProperty = modelProperties.get(PROPERTY_RELATIONSHIP_FROM);
              Property<?> toProperty = modelProperties.get(PROPERTY_RELATIONSHIP_TO);
              Property<?> relationshipTypeProp = modelProperties.get(PROPERTY_RELATIONSHIP_TYPE);
      
              EntityManager em = getEntityManager(ctx);
      
              CriteriaBuilder builder = em.getCriteriaBuilder();
              CriteriaQuery<?> criteria = builder.createQuery(identityClass);
              Root<?> root = criteria.from(identityClass);
      
              List<Predicate> predicates = new ArrayList<Predicate>();
              predicates.add(builder.equal(root.get(fromProperty.getName()),
                      lookupIdentity(fromIdentity, em)));
              predicates.add(builder.equal(root.get(toProperty.getName()),
                      lookupIdentity(toIdentity, em)));
              predicates.add(builder.equal(root.get(relationshipTypeProp.getName()),
                      lookupRelationshipType(relationshipType, em)));
      
              criteria.where(predicates.toArray(new Predicate[predicates.size()]));
      
              Object relationship = em.createQuery(criteria).getSingleResult();
              em.remove(relationship);
          }
      

      The bug is due to those following lines :
      CriteriaQuery<?> criteria = builder.createQuery(identityClass);
      Root<?> root = criteria.from(identityClass);
      It should be instead :
      CriteriaQuery<?> criteria = builder.createQuery(relationshipClass);
      Root<?> root = criteria.from(relationshipClass);

        Attachments

          Activity

            People

            Assignee:
            lightguard Jason Porter
            Reporter:
            poulpe Charles Louppe (Inactive)
            Archiver:
            samahaja Sagar Mahajan

              Dates

              Created:
              Updated:
              Resolved:
              Archived: