What is difference between invalid and invalidated session - java

How sessions become invalid?
Invalidated session is an invalid session?
What is difference between invalid and invalidated session?
Why invalid session is not null?

When you invalidate the session, doesn't mean that the reference of the session become null.
Invalidates this session then unbinds any objects bound to it.
When you invalidate, it just remove all the data inside it and itself gets removed from the session pool. So when you ask for the session in current context, you don't receive any session as the session invalidated.
Why invalid session is not null?
If you have the session reference is in your hand, it can't be null. You can still access it, however the session data gets vanished. Once you again call/look for session, for ex request.getSession(false), you'll receive a null as session as the earlier session validated.

Related

what is __flexSession attribute in HttpSession

i want to know what is __flexSession attribute in httpsession. Working on an application front is flex, wildfly10 is application server and back end is java. HttpSession has an attribute with name of __flexSession, which has HttpFlexSession object.which seems clone of HttpSession.After invalidation of HttpSession whenever I invalidate HttpFlexSession I got this exception.
java.lang.IllegalStateException: WFLYCLWEBUT0001: Session KvLvpquLBKMYJ_APyZ6jzxhenh3cRIjoZtHkdAf3 is invalid at org.wildfly.clustering.web.undertow.session.DistributableSession.validate(DistributableSession.java:55)
at org.wildfly.clustering.web.undertow.session.DistributableSession.getAttribute(DistributableSession.java:142)
at io.undertow.servlet.spec.HttpSessionImpl.getAttribute(HttpSessionImpl.java:122)
at com.os.sp.web.servlet.SessionInvalidateServlet.doPost(SessionInvalidateServlet.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
This problem is resolved
"__flexSession" is auto created attribute it contains a session which is replica of main session (parent session).
If you will invalidate the session it will automatically invalidate the session contain by "__flexSession" attribute.
If you will invalidate the session contain by "__flexSession" attribute it will invalidate its parent also.
It’s just a theory but the problem is how you can ensure both sessions are invalidated.
So to overcome this doubt solution is first of all isolate both sessions to each other than invalidate one by one as

What does tomcat do when session expires?

What does tomcat do when session expires?
Does it set the session object invalidated?
Does it unlink all references to the session object so that I may not be able to get the expired session object by calling request.getSession(false) ?
I'm using Servlet 2.5 spec. Thanks.
There is no internal session garbage collector thread. Session are removed during getSession() invocations.
If request.getSession() is invoked and the session is no longer valid (its idle time is greater than maxInactiveInterval) then internal expire() method will be called. This method removes session from the Manager and fires appropriate events on the HttpSessionListener.
One can manually invalidate the session using its invalidate() method, which is a wrapper for the expire().
Tomcat (and every other container) will call HttpSession.invalidate()
From the documentation:
Invalidates this session then unbinds any objects bound to it.
Afterwards, request.getSession(false) will return null.
Related:
Best Practice: Releasing and invalidating HTTP sessions

session.invalidate() IllegalStateException

I'm trying to invalidate a session. When I call:
session.invalidate()
it throws
java.lang.IllegalStateException: getLastAccessedTime: Session already invalidated
Any idea why? I can see the session and it's values just before the invalidate line.
You can use an HttpSessionListener to understand where and when the Session is timing-out or getting invalidated before you call the invalidate yourself.

Java Request.isRequestedSessionValid() still true after session expires

I am using Spring Security 3.0 and created a custom filter to check for expired sessions.
My problem is that request.isRequestedSessionValid() returns true in my filter even after I let the session expire or log out. If I try to access any secured page, I do get redirected to my login page so I know that the session management works.
My understanding was that when a web session times out, the session is automatically invalidated and I also set invalidate-session in my logout element of Spring Security. How can the session still be valid? Am I checking the wrong value?
request.isRequestedSessionValid() can itself cause a session to be created, even after logout has been called. Use request.getSession(false) != null to check instead, which will ensure that a session is not created.

Servlet application: Http session timeout

Hi just want to confirm when a session is expired in a webapp based on servlet.
The following session id will be available until the session is garbage collected, is that correct?
httpServletRequest.getRequestedSessionId()
Thanks,
C
if the session got expired, then at that point the session will be garbage collected and
httpServletRequest.getRequestedSessionId() will return new value when that method is called.
please check below url
http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.1/api/javax.servlet.http.HttpServletRequest.html#getRequestedSessionId%28%29
When a session is expired getRequestedSessionId() return id new session which will be created when you call this method
To check if session is timed-out (in invalid state) check isRequestedSessionIdValid
From JavaDoc
getRequestedSessionId
public abstract String
getRequestedSessionId()
Gets the session id specified with this request. This may differ from the
actual session id. For example, if the
request specified an id for an invalid
session, then this will get a new
session with a new id.
Returns:
the session id specified by this request, or null if the request
did not specify a session id

Categories