JAAS -- 可以不改变业务逻辑代码而使用不同验证机制。保持业务逻辑和验证授权代码的独立性。松耦合。
http://java.sun.com/j2se/1.5.0/docs/guide/security/jaas/tutorials/index.html
JAAS LoginModule Developer's Guide
http://java.sun.com/j2se/1.5.0/docs/guide/security/jaas/JAASLMDevGuide.html
Mastering ejb3 chapter11
WEB层利用JAAS验证授权
1.在web.xml中通过<login-config> and <security-constraint>配置希望保护什么资源,如何保护他们的安全。
web.xml 配置sample
<!-- authorization -->
<security-constraint>
A collection of protected resources along with the access mechanism
<web-resource-collection>
<web-resource-name>
Restricted to Secure role
</web-resource-name>
<description>Declarative security</description>
<url-pattern>/*</url-pattern>
</web-resource-collection>
The list of roles that can access the resource.
<auth-constraint>
<role-name>users</role-name>
</auth-constraint>
</security-constraint>
<!-- anthentication -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>adboard</realm-name>
<form-login-config>
<form-login-page>/login/login.jsp</form-login-page>
<form-error-page>/login/error.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<role-name>users</role-name>
</security-role>
2.当然还需要根据jaas的规范,实现相应的验证代码(实现PasswordLoginModule的子类)
3.运行时web container会根据web.xml中的配置,调用JAAS相应的realm来进行验证。
对于上面配置的例子,
当用户访问/login/login.jsp时,会调用loginModule,储存用户的登陆成功信息。
当访问/*(这个正则表达式不匹配/login/login.jsp)时,check是否有用户的登陆信息存在。
这样就不需要在每个需要保护的页面都加入权限check。这样相当于在需要保护的页面上加了拦截器。
本文介绍如何利用Java认证和授权服务(JAAS)在Web应用中实施安全验证和授权。通过配置web.xml文件定义受保护资源及访问机制,并实现PasswordLoginModule子类来定制验证逻辑。此方法减少了重复代码并提高了安全性。
3910

被折叠的 条评论
为什么被折叠?



