浏览代码

redis 设置fastjson解析

vincent 3 年之前
父节点
当前提交
511142ef33

+ 2 - 1
server/src/main/java/edp/core/config/RedisConfig.java

@@ -19,6 +19,7 @@
 
 package edp.core.config;
 
+import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.BeanFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -47,7 +48,7 @@ public class RedisConfig {
             redisTemplate = (RedisTemplate<String, Object>) beanFactory.getBean("redisTemplate");
 
             redisTemplate.setKeySerializer(new StringRedisSerializer());
-            redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
+            redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
             redisTemplate.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
             redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
 

+ 12 - 4
server/src/main/java/edp/davinci/core/inteceptor/AuthenticationInterceptor.java

@@ -20,6 +20,7 @@
 package edp.davinci.core.inteceptor;
 
 import com.alibaba.druid.util.StringUtils;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import edp.core.annotation.AuthIgnore;
 import edp.core.annotation.AuthShare;
@@ -95,11 +96,18 @@ public class AuthenticationInterceptor implements HandlerInterceptor
             response.getWriter().print(ErrorMsg.ERR_MSG_AUTHENTICATION);
             return false;
         }
+        log.debug("{} : ticket is found in url ", request.getServletPath());
         System.out.println(">>>>>" + ticket);
-        Map<String,Object> redisMap = (Map<String, Object>) redisUtils.get(ticket);
-        Map<String,Object> userMap = (Map<String, Object>) redisMap.get("user");
-        System.out.println(userMap.get("username"));
-        String username = (String) userMap.get("username");
+        Object redisMap = (Map<String, Object>) redisUtils.get(ticket);
+        if (null == redisMap)
+        {
+            log.debug("{} : ticket is not found in redis", ticket);
+            response.setStatus(HttpCodeEnum.FORBIDDEN.getCode());
+            response.getWriter().print(ErrorMsg.ERR_MSG_PERMISSION);
+            return false;
+        }
+        JSONObject userinfo = (JSONObject) JSONObject.toJSON(redisMap);
+        String username = userinfo.getString("username");
         User user = userService.getByUsername(username);
         if (null == user)
         {