本文介绍了7的Websphere门户:为登录状态Servlet的检查,以门户网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个WebSphere 7.0门户。一个人必须登录到能够看到这是罚款所有Portlet的任何信息。但另外有一对夫妇在同一个WAR文件部署产生对AJAX的脚本一些原始数据的servlet。

目前,如果一个人知道该URL到特定的se​​rvlet可以绕过来自WebSphere Portal的认证。我想改变这一点,检查如果用户到Portal当前登录。我该怎么做呢?我试图((PumaHome)新的InitialContext()查询(新CompositeName(PumaHome.JNDI_NAME))。)getProfile()getCurrentUser(); 但这返回null

解决方案

在WebSphere Application Server返回本金和只有当你将其配置为使用JavaEE的安全上下文为Web应用程序的远程用户。编辑您的web.xml中包含类似

 <安全约束>
 <显示-名称>&userConstraint LT; /显示-名称>
 <网上资源收集和GT;
  <网上资源名称>&安全LT; /网络资源名称>
  < URL模式> / *< / URL模式>
  < HTTP的方法> GET< / HTTP的方法>
  < HTTP的方法>中邮LT; / HTTP的方法>
 < /网上资源收集和GT;
 < AUTH约束>
  <描述>用户< /描述>
  <角色名称>用户LT; /角色名称>
 < / AUTH约束>
< /安全约束>
<安全角色>
 <描述> secrole< /描述>
 <角色名称>用户LT; /角色名称>
< /安全角色>

和重新部署应用程序。完成部署后您的应用程序来看看在管理控制台应用程序的设置。你会发现用户/角色映射。 从受信任领域的所有认证用户添加到新添加的角色。重新启动应用程序。

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

I run a WebSphere 7.0 Portal. One has to log in to be able to see any information which is fine for all portlets. But additionally there are a couple of servlets that a deploy in the same war file that produce some raw data for AJAX-scripts.

Currently one can bypass the authentication from WebSphere Portal if one knows the URL to that particular servlet. I want to change this and check if the user is currently logged in to the Portal. How do I do this? I tried ((PumaHome) new InitialContext().lookup(new CompositeName(PumaHome.JNDI_NAME))).getProfile().getCurrentUser(); but this returns null.

解决方案

WebSphere Application Server returns principal and remote user only if you configure it to use the JavaEE security context for your web application. Edit your web.xml to contain something like

<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>

and redeploy your application. After deploying your application take a look at the application's settings in the Administrative Console. You will notice "User/role mapping". Add "all authenticated users from trusted realms" to the newly added role. Restart the application.

After that anonymous users can not access your application anymore. Also, the getRemoteUser and other APIs will return the user properly.

这篇关于7的Websphere门户:为登录状态Servlet的检查,以门户网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 21:26