Class ReadOnlyUserVariablesFilter
java.lang.Object
com.smartfoxserver.controllers.filter.SysControllerFilter
com.smartfoxserver.controllers.filter.ReadOnlyUserVariablesFilter
- All Implemented Interfaces:
ISystemFilter
This filter can be added to any existing application to provide read-only User Variables.
By providing a list of User Variables names the filter will automatically discard all update/delete requests that match the passed variables list.
This of course affects only client-side requests, while server-side updates will not be subject to filtering. The filter works on a per-Zone basis, so each Zone that requires this feature will need its own filter.
Here's an example of how to initialize the filter inside the Zone Extension:
public class MyExtension extends SFSExtension
{
public void init()
{
// Reset filter chain to clean previous filters
getParentZone().resetSystemFilterChain();
ISystemFilterChain filterChain = new SysControllerFilterChain();
ReadOnlyUserVariablesFilter filter = new ReadOnlyUserVariablesFilter(getParentZone(), Arrays.asList("alpha", "beta"));
filterChain.addFilter("ReadOnlyUserVars", filter);
// Plug the filter chain
getParentZone().setFilterChain(SystemRequest.SetUserVariables, filterChain);
}
public void destroy()
{
super.destroy();
}
}
- Since:
- 2.6.0
- See Also:
-
Field Summary
Fields inherited from class com.smartfoxserver.controllers.filter.SysControllerFilter
logger -
Constructor Summary
ConstructorsConstructorDescriptionBuilds an empty filter.ReadOnlyUserVariablesFilter(Zone zone, List<String> varNames) Builds a new filter with a list of read-only User Variables names. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVariable(String varName) Add a new User Variable name to be set as read-onlyvoidResets the filter: all variable names are removed.handleClientRequest(User sender, ISFSObject params) Handles a client requestvoidremoveVariable(String varName) Removes a variable name, rendering the related User Variable readable and writableMethods inherited from class com.smartfoxserver.controllers.filter.SysControllerFilter
getName, setName, trace, trace
-
Constructor Details
-
ReadOnlyUserVariablesFilter
Builds an empty filter. No variables will be filtered until one or more User Variables names will be specified.- Parameters:
zone- the Zone
-
ReadOnlyUserVariablesFilter
Builds a new filter with a list of read-only User Variables names.- Parameters:
zone- the ZonevarNames- the list of variables names
-
-
Method Details
-
addVariable
Add a new User Variable name to be set as read-only- Parameters:
varName- the variable name
-
removeVariable
Removes a variable name, rendering the related User Variable readable and writable- Parameters:
varName-
-
getFilteredVariables
- Returns:
- a list of User Variables names set as read-only
-
clearFilter
public void clearFilter()Resets the filter: all variable names are removed. -
handleClientRequest
Description copied from interface:ISystemFilterHandles a client request- Parameters:
sender- the sender of the requestparams- the parameters of the request- Returns:
- the action returned determines if the FilterChain can continue its flow or it must stop
- Throws:
SFSException- See Also:
-