Class ConditionalFilter

java.lang.Object
org.forgerock.openig.filter.ConditionalFilter
All Implemented Interfaces:
Filter

public class ConditionalFilter extends Object implements Filter
This filter conditionally executes a delegate Filter given the result of a 'condition' function. If the condition is true then the delegated filter is executed, skipped otherwise.
  • Constructor Details

    • ConditionalFilter

      public ConditionalFilter(Filter delegate, boolean condition)
      Constructs a ConditionalFilter.

      This constructor is provided as an ease to write some code : since you have access to the boolean, you may optimise the code like this :

           
       if (condition) {
          return delegate;
       } else {
          return new Filter() {
             @Override
             public Promise<Response, NeverThrowsException> filter(Context context, Request request, Handler handler) {
                return handler.handle(context, request);
             }
          };
       }
           
       
      Parameters:
      delegate - the filter that will be executed if the condition is true.
      condition - the condition that controls the delegate filter's execution
    • ConditionalFilter

      public ConditionalFilter(Filter delegate, AsyncFunction<ContextAndRequest,Boolean,Exception> condition)
      Constructs a ConditionalFilter.
      Parameters:
      delegate - the filter that will be executed if the condition is true.
      condition - the function that will be executed at each request and will allow or not to execute the delegate filter.
  • Method Details

    • filter

      public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next)
      Description copied from interface: Filter
      Filters the request and/or response of an exchange. To pass the request to the next filter or handler in the chain, the filter calls next.handle(context, request).

      This method may elect not to pass the request to the next filter or handler, and instead handle the request itself. It can achieve this by merely avoiding a call to next.handle(context, request) and creating its own response object. The filter is also at liberty to replace a response with another of its own by intercepting the response returned by the next handler.

      Specified by:
      filter in interface Filter
      Parameters:
      context - The request context.
      request - The request.
      next - The next filter or handler in the chain to handle the request.
      Returns:
      A Promise representing the response to be returned to the client.