Class ReadOnlyUserVariablesFilter

java.lang.Object
com.smartfoxserver.controllers.filter.SysControllerFilter
com.smartfoxserver.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:
  • Constructor Details

    • 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, List<String> varNames)
      Builds a new filter with a list of read-only User Variables names.
      Parameters:
      zone - the Zone
      varNames - the list of variables names
  • Method Details

    • addVariable

      public void addVariable(String varName)
      Add a new User Variable name to be set as read-only
      Parameters:
      varName - the variable name
    • removeVariable

      public void removeVariable(String varName)
      Removes a variable name, rendering the related User Variable readable and writable
      Parameters:
      varName -
    • getFilteredVariables

      public List<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 request
      params - 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: