FluorineFx.NET的认证(Authentication )与授权(Authorization)和ASP.NET中的大同小异,核实用户的身份既为认证,授权则是确定一个用户是否有某种执行权限,应用程序可根据用户信息授予和拒绝执行。FluorineFx.NET的认证和授权使用.Net Framework基于角色的安全性的支持。

比如说我们需要自定义一个认证与授权的方案,指定那些远程服务上的那些方法将要被认证或授权以及授权用户角色组等,我们就需要自定义一个LoginCommand并实现ILoginCommand接口或者继承于FluorineFx.Security.GenericLoginCommand(此类实现了ILoginCommand接口)基类。接口定义如下:

1 namespaceFluorineFx.Security2 {3 publicinterfaceILoginCommand4 {5 IPrincipal DoAuthentication(stringusername, Hashtable credentials);6 boolDoAuthorization(IPrincipal principal, IList roles);7 boolLogout(IPrincipal principal);8 voidStart();9 voidStop();10 }11 }

网关通过调用该接口中的方法DoAuthentication()来实现验证,具体的验证规则我们可以自定义(重写方法的实现)。

1 ///<summary>2 ///自定义 LoginCommand3 ///</summary>4 publicclassLoginCommand : GenericLoginCommand5 {6 publicoverrideIPrincipal DoAuthentication(stringusername, Hashtable credentials)7 {8 stringpassword =credentials["password"] asstring;9 if(username =="admin"&&password =="123456")10 {11 //用户标识12 GenericIdentity identity =newGenericIdentity(username);13 //角色数组14 GenericPrincipal principal =newGenericPrincipal(identity, newstring[] { "admin", "privilegeduser"});15 returnprincipal;16 }17 else18 {19 returnnull;20 }21 }22 }

如上面代码块,检测用户是不是属于"admin"和"privilegeduser"两个角色组之一,否则则不能通过验证。要实现授权则是通过DoAuthorization()方法来实现,我们同样可以重写实现以满足自己的需求。

除此之外还需要service-config.xml,指定通过那一个LoginCommand来执行认证与授权,以及要被授权的方法和角色组,login-command的class指向自定义的LoginCommand.

<security><security-constraint id="privileged-users"><auth-method>Login</auth-method><roles><role>admin</role><role>privilegeduser</role></roles></security-constraint><login-command class="FlexDotNet.ServiceLibrary.Authentication.LoginCommand"server="asp.net"/></security>

要使Flex能够调用认证与授权,同样需要提供一个远程服务接口,并为该接口添加RemotingServiceAttribute描述:

