Class ReadOnlyUserVariablesFilter
- java.lang.Object
-
- com.smartfoxserver.v2.controllers.filter.SysControllerFilter
-
- com.smartfoxserver.v2.controllers.filter.ReadOnlyUserVariablesFilter
-
- All Implemented Interfaces:
ISystemFilter
public class ReadOnlyUserVariablesFilter extends SysControllerFilter
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:
SysControllerFilter
,SysControllerFilterChain
-
-
Field Summary
-
Fields inherited from class com.smartfoxserver.v2.controllers.filter.SysControllerFilter
logger
-
-
Constructor Summary
Constructors Constructor Description ReadOnlyUserVariablesFilter(Zone zone)
Builds an empty filter.ReadOnlyUserVariablesFilter(Zone zone, java.util.List<java.lang.String> varNames)
Builds a new filter with a list of read-only User Variables names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addVariable(java.lang.String varName)
Add a new User Variable name to be set as read-onlyvoid
clearFilter()
Resets the filter: all variable names are removed.java.util.List<java.lang.String>
getFilteredVariables()
FilterAction
handleClientRequest(User sender, ISFSObject params)
Handles a client requestvoid
removeVariable(java.lang.String varName)
Removes a variable name, rendering the related User Variable readable and writable-
Methods inherited from class com.smartfoxserver.v2.controllers.filter.SysControllerFilter
getName, setName, trace, trace
-
-
-
-
Constructor Detail
-
ReadOnlyUserVariablesFilter
public ReadOnlyUserVariablesFilter(Zone zone)
Builds an empty filter. No variables will be filtered until one or more User Variables names will be specified.- Parameters:
zone
- the Zone
-
ReadOnlyUserVariablesFilter
public ReadOnlyUserVariablesFilter(Zone zone, java.util.List<java.lang.String> varNames)
Builds a new filter with a list of read-only User Variables names.- Parameters:
zone
- the ZonevarNames
- the list of variables names
-
-
Method Detail
-
addVariable
public void addVariable(java.lang.String varName)
Add a new User Variable name to be set as read-only- Parameters:
varName
- the variable name
-
removeVariable
public void removeVariable(java.lang.String varName)
Removes a variable name, rendering the related User Variable readable and writable- Parameters:
varName
-
-
getFilteredVariables
public java.util.List<java.lang.String> 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
public FilterAction handleClientRequest(User sender, ISFSObject params) throws SFSException
Description copied from interface:ISystemFilter
Handles 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:
FilterAction
-
-