Websphere 7 Portal:Servlet检查Portal的登录状态?

时间:2011-02-06 12:53:06

标签: authentication servlets websphere-portal

我运行WebSphere 7.0 Portal。必须登录才能看到任何适用于所有portlet的信息。但另外还有一些servlet部署在同一个war文件中,可以为AJAX脚本生成一些原始数据。

目前,如果知道该特定servlet的URL,则可以绕过WebSphere Portal的身份验证。我想更改此项并检查用户当前是否已登录到Portal。我该怎么做呢?我尝试了((PumaHome) new InitialContext().lookup(new CompositeName(PumaHome.JNDI_NAME))).getProfile().getCurrentUser();,但这会返回null。

1 个答案:

答案 0 :(得分:6)

只有将WebSphere Application Server配置为使用Web应用程序的JavaEE安全上下文时,它才会返回主体和远程用户。编辑您的web.xml以包含类似

的内容
<security-constraint>
 <display-name>userConstraint</display-name>
 <web-resource-collection>
  <web-resource-name>secure</web-resource-name>
  <url-pattern>/*</url-pattern>
  <http-method>GET</http-method>
  <http-method>POST</http-method>
 </web-resource-collection>
 <auth-constraint>
  <description>user</description>
  <role-name>user</role-name>
 </auth-constraint>
</security-constraint>
<security-role>
 <description>secrole</description>
 <role-name>user</role-name>
</security-role>

并重新部署您的申请。部署应用程序后,请查看管理控制台中的应用程序设置。您会注意到“用户/角色映射”。将“所有经过身份验证的用户从受信任的域”添加到新添加的角色中。重启应用程序。

之后,匿名用户无法再访问您的应用程序。此外,getRemoteUser和其他API将正确返回用户。