[seam-issues] [JBoss JIRA] Created: (SEAMSECURITY-70) Calling RoleManager.removeRole(Roletype rt, User u, Group g) throws an NPE

Charles Louppe (JIRA) jira-events at lists.jboss.org
Wed Jun 1 15:35:00 EDT 2011


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

                 Key: SEAMSECURITY-70
                 URL: https://issues.jboss.org/browse/SEAMSECURITY-70
             Project: Seam Security
          Issue Type: Bug
            Reporter: Charles Louppe


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 :
{code:java}
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);
    }
{code}
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);

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the seam-issues mailing list