import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; /**
* Annotation which indicates the annotated method must be secured.
*/
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EnableDataSecurity { /**
* 启用当前机构条件开关 ON/OFF
* */
public String enableCurrentOrgCondition() default "ON"; /**
* 启用机构货主表关联开关 ON/OFF
* */
public String enableOrgOwnerRelation() default "ON"; /**
* 启用域管理员创建货主 所属域开放权限开关 ON/OFF,只针对域管理员
* */
public String enableOwnerCreateDomainAuth() default "ON";
}
package com.yundaex.common.security.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
import org.springframework.stereotype.Component; import com.yundaex.common.security.annotation.EnableDataSecurity;
import com.yundaex.common.security.context.WMSSecurityContext; @Aspect
@Component("enableDataSecurityAroundAdvice")
public class EnableDataSecurityAroundAdvice { //private static final Logger logger = Logger.getLogger(EnableDataSecurityAroundAdvice.class); /*public EnableDataSecurityAroundAdvice() {
logger.debug("EnableDataSecurityAroundAdvice initial success");
}*/ @Pointcut(value = "@annotation(enableDataSecurity)", argNames = "enableDataSecurity")
protected void enableDataSecurity(EnableDataSecurity enableDataSecurity) {} /**
* indicate the method should be exeucte the data security operation.
* */
// @SuppressWarnings("rawtypes")
@Before(value = "enableDataSecurity(enableDataSecurity)", argNames="enableDataSecurity")
public void before(JoinPoint joinPoint, EnableDataSecurity enableDataSecurity) throws Throwable { // Class clazz = joinPoint.getTarget().getClass();
if (MethodInvocationProceedingJoinPoint.class.isAssignableFrom(joinPoint.getClass())) { MethodInvocationProceedingJoinPoint methodInvocationProceedingJoinPoint = (MethodInvocationProceedingJoinPoint) joinPoint;
final String methodName = methodInvocationProceedingJoinPoint.getSignature().getName(); // String methodSignature = clazz.getName() + methodName;
String enableCurrentOrgCondition = enableDataSecurity.enableCurrentOrgCondition();
String enableOrgOwnerRelation = enableDataSecurity.enableOrgOwnerRelation();
String enableOwnerCreateDomainAuth = enableDataSecurity.enableOwnerCreateDomainAuth();
String methodSignature = methodName.concat("&")
.concat(enableCurrentOrgCondition)
.concat("&").concat(enableOrgOwnerRelation)
.concat("&").concat(enableOwnerCreateDomainAuth);
//set to thread local to proceeding
WMSSecurityContext.getDataSecurityMethodSignature().set(methodSignature);
} else {
//TODO THROW EXCEPTION TO EXPLAIN "Unsupport in the scenario using annotation 'EnableDataSecurity'"
} } @After(value = "enableDataSecurity(enableDataSecurity)", argNames="enableDataSecurity")
public void after(JoinPoint joinPoint,EnableDataSecurity enableDataSecurity) throws Throwable {
WMSSecurityContext.getDataSecurityMethodSignature().remove();
} }
applicationContext.xml

<aop:aspectj-autoproxy proxy-target-class="true"/>

加注解时插入权限切面@EnableDataSecurity的更多相关文章

  1. linux环境,hidraw设备自动加载时默认权限的设置方法

    在linux系统中,hidraw设备会自动加载并设置默认权限,但系统的默认只允许root用户访问,普通用户是不允许读写. 设置的方法是修改udev的配置,配置路径是/etc/udev/rules.d/ ...

  2. Shiro入门之二 --------基于注解方式的权限控制与Ehcache缓存

    一  基于注解方式的权限控制 首先, 在spring配置文件applicationContext.xml中配置自动代理和切面 <!-- 8配置自动代理 -->    <bean cl ...

  3. Android之运行时相机权限和联系人权限获取

    原文:Android之运行时相机权限和联系人权限获取 本文链接:http://blog.csdn.net/qq_16628781/article/details/61623502 Android之运行 ...

  4. springcloud项目实现自定义权限注解进行接口权限验证

    一般在项目开发中会根据登录人员的权限大小对接口也会设置权限,那么对接口权限是怎么实现的呢,大多数都是用自定义权限注解,只需要在接口上加上一个注解就可以实现对接口的权限拦截,是否对该接口有权调用 接下来 ...

  5. @@IDENTITY在加触发器时返回错误的ID值

    表ID是自增的,所以在添加时要查一下,之前是用@@IDENTITY来查,最近在加触发器时发现返回的会是在触发器中插入语句的数据ID值,上网找了下资料,发现是因为@@IDENTITY 将返回在当前会话中 ...

  6. PHP 执行命令时sudo权限的配置

    PHP 执行命令时sudo权限的配置 1.先写一个PHP文件 <?php system('whoami'); 先看自己的apache2的用户是谁,下面是笔者的截图,笔者使用apche2的用户是w ...

  7. 查询时根据权限更改sql

    import java.lang.reflect.Method; import org.apache.log4j.Logger; import org.springframework.aop.Meth ...

  8. 【spring data jpa】使用spring data jpa 的删除操作,需要加注解@Modifying @Transactional 否则报错如下: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call

    使用spring data jpa 的删除操作,需要加注解@Modifying     @Transactional 否则报错如下: No EntityManager with actual tran ...

  9. [Swift通天遁地]八、媒体与动画-(3)实现视频播放的水印、Overlay、暂停时插入广告等效果

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

随机推荐

  1. js右击事件

    先贴代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...

  2. pycharm安装 package报错:module 'pip' has no attribute 'main'

    转自: <pycharm安装 package报错:module 'pip' has no attribute 'main'> https://www.cnblogs.com/Fordest ...

  3. 一 Akka学习 - actor

    (引用 http://shiyanjun.cn/archives/1168.html) 一: 什么是Akka? Akka是JAVA虚拟机JVM平台上构建高并发.分布式和容错应用的工具包和运行时,是一个 ...

  4. JavaScript之使用JavaScript模仿oop编程

    第一, 首先,使用关键字function定义一个类 function Shape1(ax,ay) {//此时将function看成声明类的标志 ; ; var init=function () {// ...

  5. VC 绘图,使用双缓冲技术实现

    VC 绘图,使用双缓冲技术实现 - Cloud-Datacenter-Renewable Energy-Big Data-Model - 博客频道 - CSDN.NET VC 绘图,使用双缓冲技术实现 ...

  6. Ajax效果--个人收藏

    $.ajax({ url: "../../../Tools/WeChatMenu.ashx?action=get_menu", type: "post", da ...

  7. 汉字转为unicode

    在word中输入“立项申请阶段”,将光标移到每字之后时按下组合键Alt+X. 立项申请阶段 7ACB  9879  7533  8BF7  9636  6BB5 \u7ACB\u9879\u7533\ ...

  8. win7 32位安装 python 及Numpy、scipy、matplotlib函数包

    操作系统: win7 64位,但选择安装32位的python. 1,python下载安装 https://www.python.org/downloads/ 下载2.7版,一路下一步安装. 并在pat ...

  9. 6、R语言绘制带errorbar 的柱状图

    转载:http://www.cnblogs.com/xudongliang/p/7283733.html data <- data.frame(mean = c(10, 15), sd = c( ...

  10. Spring入门第二十三课

    我们看基于XML配置的方式配置AOP 看代码: package logan.study.aop.impl; public interface ArithmeticCalculator { int ad ...