class BasicObjectPermissionArgumentVoter implements AccessDecisionVoter<Object>, AfterInvocationProvider {

    protected Collection<ObjectPermission> getObjectPermissions(Object object) {
        List<ObjectPermission> permissions = new ArrayList<ObjectPermission>();
        if (object instanceof ObjectPermission) {
            permissions.add((ObjectPermission) object);
        } else if (object instanceof Collection) {
            Collection collection = (Collection) object;
            // check only first element for instanceof ObjectPermission because of performance reason
            if (!collection.isEmpty() && collection.iterator().next() instanceof ObjectPermission) {
                // if the first element is ObjectPermission, then let's assume, that the rest are also ;)
                permissions.addAll(collection);
            }
        } else if (object instanceof MethodInvocation) {
            Object[] arguments = ((MethodInvocation) object).getArguments();
            if (arguments != null) {
                for (Object argument : arguments) {
                    // collect all arguments from invocation and check them all
                    permissions.addAll(getObjectPermissions(argument));
                }
            }
        }
        return permissions;
    }

}