FLEX权限--使用RemoteObject交互结合spring AOP控制项目权限教程
<aop:pointcut id="logicMethods" expression="execution (* cn.flex.logic.service.*.*(..)) and not execution
(* cn.flex.logic.service.UserService.checkLogin(..))"/>
<aop:around pointcut-ref="logicMethods" method="testAuth" />
</aop:aspect>
</aop:config>
下面是后台类代码:
3. 拦截器代码
import org.aspectj.lang.ProceedingJoinPoint;
import flex.messaging.FlexContext;
public class AuthPermission {
public Object testAuth(ProceedingJoinPoint point) throws Throwable {
String user = (String)FlexContext.getFlexSession().getAttribute("userName");
if(user != null){
System.out.println("executing...");
return point.proceed();
}else {
System.out.println("You have no permission...");
return null;
}
}
}
?
4. 逻辑业务管理类代码, 所有与flex交互的类都继承该类, 这样可以方便调用逻辑层的所有业务
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import cn.flex.logic.service.UserService;
import cn.flex.logic.service.base.ServiceManager;
import flex.messaging.FlexContext;
public class BaseLogicImpl {
private ServiceManager srvManager;
public HttpServletRequest getRequest() {
return FlexContext.getHttpRequest();
}
public HttpSession getSession() {
return FlexContext.getHttpRequest().getSession(); //FlexContext.getFlexSession()同理
}
public void setSrvManager(ServiceManager srvManager) {
this.srvManager = srvManager;
}
public UserService getUserService() {
return srvManager.getUserService();
}
}
4. 用户业务逻辑处理代码:
import cn.flex.web.BaseLogicImpl;
public class UserActive extends BaseLogicImpl{
/**
* 用户登陆
* @param name
* @param psw
* @return
*/
public Integer login(String name, String psw) {
Integer result = getUserService().checkLogin(name, psw);
//result整型标识处理接口, 0 为登陆成功, 1为错误, null为用户名不存在.
if(result!=null && result == 0) {
getSession().setAttribute("userName", name);
}
return result;
}
}
5. FLEX主要代码:
private function toLogin():void {
var name:String = ui_name.text;
var psw:String = ui_pass.text;
userSv.login(name, psw);
}
private function loginResult(event:ResultEvent):void {
var data:Object = event.result;
//trace(data);
if(data == 0){
Alert.show("login success.");
showMainFM();
}else if(data == 1){
Alert.show("The password is wrong.");
}else if(data == null ){
Alert.show("The user account doesn't exsit.");
}
}
<mx:RemoteObject id="userSv" destination="userActive"
endpoint="/FlexWeb/messagebroker/amf" >
<mx:method name="login" result="loginResult(event)" />
</mx:RemoteObject>
<mx:Panel id="loginPanel" title="User Login" showEffect="{irisLoginEffect}"
width="300" height="230" creationCompleteEffect=""
layout="absolute" verticalCenter="0" horizontalCenter="0" y="113">
<mx:Canvas borderColor="#ffffff" y="19" x="16.5">
<mx:Label text="UserName:" x="10" y="31"/>
<mx:TextInput id="ui_name" x="87" y="29"/>
<mx:Label text="Password:" x="15" y="70"/>
<mx:TextInput id="ui_pass" x="87" y="68"/>
<mx:Button click="toLogin()" label="确定" x="87" y="101"/>
<mx:Button click="showRegisterFM()" label="注册" x="169" y="101"/>
</mx:Canvas>
</mx:Panel>