-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AwsHttpServletRequest throws UnsupportedOperationException in getRequestedSessionId instead of returning null #111
Comments
Neglected to mention that it appears that you can work around this by completely disabling session management:
which prevents the
which tells Spring never to create a session. However this configuration keeps the |
Thanks for the feedback @kdhunter. Throwing that exception was a deliberate choice. Writing applications with Lambda, we expect you not to rely on a session - your code needs to be completely stateless. I will definitely include your snippet on how to disable session checking in the Spring Boot docs. If this is something you want to leverage, can you tell me a little bit more about the use-case and what you are trying to achieve? I'll see if there's anything we can do. |
I completely agree that the code needs to be stateless. However, “getRequestedSessionId” does not create a session.
To enforce statelessness, the appropriate place to throw an exception would be in getSession - a call to getSession() or getSession(true) should throw.
My concern is that there is a lot of common software that may check for the existence of a session (via any number of means), but may be perfectly happy operating without one - this was just such a case.
So it seems to me that any of the methods that create a session should throw, but none of the ones that merely check for its existence should.
… On Jan 30, 2018, at 1:32 PM, Stefano Buliani ***@***.***> wrote:
Thanks for the feedback @kdhunter <https://github.com/kdhunter>. Throwing that exception was a deliberate choice. Writing applications with Lambda, we expect you not to rely on a session - your code needs to be completely stateless. I will definitely include your snippet on how to disable session checking in the Spring Boot docs.
If this is something you want to leverage, can you tell me a little bit more about the use-case and what you are trying to achieve? I'll see if there's anything we can do.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#111 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAc4_9uG2V3ZbkTMCdGYjY1CbDguaRTnks5tP2BDgaJpZM4RyfrY>.
|
… bug introduced with the fixes for #84. Added unit tests
@kdhunter fair point. Would returning null from the |
I've just tested returning from the |
…g log messages in request object when a framework tries to access the session
In my particular case, things were blowing up at the point in the code that I posted - I didn’t get any farther, so it’s very possible that I could have run into trouble later even if getRequestSessionId had returned null. I had configured my application to be “stateless" - I had assumed (possibly incorrectly) that nothing would then attempt to create a session.
Possibly that's incorrect without the additional configuration - as I said, I didn't get farther than the code I posted earlier. I absolutely agree that including explicit documentation as to how you need to set up Spring Security would be a tremendous help for others that might run into similar problems. All that being said, I still kind of think that having getRequestSessionId return null and have the exception being thrown from getSession() or getSession(true) feels “more correct." In my opinion, it would better draw attention to exactly what it is that you were trying to prevent (the creation of an HttpSession when sessions aren't supported). Throwing an UnsupportedOperationException from getSession that says "sessions aren't supported in this environment" would (to me at least) pretty explicitly explain that. It would also better draw attention to the offending portion of whatever code was triggering the attempted session creation so that people would have a better idea how to work around it. With the current implementation, I was forced to kind of infer your intent. Just my $0.02. |
Thanks @kdhunter, makes sense to me to return null on the session id and throw the exception when the framework tries to explicitly get/create a session. I will make this change for the next release. I will update the documentation to include the spring security settings today. |
Changes are done and committed to the |
Using aws-serverless-java-container-spring 0.9 and Spring Boot 1.5.9.RELEASE, which pulls in Spring Security 4.2.3.RELEASE.
The current implementation of
com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest
throws anUnsupportedOperationException
when thegetRequestedSessionId()
method is called.The default Spring Boot configuration includes the Spring Security
SessionManagementFilter
in the filter chain. The problem is that theSessionManagementFilter
checks the requested session ID under some scenarios:From org.springframework.security.web.session.SessionManagementFilter, starting at line 118 in
doFilter
:Thus, the call to
request.getRequestedSessionId()
throws and the exception then propagates through the system, destroying the request.If
getRequestedSessionId()
returnednull
, instead of throwing an exception, this problem wouldn't occur.A
null
return value fromgetRequestedSessionId()
indicates that the user did not specify a session ID. This would be consistent with the fact thatisRequestedSessionIdValid(
) returns false, and in conformance with theHttpServletRequest
specification.The text was updated successfully, but these errors were encountered: