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. 搞事情 -- python之线程

    简介 操作系统线程理论 线程概念的引入背景 线程的特点 进程和线程的关系 使用线程的实际场景 用户级线程和内核级线程(了解) 线程和python 理论知识 线程的创建Threading.Thread类 ...

  2. bzoj 3439: Kpm的MC密码 Trie+动态开点线段树

    题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3439 题解: 首先我们发现这道题要查的是后缀不是前缀. 如果查前缀就可以迅速查找到字符串 ...

  3. Linux 下使用 ssh 登录局域网其他电脑的方法

    Linux 下使用 ssh 登录局域网其他电脑的方法 首先查看电脑是否安装 ssh 客户端,如果没有执行下面命令安装客户端. sudo apt-get install openssh-client s ...

  4. 向vivi中加入命令

    在vivi的lib/command.c中添加自己的命令 核心数据结构user_command. typedef struct user_command { const char *name;      ...

  5. HDOJ2043(JAVAset容器练习)

    import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; public class Main { ...

  6. hdoj1113(字符串map应用)

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  7. 【转】Pro Android学习笔记(十二):了解Intent(下)

    解析Intent,寻找匹配Activity 如果给出component名字(包名.类名)是explicit intent,否则是implicit intent.对于explicit intent,关键 ...

  8. winform 客户端 HTTP协议与服务端通信以及解决中文乱码

    本来从来没有仔细研究过Http协议,今天因为公司业务需求,调试了半天,终于现在会Winform用Http协议与服务端通信了,其中常用的有POST和Get方式: 仔细看了人人网和新浪等大部分都是采用GE ...

  9. TCP/IP的3次握手和4次握手

    在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接,如图1所示. (1) 第一次握手:建立连接时,客户端A发送SYN包(SYN=j)到服务器B,并进入SYN_SEND状态,等 ...

  10. RStudio版本管理 整合Git

    本文为原创,转载注明出处. 系统环境: win7 x64 R-3.1.0-win.exe RStudio-0.98.507.exe 前置条件:必须拥有github仓库: 如:https://githu ...