自己写一套权限控制,去掉spring security
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.zyplayer.doc.data.utils;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class BeanUtil {
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T extends Annotation> T getAnnotation(JoinPoint pjp, Class<T> t) throws Exception {
|
||||
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
|
||||
T annotation = method.getAnnotation(t);// 方法上定义的
|
||||
if (annotation == null) {
|
||||
annotation = (T) pjp.getSignature().getDeclaringType().getAnnotation(t);// 类上定义的
|
||||
if (annotation == null) {
|
||||
Object target = pjp.getTarget();
|
||||
annotation = target.getClass().getAnnotation(t);// 实现类上定义的
|
||||
if (annotation == null) {
|
||||
Signature sig = pjp.getSignature();
|
||||
if (sig instanceof MethodSignature) {
|
||||
MethodSignature msig = (MethodSignature) sig;
|
||||
Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
|
||||
annotation = currentMethod.getAnnotation(t);// 实现类的方法上定义的
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.zyplayer.doc.data.utils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 缓存工具类
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年05月25日
|
||||
*/
|
||||
public class CacheUtil {
|
||||
|
||||
// 定期清除过期的key
|
||||
static {
|
||||
Timer timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
for (Map.Entry<String, CacheTime> entry : cacheTimeMap.entrySet()) {
|
||||
CacheTime cacheTime = entry.getValue();
|
||||
if (currentTimeMillis - cacheTime.getLastVisitTime() < (cacheTime.getSecond() * 1000)) {
|
||||
continue;
|
||||
}
|
||||
cacheMap.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
private static Map<String, Object> cacheMap = new ConcurrentHashMap<>();
|
||||
private static Map<String, CacheTime> cacheTimeMap = new ConcurrentHashMap<>();
|
||||
|
||||
public static void put(String key, Object value) {
|
||||
put(key, value, (long) (60 * 60 * 12));
|
||||
}
|
||||
|
||||
public static void put(String key, Object value, Long second) {
|
||||
cacheMap.put(key, value);
|
||||
cacheTimeMap.put(key, new CacheTime(second));
|
||||
}
|
||||
|
||||
public static void remove(String key) {
|
||||
cacheMap.remove(key);
|
||||
cacheTimeMap.remove(key);
|
||||
}
|
||||
|
||||
public static <T> T get(String key) {
|
||||
CacheTime cacheTime = cacheTimeMap.get(key);
|
||||
if (cacheTime != null) {
|
||||
cacheTime.setLastVisitTime(System.currentTimeMillis());
|
||||
cacheTimeMap.put(key, cacheTime);
|
||||
}
|
||||
return (T) cacheMap.get(key);
|
||||
}
|
||||
|
||||
private static class CacheTime {
|
||||
private Long second;
|
||||
private Long lastVisitTime;
|
||||
|
||||
public CacheTime(Long second) {
|
||||
this.second = second;
|
||||
this.lastVisitTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Long getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public void setSecond(Long second) {
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public Long getLastVisitTime() {
|
||||
return lastVisitTime;
|
||||
}
|
||||
|
||||
public void setLastVisitTime(Long lastVisitTime) {
|
||||
this.lastVisitTime = lastVisitTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user