You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Tamás Cservenák <ta...@cservenak.net> on 2011/02/23 13:19:13 UTC
Sessions + REST
Howdy,
I was just wondering, wrt our issue brought up on this list (and a
nice followups) regarding Sessions in RESTful applications.
That thread provided a nice solution too:
http://shiro-user.582556.n2.nabble.com/Sessions-and-REST-td6036008.html
Also, Les mentioned the SHIRO-266 issue too, that will address this in future.
But, these discussions above covers applications that are "this or
that" (black or white) only. As we know, the culprit of initial issue
was stateless clients! Clients like Maven, wget, some script, etc
(stateless clients) usually does not handle Cookies, so the session
created by Shiro, and it's ID sent back to stateless client is unused
completely. And this is not uncommon thing (using stateless clients).
Hence, we started thinking about some "hybrid" solution (and it's
maybe covered by SHIRO-266 or maybe not), to allow Business Logic (the
app integrating Shiro) to decide, whether a Session is not needed (in
100% RESTful apps, or when you _know_ the client is stateless) or is
needed (the usual "human" interaction over a UI or such).
We had a discussion about this yesterday, and concluded that the best
solution for app like Nexus (which is RESTful, but we want to relax it
stateless nature for some human interactions for better usability)
would be a solution like this.
Simply, when we _know_ it is a human user accessing Nexus, create and
maintain "normal" sessions (not those per-request sessions mentioned
in thread above), and when we _know_ it is non-human interacting with
Nexus, don't bother with Sessions at all, be 100% strict RESTful. Just
enforce every request carries authc info as REST defines.
Any thoughts?
Thanks,
~t~
Re: Sessions + REST
Posted by Les Hazlewood <lh...@apache.org>.
Hi Tamás,
This makes sense to me.
At the moment there are only 2 places where Shiro itself will
explicitly use the session:
1. during login, to save the authentication state (this is what
SHIRO-266 is expected to address)
2. during 'runAs' operations - to save the identity 'stack' to be
able to revert later
If a session is created at any other time, it is a result of a Shiro
end-user calling subject.getSession() or
httpServletRequest.getSession(). So even if we addressed numbers 1
and 2, there is still end-user getSession() calls to worry about.
I think a potential solution for that is to have SubjectFactory
implementations that return a Subject instance that reacts to
getSession() and getSession(true) calls by throwing an exception,
indicating that sessions are not allowed at any point during that
thread's execution. You'd be able to turn that behavior on and off at
runtime of course.
Thoughts?
--
Les Hazlewood
Founder, Katasoft, Inc.
Application Security Products & Professional Apache Shiro Support and Training:
http://www.katasoft.com