My fitler is invoked unexpectedly?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

My fitler is invoked unexpectedly?

Guofeng Zhang
Hi,

My Spring Rest application uses shiro-spring. It configured using Sping Java Config.

I defined an authentication filter and configure only this one filter using ShiroFilterFactoryBean.setFilters() and ShiroFilterFactoryBean.setFilterChainDefinitionMap() using specific url pattern (not using wild pattern match). my application works well.

Then I defined another filter for logout by deriving from LogoutFilter, and call "subject.logout()" from the overrided preHandle(). But I found that even if I only add it to ShiroFilterFactoryBean's filters property, it is invoked when I call a API annotated by @RequiresAuthentication and @RequiresRoles and caused my application failed to work.

I cannot figure out why this logout filter is invoked.

I think a filter is only invoked when the request url matches the url configured for the filter by filterChainDefinitionMap property.

Your help is appreciated.

Thanks,

Guofeng
Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Brian Demers
What does your filter chain definition map look like?

On Sun, Dec 18, 2016 at 6:54 AM, Guofeng Zhang <[hidden email]> wrote:
Hi,

My Spring Rest application uses shiro-spring. It configured using Sping Java Config.

I defined an authentication filter and configure only this one filter using ShiroFilterFactoryBean.setFilters() and ShiroFilterFactoryBean.setFilterChainDefinitionMap() using specific url pattern (not using wild pattern match). my application works well.

Then I defined another filter for logout by deriving from LogoutFilter, and call "subject.logout()" from the overrided preHandle(). But I found that even if I only add it to ShiroFilterFactoryBean's filters property, it is invoked when I call a API annotated by @RequiresAuthentication and @RequiresRoles and caused my application failed to work.

I cannot figure out why this logout filter is invoked.

I think a filter is only invoked when the request url matches the url configured for the filter by filterChainDefinitionMap property.

Your help is appreciated.

Thanks,

Guofeng

Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Guofeng Zhang
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng

Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Brian Demers
Can you include your configuration ?

On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <[hidden email]> wrote:
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng


Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Guofeng Zhang
Here it is:
    @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager());
        ,,,,
        Map<String, Filter> filters = new HashMap<>();
        ....
        filters.put("tokenLogout", TokenLogoutFilter());
        shiroFilter.setFilters(filters);

        return shiroFilter;
    }

Thanks for your support very much.

Guofeng

On Wed, Dec 21, 2016 at 1:26 AM, Brian Demers <[hidden email]> wrote:
Can you include your configuration ?

On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <[hidden email]> wrote:
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng



Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Brian Demers
We probably need to see more of your example, how are you defining your filterChainDefinitionMap ? Which version of Shiro are you using?  Do you have code you can put on github somewhere?


On Wed, Dec 21, 2016 at 6:17 AM, Guofeng Zhang <[hidden email]> wrote:
Here it is:
    @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager());
        ,,,,
        Map<String, Filter> filters = new HashMap<>();
        ....
        filters.put("tokenLogout", TokenLogoutFilter());
        shiroFilter.setFilters(filters);

        return shiroFilter;
    }

Thanks for your support very much.

Guofeng

On Wed, Dec 21, 2016 at 1:26 AM, Brian Demers <[hidden email]> wrote:
Can you include your configuration ?

On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <[hidden email]> wrote:
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng




Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Guofeng Zhang
I did not add "tokenLogout" filter to filterChainDefinitionMap.
If a filter is add to filters, does this mean that it will be invoked for any request, especially whne the filter overrided onPreHandle()?

Thanks again.

On Thu, Dec 22, 2016 at 11:57 PM, Brian Demers <[hidden email]> wrote:
We probably need to see more of your example, how are you defining your filterChainDefinitionMap ? Which version of Shiro are you using?  Do you have code you can put on github somewhere?


On Wed, Dec 21, 2016 at 6:17 AM, Guofeng Zhang <[hidden email]> wrote:
Here it is:
    @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager());
        ,,,,
        Map<String, Filter> filters = new HashMap<>();
        ....
        filters.put("tokenLogout", TokenLogoutFilter());
        shiroFilter.setFilters(filters);

        return shiroFilter;
    }

Thanks for your support very much.

Guofeng

On Wed, Dec 21, 2016 at 1:26 AM, Brian Demers <[hidden email]> wrote:
Can you include your configuration ?

On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <[hidden email]> wrote:
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng





Reply | Threaded
Open this post in threaded view
|

Re: My fitler is invoked unexpectedly?

Brian Demers
Only if it is mapped to a given path

On Sun, Dec 25, 2016 at 2:11 AM, Guofeng Zhang <[hidden email]> wrote:
I did not add "tokenLogout" filter to filterChainDefinitionMap.
If a filter is add to filters, does this mean that it will be invoked for any request, especially whne the filter overrided onPreHandle()?

Thanks again.

On Thu, Dec 22, 2016 at 11:57 PM, Brian Demers <[hidden email]> wrote:
We probably need to see more of your example, how are you defining your filterChainDefinitionMap ? Which version of Shiro are you using?  Do you have code you can put on github somewhere?


On Wed, Dec 21, 2016 at 6:17 AM, Guofeng Zhang <[hidden email]> wrote:
Here it is:
    @Bean(name = "shiroFilter")
    public ShiroFilterFactoryBean shiroFilter() {
        ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
        shiroFilter.setSecurityManager(securityManager());
        ,,,,
        Map<String, Filter> filters = new HashMap<>();
        ....
        filters.put("tokenLogout", TokenLogoutFilter());
        shiroFilter.setFilters(filters);

        return shiroFilter;
    }

Thanks for your support very much.

Guofeng

On Wed, Dec 21, 2016 at 1:26 AM, Brian Demers <[hidden email]> wrote:
Can you include your configuration ?

On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <[hidden email]> wrote:
That's my fault. I should derive from PathMatchingFilter and give it a url pattern by setFilterChainDefinitionMap, then it works as expected.

But I still cannot understand why this filter is invoked even if I do not add it to filterChainDefinitionMap.

Thanks for your response very much.

Guofeng