安子我最近在做一个权限控制模块,大抵是有权限的人能从数据库中查到的信息比权限低的人查的多一些。工程用的是JPA hibernate,想做一个过滤器来设置条件过滤。
一开始安子我想过直接用aspectj来做过滤,但是不知道为啥:
@Around("this(net.risesoft.repository.DyGroupRepository)")不太好使,也不知道为啥不好使比较尴尬,这个问题留给路过的大牛来指导吧。
废话到此,言归正传~
首先研习了一下源码,发现jpaRepositoryFactory父类RepositoryFactorySupport里面代理建立repository的时候有这么一段:
@SuppressWarnings({ "unchecked" })
public T getRepository(Class repositoryInterface, Object customImplementation) {
RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface);
Class> customImplementationClass = null == customImplementation ? null : customImplementation.getClass();
RepositoryInformation information = getRepositoryInformation(metadata, customImplementationClass);
validate(information, customImplementation);
Object target = getTargetRepository(information);
// Create proxy
ProxyFactory result = new ProxyFactory();
result.setTarget(target);
result.setInterfaces(new Class[] { repositoryInterface, Repository.class });
result.addAdvice(ExposeInvocationInterceptor.INSTANCE);
if (TRANSACTION_PROXY_TYPE != null) {
result.addInterfac