Q:

Geoserver and Geofence - using custom rules

I've checked all the options of the rule creation in GeoFence Embedded (integrated with GeoServer) and GeoFence Standalone web application. The available options for building data access rules seem to be limited to: username, user's role, service name, request name, workspace and layer. The additional option is to limit the access with the geographical area.
Is there a way, using GeoServer and GeoFence, to make rules more specific, as in the following examples:  

Restricting access to a group of features from a layer, which belong to the selected bigger layer (show only cities from a selected state)  
Using CQL expressions in GeoFence rules with system variables (showing only features from a layer which have in one attribute the username of the logged-in, using GeoFence authenticator, user)

A:

Rules can also filter by the caller's IP address, as described here:
https://github.com/geoserver/geofence/wiki/Main-concepts#rules

you can restrict the set of returned features by using a CQL filter. Once you define a layer in a rule, the "detail" button will become active. Pressing it, a dialog will be displayed where various settings can be set for the rule. Among these, there is a textarea where you can enter the CQL filter. More info here: https://github.com/geoserver/geofence/wiki/Main-concepts#constraints.
the CQL string is reported as-is to GeoServer, and no parsing or token substitution is performed on it.

