You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by "rama.casturi" <ra...@gmail.com> on 2012/04/09 23:12:13 UTC
Sessions from different filters interfering with each other
Hi,
Here is a shiro filter configuration that I am trying and I believe sessions
created for the two form filters are interfering with each other.
<bean id="shiroFilter"
class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager" />
<property name="filterChainDefinitions">
<value>
/foo/**/** = fooFilter
/bar/**/** = barFilter
</value>
</property>
</bean>
<bean id="fooFilter"
class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">
<property name="loginUrl" value="/foo/login" />
</bean>
<bean id="barFilter"
class="org.apache.shiro.web.filter.authc.FormAuthenticationFilter">
<property name="loginUrl" value="/bar/login" />
</bean>
<bean id="sessionManager"
class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
</bean>
<bean id="securityManager"
class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realms">
<util:set>
<ref bean="fooPagesAuthorizingRealm"/>
<ref bean="barPagesAuthorizingRealm"/>
</util:set>
</property>
</bean>
*// This realm authenticate against users in one database*
<bean id="fooPagesAuthorizingRealm"
class="com.xyz.FooPagesAuthorizingRealm">
<property name="credentialsMatcher"
ref="hashedPasswordMatcher" />
</bean>
*// This realm authenticate against users in a different database
from the above*
<bean id="barPagesAuthorizingRealm"
class="com.xyz.FooPagesAuthorizingRealm">
<property name="credentialsMatcher"
ref="hashedPasswordMatcher" />
</bean>
In the above configuration, all /foo/**/** urls are supposed to be
accessible only to a certain set of users, and /bar/**/** urls are
accessible to a different set of users.
What I am seeing though is, a user who logs to /foo/login successfully is
able to access any of the /bar/**/** urls. I guess this is because the
session that is created for this user when he logged into /foo/login is
letting him access the /bar/**/** urls as well.
Is this a bug or am I doing something wrong in my example? This is a valid
scenario in my application. Any help is appreciated.
Thanks
Rama
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7451046.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by Jared Bunting <ja...@peachjean.com>.
It certainly seems workable. That is basically what I described in #2.
On May 10, 2012 3:47 PM, "rama.casturi" <ra...@gmail.com> wrote:
> Thanks Jared.
>
> I suppose the problem is with depending on the container to provide session
> management. Could this be solved if I use Shiro's native session maangement
> instead of defaulting to container managed sessions? In that case, I could
> probably set up two different security managers and associate one each to
> the two filters that manage access to their set of URLs. Is this workable?
>
> Rama
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7548299.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>
Re: Sessions from different filters interfering with each other
Posted by "rama.casturi" <ra...@gmail.com>.
Thanks Jared.
I suppose the problem is with depending on the container to provide session
management. Could this be solved if I use Shiro's native session maangement
instead of defaulting to container managed sessions? In that case, I could
probably set up two different security managers and associate one each to
the two filters that manage access to their set of URLs. Is this workable?
Rama
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7548299.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by Jared Bunting <ja...@peachjean.com>.
I think it is an uncommon use case. Most of the time, if I'm building
to completely unrelated web applications, that users are required to
have different sessions to log into, I will make it 2 webapps. I can
think of a few ways to make this work.
1. What Jonathan originally suggested. Using a role to distinguish
between the two.
2. Setting up two entirely different security managers. This would
require a custom EnvironmentLoaderListener (to store the second
SecurityManager in a different attribute in the ServletContext). It
would also require a custom ShiroFilter to store retrieve the second
SecurityManager from the servlet context. And then you would need to
use native (as opposed to container-based) sessions, and use a custom
version of DefaultWebSessionManager to set a different name for the
session cookie.
In general, shiro is not designed to run two completely separate
security setups in the same web application. This was actually
discussed as part of 1.2.0 and the EnvironmentLoaderListener.
I suggest the roles.
-Jared
On Thu 03 May 2012 12:49:54 PM CDT, rama.casturi wrote:
> If this is an uncommon use case, can anyone throw some light on how would I
> be able to resolve/re-design this? I am constrained by having a single
> webapp. Is there a workaround to this in Shiro?
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7524562.html
> Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by "rama.casturi" <ra...@gmail.com>.
If this is an uncommon use case, can anyone throw some light on how would I
be able to resolve/re-design this? I am constrained by having a single
webapp. Is there a workaround to this in Shiro?
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7524562.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by sh...@xoxy.net.
Section 7.3 of the servlet specification defines the scope of the session
to be that of the application/servlet context, so this does appear to be an
uncommon use case.
On Thu, Apr 19, 2012 at 1:23 PM, rama.casturi - rama.casturi@gmail.com
<+s...@spamgourmet.com>wrote:
> Thanks again Jonathan.
>
> I guess the question is, is this not a common use case? Is my use case and
> its design flawed? I am asking that because if Shiro does not support it
> out
> of the box, they did not think it to be a common use case.
>
> Anyways, I guess it is not so much WHICH realm authenticated you, but the
> value of JSESSIONID having some context (the url path maybe) and the
> validation of that value (by the security/session manager) being done based
> on that context. Even if we have two different filters for the two url
> paths, there is still only one security and session manager in the entire
> app. To me that seems the basic problem.
>
> Rama
>
> --
> View this message in context:
> http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7481506.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>
>
Re: Sessions from different filters interfering with each other
Posted by "rama.casturi" <ra...@gmail.com>.
Thanks again Jonathan.
I guess the question is, is this not a common use case? Is my use case and
its design flawed? I am asking that because if Shiro does not support it out
of the box, they did not think it to be a common use case.
Anyways, I guess it is not so much WHICH realm authenticated you, but the
value of JSESSIONID having some context (the url path maybe) and the
validation of that value (by the security/session manager) being done based
on that context. Even if we have two different filters for the two url
paths, there is still only one security and session manager in the entire
app. To me that seems the basic problem.
Rama
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7481506.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by Jonathan Barker <jo...@gmail.com>.
By same thing, I meant the security services, not the application.
The roles approach seemed the easy way. What you really seem to be
looking for is a security filter that discriminates based on WHICH
realm authenticated you, which would seem like an extension to the
authc filter that takes a parameter - the name/class of the realm.
On Thu, Apr 19, 2012 at 2:02 AM, rama.casturi <ra...@gmail.com> wrote:
> Thanks Jonathan. I kind of figured that using roles to restrict access is the
> way to go, but I want to find a solution for the scenario the way I
> described it.
>
> The fact is the two entry points are NOT into the same thing, but two
> different apps (although they reside in the same webapp), each with its own
> set of url paths and user base.
>
> Is it not possible for each set of users to be authenticated separately
> based on logins for each set of urls? I was hoping this would be a somewhat
> common use case.
>
> Rama
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7479475.html
> Sent from the Shiro User mailing list archive at Nabble.com.
--
Jonathan Barker
ITStrategic
Re: Sessions from different filters interfering with each other
Posted by "rama.casturi" <ra...@gmail.com>.
Thanks Jonathan. I kind of figured that using roles to restrict access is the
way to go, but I want to find a solution for the scenario the way I
described it.
The fact is the two entry points are NOT into the same thing, but two
different apps (although they reside in the same webapp), each with its own
set of url paths and user base.
Is it not possible for each set of users to be authenticated separately
based on logins for each set of urls? I was hoping this would be a somewhat
common use case.
Rama
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7479475.html
Sent from the Shiro User mailing list archive at Nabble.com.
Re: Sessions from different filters interfering with each other
Posted by Jonathan Barker <jo...@gmail.com>.
The behaviour is what I would expect. Whichever filter you go
through, you are authenticated. Done. You've just defined two entry
points to the same thing.
What you might want to do is to have one realm always add a ROLE_FOO
to the user, and the other to add ROLE_BAR, and then use the roles to
determine access to the /bar/ and /foo/ sections.
On Thu, Apr 19, 2012 at 12:59 AM, rama.casturi <ra...@gmail.com> wrote:
> Just pinging again to see if anyone has insight into this. I have dug enough
> into the code, but to no avail. Hope someone can help!
>
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7479374.html
> Sent from the Shiro User mailing list archive at Nabble.com.
--
Jonathan Barker
ITStrategic
Re: Sessions from different filters interfering with each other
Posted by "rama.casturi" <ra...@gmail.com>.
Just pinging again to see if anyone has insight into this. I have dug enough
into the code, but to no avail. Hope someone can help!
--
View this message in context: http://shiro-user.582556.n2.nabble.com/Sessions-from-different-filters-interfering-with-each-other-tp7451046p7479374.html
Sent from the Shiro User mailing list archive at Nabble.com.