案例學習BlazeDS+Spring之十五:Security Integration 101

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.