前言: 前些日子写了一篇关于JAAS+LDAP在JBOSS上的配置: http://blog.csdn.net/oicqren/archive/2004/11/27/195803.aspx 现将其移植到Websphere上,这个过程比JBOSS复杂。同样是整天在网上搜啊、试啊、问啊,打电话骚扰IBM工程师啊!说来奇怪,就是没人能给一准确答案。也许是老婆来深圳看我,带来很多支持与运气。今天解决了这个问题,贴出来。 ps.更多安全信息请参考红皮书:sg246573
目标: 使用JAAS框架,使用LDAP Server,使用Websphere,做用户的验证和授权 (验证的含义是用户有效,即用户名、密码输入正确;授权的含义是用户被授予某种角色)
基础要求: 精通J2EE框架 熟悉iPlanet Directory Server配置 熟悉Websphere配置 熟悉JAAS框架
准备: windows 2k (要加入域) j2sdk1.4.2 installed Websphere 5.1.x Or Webphsere installed iPlanet Directory Server 5.1 Service Pack 2 installed
假设: 应用名称为myApp
应用中需要配置的point-list: web.xml application.xml ibm-application-bnd.xmi iPlanet Directory Server用户和角色 websphere admin console:安全性>JAAS 配置>应用程序登录 websphere admin console:安全性>用户注册表>LDAP websphere admin console:安全性>全局安全性 websphere admin console:应用程序>企业应用程序>myApp>映射安全性角色到用户/组 可选配置点: websphere admin console:安全性>认证机制>LTPA
另外: 可以通过WAS AAT工具、或者WSAD开发工具、文本编辑器来修改下面的配置。但要做到配置相同。 我用UltraEdit修改的。所以下面的方法没有工具的介绍。
[web.xml] --------------------------------------------------------------------------------------------- 是什么我不用说了吧!在</web-app></web-app>标签中增加下面一段。 <security-constraint>:安全约束的表述 <url-pattern>: 被限定在安全约束中的资源文件名模式*.jsp代表所有jsp文件,*.do代表struts的所有Action <http-method>: 被限定在安全约束中的访问方法 <auth-constraint>: 那一种角色可以认为有权限访问资源 <auth-method>: 验证授权的方式,此处必须是FORM类型 </realm-name>: 安全域名称 <form-login-page>: 如果还没有做验证,将转向到此页面 <form-error-page>: 如果验证未通过,将转向到此页面 <security-role>: 描述一下上面用到的角色 <security-constraint> <web-resource-collection> <web-resource-name>Restricted</web-resource-name> <description>Declarative security tests</description> <url-pattern>*.do</url-pattern> <url-pattern>*.jsp</url-pattern> <http-method>HEAD</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> <http-method>DELETE</http-method> </web-resource-collection> <auth-constraint> <role-name>icpuser</role-name> </auth-constraint> <user-data-constraint> <description>no description</description> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>icprealm</realm-name> <form-login-config> <form-login-page>/login.do</form-login-page> <form-error-page>/LogError.do</form-error-page> </form-login-config> </login-config> <security-role> <description>A user allowed to login</description> <role-name>icpuser</role-name> </security-role> ---------------------------------------------------------------------------------------------
[application.xml] --------------------------------------------------------------------------------------------- 不说了,J2EE开发人员都应该认识它。 修改<display-name>myApp</display-name> 在<application></application>标签中增加下面一段。id="......"很重要不能省略。 <security-role id="SecurityRole_1"> <description>role-icpuser</description> <role-name>icpuser</role-name> </security-role> ---------------------------------------------------------------------------------------------
[ibm-application-bnd.xmi] --------------------------------------------------------------------------------------------- 在"应用程序>安装新的应用程序"功能中将自己的程序成功发布之后。 检查$WAS_HOME\config\cells\zkf5011\applications\myApp.ear\deployments\myApp\META-INF\ibm-application-bnd.xmi文件是否存在下面配置,如果没有请添加。这里的<role href="META-INF/application.xml#......"/>很重要,必须和application.xml的<security-role id="......">相同,都为"SecurityRole_1" <authorizationTable> <authorizations xmi:id="RoleAssignment_1"> <role href="META-INF/application.xml#SecurityRole_1"/> </authorizations> <authorizationTable>
|