You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Guofeng Zhang <gu...@gmail.com> on 2016/12/18 14:54:02 UTC
My fitler is invoked unexpectedly?
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
Re: My fitler is invoked unexpectedly?
Posted by Brian Demers <br...@gmail.com>.
Only if it is mapped to a given path
On Sun, Dec 25, 2016 at 2:11 AM, Guofeng Zhang <gu...@gmail.com> 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 <br...@gmail.com>
> 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 <gu...@gmail.com>
>> 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 <br...@gmail.com>
>>> wrote:
>>>
>>>> Can you include your configuration ?
>>>>
>>>> On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <gu...@gmail.com>
>>>> 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
>>>>>
>>>>>
>>>>
>>>
>>
>
Re: My fitler is invoked unexpectedly?
Posted by Guofeng Zhang <gu...@gmail.com>.
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 <br...@gmail.com>
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 <gu...@gmail.com>
> 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 <br...@gmail.com>
>> wrote:
>>
>>> Can you include your configuration ?
>>>
>>> On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <gu...@gmail.com>
>>> 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
>>>>
>>>>
>>>
>>
>
Re: My fitler is invoked unexpectedly?
Posted by Brian Demers <br...@gmail.com>.
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 <gu...@gmail.com> 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 <br...@gmail.com>
> wrote:
>
>> Can you include your configuration ?
>>
>> On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <gu...@gmail.com>
>> 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
>>>
>>>
>>
>
Re: My fitler is invoked unexpectedly?
Posted by Guofeng Zhang <gu...@gmail.com>.
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 <br...@gmail.com>
wrote:
> Can you include your configuration ?
>
> On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <gu...@gmail.com>
> 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
>>
>>
>
Re: My fitler is invoked unexpectedly?
Posted by Brian Demers <br...@gmail.com>.
Can you include your configuration ?
On Mon, Dec 19, 2016 at 5:43 PM, Guofeng Zhang <gu...@gmail.com> 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
>
>
Re: My fitler is invoked unexpectedly?
Posted by Guofeng Zhang <gu...@gmail.com>.
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
Re: My fitler is invoked unexpectedly?
Posted by Brian Demers <br...@gmail.com>.
What does your filter chain definition map look like?
On Sun, Dec 18, 2016 at 6:54 AM, Guofeng Zhang <gu...@gmail.com> 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
>