Description
Mattias Severson (Migrated from SEC-2083) said:
When using annotations to filter collections based, e.g. @PostFilter("hasPermission(filterObject, 'SOME_PERMISSION')")
, the DefaultMethodSecurityExpressionHandler.filter() gets called. The problem with this method is that if the filterTarget
is an immutable list or an immutable set, an exception will thrown (because collection.clear()
is called before the elements in the retainList
are added back to the collection).
One solution to overcome this problem is to implement an "ImmutableMethodSecurityExpressionHandler" by subclassing the DefaultMethodSecurityExpressionHandler
, override the filter()
method if the filterTarget
is of type List
, Set
, or SortedSet
, do the filtering as before, but instead of clearing the existing collection, returning the retainList
wrapped in Collections.unmodifiableList(), Collections.unmodifiableSet() or Collections.unmodifiableSortedSet() respectively.
UPDATE: We should also support Arrays.asList
which is a fixed size collection