flex + Spring + Annotaion 权限(登录)验证
???? 在Flex开发中,Flex端后台(Java)时,不仅要在前台根据权限对一些功能进行屏蔽限制,也要在后台进行拦截,下面使用spring的aop和自定义annotation来演示登录管理功能。
?? ?自定义annotation: AuthLogin,为了对一些不需要登录验证的方法进行标记。
?
?没有登录Exception:
?
??
spring配制文件中对aop进行配制:对所有business包中的方法进行拦截(Before前置通知)。
??
Flex端对异常进行捕获,并进行提示:
如使用RemoteObject对象的fault引用的方法进行提示(fault=”MyAlert.show(event.fault.faultString);”),
自定义的Alert类package test.swf.util{import flash.display.Sprite;import flash.net.URLRequest;import flash.net.navigateToURL;import mx.controls.Alert;import mx.events.CloseEvent;public class MyAlert extends Alert{private static const NO_LOGIN_EXCEPTION:String = "test.exception.NoLoginException";public static function show(text:String = "", title:String = "",flags:uint = 0x4 /* Alert.OK */, parent:Sprite = null, closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4 /* Alert.OK */):Alert{if(text == null || text.length ==0){text = "";}else{if(text.indexOf(NO_LOGIN_EXCEPTION,0)!= -1){//捕获到NoLoginException,改变消息框关闭函数,使其跳转到登录页closeHandler = toLoginPage;}var startIndex:int = text.indexOf("[",0);var endIndex:int = text.indexOf("]",0);if(startIndex != -1 && endIndex != -1 && startIndex < endIndex){text= text.substring(text.indexOf("[") ,text.indexOf("]"));}}return Alert.show( text, title,flags, parent, closeHandler, iconClass, defaultButtonFlag); }//跳转到登录页,简单实现private static function toLoginPage(event:CloseEvent = null):void{var url:URLRequest=new URLRequest("index.html");navigateToURL(url, "_self");}}}??
完成。
?