我试图按照此问题中的描述实施loggin过滤器: How implement a login filter in JSF?
但无法获得与当前登录用户相关联的任何属性。我使用 Websphere 8.0 进行内置 Apache MyFaces 2.0.3
我的代码如下:
String path = req.getServletPath();
HttpSession session = req.getSession(false);
我尝试使用req.getSession().getAttribute("auth");
,它返回null
;
req.getSession().getAttribute("username")
也会返回null
。
但是当我尝试通过toString
调试或打印session
时,我得到以下输出(我隐藏了隐私信息):
(java.lang.String) # HttpSessionImpl #
{
_iSession=# com.ibm.ws.session.store.memory.MemorySession #
{
_sessionId=f7ZHa1mIEnp3CDyMammVg1U
hashCode : 73409621
create time : Sun May 31 19:34:53 IDT 2015
last access : Sun May 31 19:35:23 IDT 2015
max inactive interval : 900
user name : user:**********/uid=******,c=il,OU=**,O=********
valid session : true
new session : false
overflowed : false
app name : default_host/*********
Attribute Names=[org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementHelper.SERIALIZED_VIEW, jsf_sequence, org.apache.webbeans.web.failover, WebBeansConfigurationListener, facelets.ui.DebugOutput, javax.faces.request.charset]
_refCount=1
}
_httpSessionContext=com.ibm.ws.session.http.HttpSessionContextImpl@4cab3001
}
所以我决定会话保存我需要的数据,我只是不知道如何获得它。
当我尝试更深入地调试时,我发现它包含_iSession
类型的MemorySession
变量,其中包含变量_userName
,其中包含所需的数据,但是再一次,我无法得到它。
我已尝试将此对象强制转换为HttpSessionImpl
,但收到错误消息:
could not resolve type: com.ibm.ws.session.http.HttpSessionImpl
获取所需数据的下一步是使用反射,但我确定它是错误的方式。访问它应该是更方便的方式。
感谢您的帮助。