瀏覽代碼

取出协作权限校验拦截器

dengsixing 3 年之前
父節點
當前提交
3d276165f6

+ 106 - 106
4dkankan-center-scene/src/main/java/com/fdkankan/scene/Interceptor/CheckCooperationPermitAspect.java

@@ -1,106 +1,106 @@
-package com.fdkankan.scene.Interceptor;
-
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
-import com.fdkankan.common.constant.CommonStatus;
-import com.fdkankan.common.constant.ErrorCode;
-import com.fdkankan.common.constant.ServerCode;
-import com.fdkankan.common.exception.BusinessException;
-import com.fdkankan.common.user.SSOLoginHelper;
-import com.fdkankan.common.util.WebUtil;
-import com.fdkankan.redis.constant.RedisKey;
-import com.fdkankan.redis.util.RedisUtil;
-import com.fdkankan.scene.entity.ScenePlus;
-import com.fdkankan.scene.service.IScenePlusService;
-import java.io.IOException;
-import java.util.Map;
-import java.util.Objects;
-import javax.servlet.http.HttpServletRequest;
-import lombok.extern.log4j.Log4j2;
-import org.aspectj.lang.JoinPoint;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.annotation.Before;
-import org.aspectj.lang.annotation.Pointcut;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-@Log4j2
-@Aspect
-@Component
-@Order(101)
-public class CheckCooperationPermitAspect {
-
-	@Autowired
-	private SSOLoginHelper ssoLoginHelper;
-	@Autowired
-	private RedisUtil redisUtil;
-	@Autowired
-	private IScenePlusService scenePlusService;
-
-
-	@Pointcut("@annotation(com.fdkankan.scene.annotation.CheckCooperationPermit)")
-	public void checkCooperationPermit() {
-	}
-
-	/**
-	 * 前置通知 用于判断用户协作场景是否有协作权限
-	 *
-	 * @param joinPoint
-	 *            切点
-	 * @throws IOException
-	 */
-	@Before("checkCooperationPermit()")
-	public void doBefore(JoinPoint joinPoint) throws Exception {
-		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
-		// 读取session中的用户
-		com.fdkankan.common.model.SSOUser user = ssoLoginHelper.loginCheckV3(request.getHeader("token"));
-		if(Objects.isNull(user)){
-			throw new BusinessException(ErrorCode.TOKEN_NOT_FOUND);
-		}
-		String num = WebUtil.getNum(joinPoint, request);
-		if(StrUtil.isEmpty(num)){
-			throw new BusinessException(ErrorCode.PARAM_REQUIRED);
-		}
-
-		//判断是不是场景原用户,如果是,跳出
-        ScenePlus scenePlus= scenePlusService.getScenePlusByNum(num);
-		if(Objects.isNull(scenePlus)){
-			throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
-		}
-
-		//判断是否相机登录,是否场景的相机id和相机登录的相机id是否相等,如果都满足,则放行,否则判定为用户登录
-		if(Objects.nonNull(user.getCameraLogin())
-			&& CommonStatus.YES.code().byteValue() == user.getCameraLogin().intValue()){
-			log.info("相机登录,cameraId:{}", user.getCameraId());
-			if(scenePlus.getCameraId().equals(user.getCameraId())){
-				return;
-			}else{
-				log.info("相机登录失败---------");
-				throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
-			}
-		}
-
-		//走到这里代表是用户账号密码登录,如果查到的场景的userid是空,证明相机解绑了,需要返回无权操作
-		if(Objects.isNull(scenePlus.getUserId())){
-			log.info("场景userid为空---------");
-			throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
-		}
-
-        if(scenePlus.getUserId().equals(user.getId())){
-            return;
-        }
-
-        //如果不是用户自己的场景,判断是否有协作权限
-        String userId = redisUtil.hget(RedisKey.SCENE_COOPERATION_NUM_USERID, num);
-        if(StrUtil.isEmpty(userId)){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
-        }
-        if(!userId.equals(String.valueOf(user.getId()))){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
-        }
-	}
-
-}
+//package com.fdkankan.scene.Interceptor;
+//
+//import cn.hutool.core.collection.CollUtil;
+//import cn.hutool.core.util.StrUtil;
+//import com.fdkankan.common.constant.CommonStatus;
+//import com.fdkankan.common.constant.ErrorCode;
+//import com.fdkankan.common.constant.ServerCode;
+//import com.fdkankan.common.exception.BusinessException;
+//import com.fdkankan.common.user.SSOLoginHelper;
+//import com.fdkankan.common.util.WebUtil;
+//import com.fdkankan.redis.constant.RedisKey;
+//import com.fdkankan.redis.util.RedisUtil;
+//import com.fdkankan.scene.entity.ScenePlus;
+//import com.fdkankan.scene.service.IScenePlusService;
+//import java.io.IOException;
+//import java.util.Map;
+//import java.util.Objects;
+//import javax.servlet.http.HttpServletRequest;
+//import lombok.extern.log4j.Log4j2;
+//import org.aspectj.lang.JoinPoint;
+//import org.aspectj.lang.annotation.Aspect;
+//import org.aspectj.lang.annotation.Before;
+//import org.aspectj.lang.annotation.Pointcut;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.core.annotation.Order;
+//import org.springframework.stereotype.Component;
+//import org.springframework.web.context.request.RequestContextHolder;
+//import org.springframework.web.context.request.ServletRequestAttributes;
+//
+//@Log4j2
+//@Aspect
+//@Component
+//@Order(101)
+//public class CheckCooperationPermitAspect {
+//
+//	@Autowired
+//	private SSOLoginHelper ssoLoginHelper;
+//	@Autowired
+//	private RedisUtil redisUtil;
+//	@Autowired
+//	private IScenePlusService scenePlusService;
+//
+//
+//	@Pointcut("@annotation(com.fdkankan.scene.annotation.CheckCooperationPermit)")
+//	public void checkCooperationPermit() {
+//	}
+//
+//	/**
+//	 * 前置通知 用于判断用户协作场景是否有协作权限
+//	 *
+//	 * @param joinPoint
+//	 *            切点
+//	 * @throws IOException
+//	 */
+//	@Before("checkCooperationPermit()")
+//	public void doBefore(JoinPoint joinPoint) throws Exception {
+//		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+//		// 读取session中的用户
+//		com.fdkankan.common.model.SSOUser user = ssoLoginHelper.loginCheckV3(request.getHeader("token"));
+//		if(Objects.isNull(user)){
+//			throw new BusinessException(ErrorCode.TOKEN_NOT_FOUND);
+//		}
+//		String num = WebUtil.getNum(joinPoint, request);
+//		if(StrUtil.isEmpty(num)){
+//			throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+//		}
+//
+//		//判断是不是场景原用户,如果是,跳出
+//        ScenePlus scenePlus= scenePlusService.getScenePlusByNum(num);
+//		if(Objects.isNull(scenePlus)){
+//			throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+//		}
+//
+//		//判断是否相机登录,是否场景的相机id和相机登录的相机id是否相等,如果都满足,则放行,否则判定为用户登录
+//		if(Objects.nonNull(user.getCameraLogin())
+//			&& CommonStatus.YES.code().byteValue() == user.getCameraLogin().intValue()){
+//			log.info("相机登录,cameraId:{}", user.getCameraId());
+//			if(scenePlus.getCameraId().equals(user.getCameraId())){
+//				return;
+//			}else{
+//				log.info("相机登录失败---------");
+//				throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
+//			}
+//		}
+//
+//		//走到这里代表是用户账号密码登录,如果查到的场景的userid是空,证明相机解绑了,需要返回无权操作
+//		if(Objects.isNull(scenePlus.getUserId())){
+//			log.info("场景userid为空---------");
+//			throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
+//		}
+//
+//        if(scenePlus.getUserId().equals(user.getId())){
+//            return;
+//        }
+//
+//        //如果不是用户自己的场景,判断是否有协作权限
+//        String userId = redisUtil.hget(RedisKey.SCENE_COOPERATION_NUM_USERID, num);
+//        if(StrUtil.isEmpty(userId)){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
+//        }
+//        if(!userId.equals(String.valueOf(user.getId()))){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
+//        }
+//	}
+//
+//}