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. ACM学习历程—HDU 5451 Best Solver(Fibonacci数列 && 快速幂)(2015沈阳网赛1002题)

    Problem Description The so-called best problem solver can easily solve this problem, with his/her ch ...

  2. 一:ORM关系对象映射(Object Relational Mapping,简称ORM)

    狼来的日子里! 奋发博取 10)django-ORM(创建,字段类型,字段参数) 一:ORM关系对象映射(Object Relational Mapping,简称ORM) ORM分两种: DB fir ...

  3. 关于openstack自动化安装的一点思考

    在openstack针对具体应用的解决方案已成型之后,按照官方文档安装openstack实际上就成了一个繁琐的事情. 我有一个设想,之前实施了一点,还未成功,但是也想记录下来.最终目标:使用U盘直接部 ...

  4. qtp ie_hook

    今天要讲的内容是注册异类子控件授予强制HOOK,名字有点抽象,简单的说就是在一个QTP可识别的A类插件窗口对象中存在着B类插件的控件对象, 最常见的例子就是在应用程序中内嵌一个Browser对象子控件 ...

  5. python 基础 操作文件和目录

    获得当前目录路径 :os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir() 删除一个文件:os.remove(filename) 删除多个空目录 :os.removefir ...

  6. play的job执行方式

    除了使用Quartz CRON trigger, 还可以写一个action来专门触发job,这样子就可以随时启动job的开始,而且还能并行其他的任务.较方便.

  7. ViewPage+Fragment(仿微信切换带通知)

    第一步 : 布局文件 activity_main.xml <?xml version="1.0" encoding="utf-8"?> <Li ...

  8. day18-事务与连接池 6.事务隔离级别与解决问题

    开两个cmd窗口,相当于两个事务. read-uncommitted这种级别是解决不了任何问题的,它什么情况都能出现.刚才演示了脏读,再演示就出现了不可重复读. read-committed隔离级别能 ...

  9. [51nod1094]和为k的连续区间

    法一:暴力$O({n^2})$看脸过 #include<bits/stdc++.h> using namespace std; typedef long long ll; ],sum[]; ...

  10. 理解setTimeout和setInterval

    setTimeout和setInterval,这两个js函数都是用来定时执行.setTimeout执行一次,setInterval执行多次. 问题出现在今天,使用setInterval是,设置执行速度 ...