加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 04:38:45 所属栏目:百科 来源:网络整理
导读:Security Integration 101 这是仅有的一个涉及的安全的demo,给本系列第一个demo——Spring BlazeDS Integration 101,增加了安全机制。 ? 一、运行DEMO: 1、运行程序:http://localhost:8400/spring-flex-testdrive/spring-blazeds-security-101/index.htm

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方面的知识,这个内容需要另起个话题了。本系列案例学习到此结束。。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读