Authored by tanling

优化黑名单

@@ -33,23 +33,60 @@ public class BlackUserAspect { @@ -33,23 +33,60 @@ public class BlackUserAspect {
33 private static Map<Integer, AbstractBlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap(); 33 private static Map<Integer, AbstractBlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap();
34 34
35 35
  36 + Logger logger = LoggerFactory.getLogger(AbstractBlackUserInterceptor.class);
  37 +
  38 +
36 @Pointcut("@annotation(com.yohoufo.order.annotation.BlackUserType)") 39 @Pointcut("@annotation(com.yohoufo.order.annotation.BlackUserType)")
37 private void pointId(){ 40 private void pointId(){
38 41
39 } 42 }
40 43
  44 + public static final String UID= "uid";
  45 +
41 @Before("pointId()") 46 @Before("pointId()")
42 private void before(JoinPoint joinPoint) throws Throwable{ 47 private void before(JoinPoint joinPoint) throws Throwable{
43 48
  49 + int uid = getParamUidValue(joinPoint);
  50 + if (uid == -1){
  51 + return;
  52 + }
44 53
45 - Object[] argsa = joinPoint.getArgs(); 54 + BlackUserType blackUserAnnotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(BlackUserType.class);
46 55
47 - Annotation[][] parameterTypes = ((MethodSignature)joinPoint.getSignature()).getMethod().getParameterAnnotations(); 56 + blackUserInteceptorMap.get(blackUserAnnotation.blackType().getCode()).before(uid);
48 57
49 - BlackUserType blackUserAnnotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(BlackUserType.class); 58 + }
  59 +
  60 +
  61 + public int getParamUidValue(JoinPoint joinPoint){
50 62
51 - blackUserInteceptorMap.get(blackUserAnnotation.blackType()).before((int)argsa[0]); 63 + try{
  64 + int paramUidIndex = -1;
  65 +
  66 + String[] paramNames = ((MethodSignature)joinPoint.getSignature()).getParameterNames();
  67 + for (int i = 0; i< paramNames.length; i++){
  68 + if (UID.equals(paramNames[i])){
  69 + paramUidIndex = i;
  70 + break;
  71 + }
  72 + }
  73 +
  74 + if (paramUidIndex == -1){
  75 + return -1;
  76 + }
  77 +
  78 + Object[] argValues = joinPoint.getArgs();
  79 + for (int i = 0; i < argValues.length; i++){
  80 + if (i == paramUidIndex){
  81 + return (int)argValues[i];
  82 + }
  83 + }
  84 + }catch (Exception e){
  85 + logger.warn("black user aspect param uis. e {}",e);
  86 + return -1;
  87 + }
52 88
  89 + return -1;
53 } 90 }
54 91
55 92
@@ -119,7 +119,7 @@ yoho.message.controller.url=http://message-controller.yohoops.org/yoho-message-c @@ -119,7 +119,7 @@ yoho.message.controller.url=http://message-controller.yohoops.org/yoho-message-c
119 yoho.reviewed.controller.url=http://172.16.6.54:8063/reviewed 119 yoho.reviewed.controller.url=http://172.16.6.54:8063/reviewed
120 120
121 #rabbit address for transaction compensate 121 #rabbit address for transaction compensate
122 -rabbit_host=192.168.104.199:30005 122 +rabbit_host=192.168.102.45:5672
123 rabbit_user=yoho 123 rabbit_user=yoho
124 rabbit_password=yoho 124 rabbit_password=yoho
125 125
1 redis: 1 redis:
2 gwNoSyncRedis : 2 gwNoSyncRedis :
3 servers: 3 servers:
4 - - 192.168.102.45:6379  
5 - auth: redis9646 4 + - 192.168.104.246:6379