spring-projects / spring-projects/spring-security

After-invocation ACL providers cannot be used with Hibernate proxies

Open
#13,645 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
CollectionFilterer and the like use a HashSet to store elements to be removed which in turn calls equals() and hashCode(). This implies that a collection of Hibernate proxies would be initialized were they to be filtered out.

In some scenarios where a service method is annotated with @Secured calling another method annotated with @Transactional, this can cause lazy proxy initialization errors because the session is closed already.

Since the elements to remove are the same as those that will be removed later on when the collection is traversed, I suggest replacing this by an identity set.

To Reproduce

@Secured("AFTER_ACL_COLLECTION_READ")
public List<Entity> loadAllEntities(Collection<Long> ids) {
    return ids.stream().map(id -> sessionFactory.getCurrentSession().load()).collect(Collectors.toList());   
}

List<Entity> entities = loadAllEntities();

Expected behavior
Entities are filtered, but should remain uninitialized since only IDs and classes are necessary for applying ACLs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CollectionFilterer and the after-invocation ACL collection filtering path described in the issue, focusing on where elements to remove are stored and compared. Verify the change with Hibernate proxy collections and confirm that ACL filtering removes the expected entities without initializing proxies.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authorization, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.