1 namespaceFlexDotNet.ServiceLibrary.Authentication2 {3 ///<summary>4 ///远程服务LoginService5 ///</summary>6 [RemotingService]7 publicclassLoginService8 {9 publicLoginService()10 { }11 12 ///<summary>13 ///登录14 ///</summary>15 ///<returns></returns>16 publicboolLogin(stringuserName,stringpassword)17 {18 if(userName =="admin"&&password =="123456")19 {20 //do other21 returntrue;22 }23 else24 {25 //do other26 returnfalse;27 }28 }29 30 ///<summary>31 ///注销32 ///</summary>33 ///<param name="userName">用户名</param>34 ///<returns></returns>35 publicboolLogout(stringuserName)36 {37 GenericIdentity identity =newGenericIdentity(userName);38 GenericPrincipal principal =newGenericPrincipal(identity, newstring[] { "admin", "privilegeduser"});39 40 if(newLoginCommand().Logout(principal))41 returntrue;42 returnfalse;43 }44 }45 }

在Flex或Flash端就可以通过RemoteObject来访问远程对象,Flex的访问配置如下代码块:

<mx:RemoteObject id="loginService"destination="login"><mx:method name="Login"result="onLoginResult(event)"fault="onLoginFault(event)"/></mx:RemoteObject>

通过配置RemoteObject指定访问login这个配置的远程服务,服务里配置了一远程方法Login,并分别定义了访问成功和失败的处理函数。上面的RemoteObject访问的目的地为login配置的目的地,详细配置在remoting-config.xml里,如下:

<destination id="login"><properties>

<source>FlexDotNet.ServiceLibrary.Authentication.LoginService</source></properties></destination>

FlexDotNet.ServiceLibrary.Authentication.LoginService为自定义的一个远程服务(标记为RemotingService)接口,通过配置访问目的地,Flex远程对象组件利用此目的地通过FluorineFx网关调用远程服务接口方法。

布局Flex界面,模拟登录验证的调用,Flex通过setCredentials()方法请求,详细如下代码块:

privatefunction Login():void
{
    loginService.logout();
    loginService.setCredentials(txtName.text,txtPassword.text);
    loginService.Login();
}

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    

<mx:Script>

        

<![CDATA[

            import mx.utils.ObjectUtil;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            private function Login():void
            {
                loginService.logout();
                loginService.setCredentials(txtName.text,txtPassword.text);
                loginService.Login();
            }
            
            private function Logout():void
            {
                loginService.logout();
            }
            
            private function onLoginResult(evt:ResultEvent):void
            {
                var result:Boolean = evt.result as Boolean;
                if(result)
                    Alert.show("登录验证成功");
            }
            
            private function onLoginFault(evt:FaultEvent):void
            {
                Alert.show(ObjectUtil.toString(evt.fault),"登录验证失败");
            }
        ]]

>

    

</mx:Script>

    
    

<mx:RemoteObject id="loginService" destination="login">

        

<mx:method name="Login" result="onLoginResult(event)" fault="onLoginFault(event)"/>

    

</mx:RemoteObject>

    

<mx:Panel x="124" y="102" width="250" height="200" layout="absolute" fontSize="12" title="用户登录">

        

<mx:Label x="19" y="28" text="用户名:"/>

        

<mx:Label x="19" y="72" text="密   码:"/>

        

<mx:TextInput x="75" y="26" width="131" id="txtName"/>

        

<mx:TextInput x="75" y="69" width="131" id="txtPassword" displayAsPassword="true"/>

        

<mx:HBox x="75" y="107" width="131" height="30">

            

<mx:Button label="登 录" click="Login()"/>

            

<mx:Button label="清 空"/>

        

</mx:HBox>

    

</mx:Panel>

</mx:Application>

services-config.xml<?xml version="1.0" encoding="utf-8" ?> <services-config><services><service-include file-path="remoting-config.xml" /></services><!-- Custom authentication --><security><security-constraint id="privileged-users"><auth-method>Custom</auth-method><roles><role>admin</role><role>privilegeduser</role></roles></security-constraint> <login-command class="FlexDotNet.ServiceLibrary.Authentication.LoginCommand" server="asp.net"/></security><channels><channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"><endpoint uri="rtmp://localhost:2086/Web/Gateway.aspx" class="flex.messaging.endpoints.AMFEndpoint"/><properties><!-- <legacy-collection>true</legacy-collection> --></properties></channel-definition><channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel"><endpoint uri="rtmp://localhost:2086/Web/Gateway.aspx" class="flex.messaging.endpoints.RTMPEndpoint"/><properties><idle-timeout-minutes>20</idle-timeout-minutes></properties></channel-definition></channels></services-config>

Flex与.NET互操作(九):FluorineFx.NET的认证(Authentication )与授权(Authorization)相关推荐

  1. Flex与.NET互操作系列文章

    本系列文章主要介绍了关于Flex与.NET结合开发中的一些互操作性,包括网络通信.数据加载.数据传输.文件传输.以及应用于Flex与.NET协作开发的通信网关开源项目FluorineFx的相关知识点. ...

  2. Flex与.NET互操作系列文章索引

    本系列文章主要介绍了关于Flex与.NET结合开发中的一些互操作性,包括网络通信.数据加载.数据传输.文件传输.以及应用于Flex与.NET协作开发的通信网关开源项目FluorineFx的相关知识点. ...

  3. Flex与.NET互操作(十二):FluorineFx.Net的及时通信应用(Remote Shared Objects)(三)

    远程共享对象(Remote Shared Objects) 可以用来跟踪.存储.共享以及做多客户端的数据同步操作.只要共享对象上的数据发生了改变,将会把最新数据同步到所有连接到该共享对象的应用程序客户 ...

  4. Flex与.NET互操作(七):了解FluorineFx的环境配置(远程对象、网关、通道、目的地)...

    注:本文内容原本计划在上一篇<Flex与.NET互操作(六):Flex和.NET协同开发利器FluorineFx >中写出,考虑到写在一起文章内容太长故分为两篇. Flex中的远程对象访问 ...

  5. arcgis api for flex 开发入门(九)webservices 的使用

    arcgis api for flex 开发入门(九)webservices 的使用 flex 本身对webservices有着良好的支持,我们可以调用互联网上的各种 webservices来结合es ...

  6. Flex与.NET互操作(三):基于WebService的数据访问(下)

    在上一篇文章<Flex与.NET互操作(二):基于WebService的数据访问(上) >中介绍了通过<mx:WebService>标签来访问Webservice.实际上我们也 ...

  7. [转]Flex与.NET互操作(三):基于WebService的数据访问(下)

    转自:http://blog.csdn.net/beniao277/archive/2009/01/19/3837605.aspx 在上一篇文章<Flex与.NET互操作(二):基于WebSer ...

  8. Flex与.NET互操作(十):基于FluorineFx.Net的及时通信应用(Real-time Messaging Applications)(一)...

     使用FluorineFx.Net开发的每一个实时通讯功能应用都拥有一个应用程序适配器(ApplicationAdapter),用来管理整个实时通讯应用的生命周期,以及接受和拒绝客户端的连接等.应用程 ...

  9. Flex与.NET互操作(八):使用FluorineFx网关实现远程访问

    关于远程访问在本系列文章中陆续的写了不少示例了,本文没有准备深入的去探讨,为了巩固FluorineFx网关的学习和使用.于此,本文将使用FluorineFx网关来提供数据服务等多项功能来介绍通过Flu ...

最新文章

  1. qt快速加载图片_Qt实用技巧:使用Qt加载超大图片的耗时测试
  2. python 存入数据库bigint_【Python】从0开始写爬虫——把扒到的豆瓣数据存储到数据库...
  3. BOOST使用 proto 转换进行任意类型操作的简单示例
  4. Java中Integer类的方法
  5. 不用点击_网站推广怎么样才能提高点击量和转化率-西安青云在线
  6. 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage“提示信息
  7. 共享打印机从网络访问此计算机,win7连接共享打印机时出现,你没有权限访问网络资源...
  8. 011 使用AOP操作注解
  9. CSS 标签左右分布的多种方法
  10. virtualbox vm 虚拟机 迁移
  11. python制作表情,使用Python制作滑稽表情
  12. yaaw 错误 “No such method: aria2.addTorrent”的解决办法
  13. Ruby学习-Ruby语言的一些特点
  14. 电脑问题处理篇5:解决电脑突然蓝屏问题
  15. 北京科技大学,计算机考研情况
  16. 基于Vivado MIG IP核的DDR3读写实验(top_rom_ddr/ddr_top)
  17. 无线电能传输LCC-S拓扑/WPT MATLAB/simulink仿真模型
  18. PONG - 100行代码写一个弹球游戏
  19. etl作业部署与调度—taskctl管理概述
  20. php省市区筛选,PHP利用正则表达式匹配省市区

热门文章

  1. C++利用双哈希表实现存储机制hash table的算法(附完整源码)
  2. C语言实现通用堆栈(附完整源码)
  3. python四舍五入round_四舍五入就用round( )?Python四舍五入的正确打开方式!
  4. 「SLAM」十四讲:第1讲 预备知识
  5. Maven项目中获取classpath和资源文件的路径
  6. 二分平均值聚类 java_二分K-均值聚类算法
  7. VGA、DVI、HDMI、DP、Type-C不同视频接口有啥区别?
  8. CNN for Semantic Segmentation(语义分割,论文,代码,数据集,标注工具,blog)
  9. dos命令for用法详解
  10. laravel-admin配置安装完新手使用