Multiple Instances of Filter with Different Configurations

27 views
Skip to first unread message

Nicholas Smith

unread,
Jul 25, 2019, 9:43:21 AM7/25/19
to ninja-framework
I have a use-case where we need to register two instances of a filter with different configuration options.  I need to have a "redirectUrl" variable be different for a couple different controller methods that the filter is assigned to. Is it possible to pass options into the filter, or to have the different instances read their configurations from different keys in the application.conf?

In the old version of our java app, we'd register the same filter twice in web.xml with independent configs and then reference them as two different filters in the app. 

For instance:

   <filter>
        <filter-name>FilterA</filter-name>
        <filter-class>filters.AuthFilter</filter-class>
        <init-param>
            <param-name>LoginURL</param-name>
            <param-value>/showcert.aspx</param-value>
        </init-param>
        <init-param>
            <param-name>RedirectURL</param-name>
            <param-value>/welcome</param-value>
        </init-param>
    </filter>

    <filter>
        <filter-name>FilterB</filter-name>
        <filter-class>filters.AuthFilter</filter-class>
        <init-param>
            <param-name>LoginURL</param-name>
            <param-value>/showcert.aspx</param-value>
        </init-param>
        <init-param>
            <param-name>RedirectURL</param-name>
            <param-value>/enroll</param-value>
        </init-param>
    </filter>

Any suggestions to achieve the same capabilities with a ninja filter?


Joe Lauer

unread,
Jul 25, 2019, 10:35:46 AM7/25/19
to ninja-framework
One quick solution would be to extend two unique classes from your parent filter and give each a config prefix string to read from.  Then you'd have two unique classnames to inject or reference in annotations, etc. throughout Ninja.

-Joe

--
You received this message because you are subscribed to the Google Groups "ninja-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ninja-framewo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ninja-framework/a874fbab-612b-40ef-a622-f9feaec0780b%40googlegroups.com.

Lakhi Calantoc

unread,
Jul 25, 2019, 12:02:35 PM7/25/19
to ninja-f...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages