Class ConditionalFilter

  • All Implemented Interfaces:
    org.forgerock.http.Filter

    public class ConditionalFilter
    extends Object
    implements org.forgerock.http.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 Detail

      • ConditionalFilter

        public ConditionalFilter​(org.forgerock.http.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 :

             {@code
         if (condition) {
            return delegate;
         } else {
            return new Filter() {
        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​(org.forgerock.http.Filter delegate,
                                 org.forgerock.util.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 Detail

      • filter

        public org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,​org.forgerock.util.promise.NeverThrowsException> filter​(org.forgerock.services.context.Context context,
                                                                                                                                                     org.forgerock.http.protocol.Request request,
                                                                                                                                                     org.forgerock.http.Handler next)
        Specified by:
        filter in interface org.forgerock.http.Filter