jaas

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。这样相当于在需要保护的页面上加了拦截器。

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值