Liferay PortletSession cannot be shared with DWR Servlet Session however using following technique we can copy required information from Liferay Session to Application Session
request.getPortletSession().setAttribute("remoteUser", request.getRemoteUser(), PortletSession.APPLICATION_SCOPE);
Access above session data inside DWR
public String test(HttpSession session) {
/**
* s1 == portal session
* s2 == DWR session
*
* s1 expires before s2 --> s2 will also expire (Tested)
* s2 expires before s1 --> s2 invalidates and should work after reload (Tested)
* s1 & s2 expires --> user reloads and relogins both should work
*
*/
String userId = (String) session.getAttribute("remoteUser");
if (userId == null) {
session.invalidate();
return "Page reload is required!";
}
return userId;
}
the above code is pretty self explanatory and safe way of exposing DWR services in a Portal Architecture.
have fun....
request.getPortletSession().setAttribute("remoteUser", request.getRemoteUser(), PortletSession.APPLICATION_SCOPE);
Access above session data inside DWR
public String test(HttpSession session) {
/**
* s1 == portal session
* s2 == DWR session
*
* s1 expires before s2 --> s2 will also expire (Tested)
* s2 expires before s1 --> s2 invalidates and should work after reload (Tested)
* s1 & s2 expires --> user reloads and relogins both should work
*
*/
String userId = (String) session.getAttribute("remoteUser");
if (userId == null) {
session.invalidate();
return "Page reload is required!";
}
return userId;
}
the above code is pretty self explanatory and safe way of exposing DWR services in a Portal Architecture.
have fun....
Comments