您的位置:首页 > 其它

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

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

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

<?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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