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方面的知識,這個內容需要另起個話題了。本系列案例學習到此結束。。