前言: 前些日子寫(xiě)了一篇關(guān)于JAAS+LDAP在JBOSS上的配置: http://blog.csdn.net/oicqren/archive/2004/11/27/195803.aspx 現(xiàn)將其移植到Websphere上,這個(gè)過(guò)程比JBOSS復(fù)雜。同樣是整天在網(wǎng)上搜啊、試啊、問(wèn)啊,打電話騷擾IBM工程師啊!說(shuō)來(lái)奇怪,就是沒(méi)人能給一準(zhǔn)確答案。也許是老婆來(lái)深圳看我,帶來(lái)很多支持與運(yùn)氣。今天解決了這個(gè)問(wèn)題,貼出來(lái)。 ps.更多安全信息請(qǐng)參考紅皮書(shū):sg246573
目標(biāo): 使用JAAS框架,使用LDAP Server,使用Websphere,做用戶(hù)的驗(yàn)證和授權(quán) (驗(yàn)證的含義是用戶(hù)有效,即用戶(hù)名、密碼輸入正確;授權(quán)的含義是用戶(hù)被授予某種角色)
基礎(chǔ)要求: 精通J2EE框架 熟悉iPlanet Directory Server配置 熟悉Websphere配置 熟悉JAAS框架
準(zhǔn)備: windows 2k (要加入域) j2sdk1.4.2 installed Websphere 5.1.x Or Webphsere installed iPlanet Directory Server 5.1 Service Pack 2 installed
假設(shè): 應(yīng)用名稱(chēng)為myApp
應(yīng)用中需要配置的point-list: web.xml application.xml ibm-application-bnd.xmi iPlanet Directory Server用戶(hù)和角色 websphere admin console:安全性>JAAS 配置>應(yīng)用程序登錄 websphere admin console:安全性>用戶(hù)注冊(cè)表>LDAP websphere admin console:安全性>全局安全性 websphere admin console:應(yīng)用程序>企業(yè)應(yīng)用程序>myApp>映射安全性角色到用戶(hù)/組 可選配置點(diǎn): websphere admin console:安全性>認(rèn)證機(jī)制>LTPA
另外: 可以通過(guò)WAS AAT工具、或者WSAD開(kāi)發(fā)工具、文本編輯器來(lái)修改下面的配置。但要做到配置相同。 我用UltraEdit修改的。所以下面的方法沒(méi)有工具的介紹。
[web.xml] --------------------------------------------------------------------------------------------- 是什么我不用說(shuō)了吧!在</web-app></web-app>標(biāo)簽中增加下面一段。 <security-constraint>:安全約束的表述 <url-pattern>: 被限定在安全約束中的資源文件名模式*.jsp代表所有jsp文件,*.do代表struts的所有Action <http-method>: 被限定在安全約束中的訪問(wèn)方法 <auth-constraint>: 那一種角色可以認(rèn)為有權(quán)限訪問(wèn)資源 <auth-method>: 驗(yàn)證授權(quán)的方式,此處必須是FORM類(lèi)型 </realm-name>: 安全域名稱(chēng) <form-login-page>: 如果還沒(méi)有做驗(yàn)證,將轉(zhuǎn)向到此頁(yè)面 <form-error-page>: 如果驗(yàn)證未通過(guò),將轉(zhuǎn)向到此頁(yè)面 <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] --------------------------------------------------------------------------------------------- 不說(shuō)了,J2EE開(kāi)發(fā)人員都應(yīng)該認(rèn)識(shí)它。 修改<display-name>myApp</display-name> 在<application></application>標(biāo)簽中增加下面一段。id="......"很重要不能省略。 <security-role id="SecurityRole_1"> <description>role-icpuser</description> <role-name>icpuser</role-name> </security-role> ---------------------------------------------------------------------------------------------
[ibm-application-bnd.xmi] --------------------------------------------------------------------------------------------- 在"應(yīng)用程序>安裝新的應(yīng)用程序"功能中將自己的程序成功發(fā)布之后。 檢查$WAS_HOME\config\cells\zkf5011\applications\myApp.ear\deployments\myApp\META-INF\ibm-application-bnd.xmi文件是否存在下面配置,如果沒(méi)有請(qǐng)?zhí)砑?。這里的<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>
|