I got into the same problem too, and I don't think there is a simple answer.
I think there are only two solutions. The one you proposed that has the performance problems that you described, since you need to download documents and enable ACLs for each result, and then do your own paging. An alternative is to push this work on the index side and index your ACL in Lucene. This gives you search results, hiding results that the user cannot see, adding filtering conditions based on the current user / group / permissions / roles, but by maintaining an index with ACL information. If your ACL is simple, this might be an option. If your ACL is hierarchical, then it is still an option, but more complex. It’s also hard to keep your index up to date with ACLs.
The fact that you are starting to learn this functionality may indicate that you are starting to stretch the Database / Hibernate / Lucene solution. Maybe a content repository like Jackrabbit might be a better fit? I guess this is probably too far away, but it might be worth a look at how he does it. Alternatively, take a look at SOLR, in particular issue , which describes what a thorny problem is.
pauli source share