Here's my question: I'm writing a platform which I will be giving to the customers to implement their projects with. So in my platform I have created a SessionService
in which I have methods like getCurrentSession
, getAttribute
, setAttribute
, etc. Before spring-session my getCurrentMethod
looked like this:
@Override
public HttpSession getCurrentSession() {
if (this.session == null) {
final ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
return attr.getRequest().getSession(true); // true == allow create
}
return this.session;
}
which worked perfectly fine, although it looks ugly and have no backing like redis. Now I want to migrate to spring-session
and I was hoping to use the SessionRepository
to find the current session of the user, however I can only see a getSession(String id)
in there. I believe the id is stored in the cookie, so to use it I will probably have to pass the HttpServletRequest
object from my controllers, to my facades, to the service layer which is very near the db layer. This looks like a very bad idea to me, so my question would be: is there any way to get the currentSession near the db layer? One way I would think is to write an interceptor that will be invoked the controllers, which will set the current session in the repository, or the service maybe? I'm just not sure this is the right way to go.