案例学习BlazeDS+Spring之十五:Security Integration 101

Security Integration 101

这是仅有的一个涉及的安全的demo,给本系列第一个demo——Spring BlazeDS Integration 101,增加了安全机制。

 

一、运行DEMO:

1、运行程序:http://localhost:8400/spring-flex-testdrive/spring-blazeds-security-101/index.html

2、在未登录的情况下,单击“Get Data”按钮,会显示一个“Access Denied”异常的对话框。

3、使用UserId:john/Password:john登录,再次单击“Get Data”,从服务端获得数据。

4、单击“Logout”按钮,再次单击“Get Data”,会再次显示“Access Denied”异常的对话框。

5、如果你已登录,通过了认证,你不需要使用ChannelSet来登录。例如,你在login.jsp(http://localhost:8400/spring-flex-testdrive/login.jsp)中使用john/john登录了,在flex程序中,则用登录,直接获取数据。

二、理解代码:

1、Main.mxml:

在程序初始化时,设置ro的channelSet

var channel:AMFChannel = new AMFChannel("my-amf", "http://localhost:8400/spring-flex-testdrive/messagebroker/amf");
            var channelSet:ChannelSet = new ChannelSet();
            channelSet.addChannel(channel);
            ro.channelSet = channelSet;

<s:RemoteObject id="ro" destination="securedProductService" fault="faultHandler(event)"/>

2、通过ro的channelSet来进行登录与注销。ro.channelSet.login(用户名,密码)和ro.channelSet.logout()。

3、flex-servlet.xml

<flex:remoting-destination ref="securedProductService" />

4、在app-config.xml中定义的securedProductService是关键:

    <bean id="securedProductService" class="org.springframework.flex.samples.product.ProductDAO">
        <constructor-arg ref="dataSource" />
        <security:intercept-methods>
            <security:protect method="find*" access="ROLE_USER" />
        </security:intercept-methods>
    </bean>

通过在<bean />中使用<security />来保护方法,认证的配置在security-config.xml中。

5、security-config.xml

<authentication-manager>
       <authentication-provider>
           <user-service>
            <user name="john" password="john" authorities="ROLE_USER" />
            <user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
            <user name="guest" password="guest" authorities="ROLE_GUEST" />
           </user-service>
       </authentication-provider>
    </authentication-manager>

6、该Demo还有一部分是Jsp登录方面的代码。

 

三、小结:

关于这个安全机制,更多的是来自Spring方面的知识,这个内容需要另起个话题了。本系列案例学习到此结束。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值