Ver Fonte

fix websocket改明文传输

classic_blue há 1 mês atrás
pai
commit
0689ade881

+ 2 - 5
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourGroupController.java

@@ -39,7 +39,6 @@ import com.tourism.webadmin.back.vo.TourImGroupTypeVo;
 import com.tourism.webadmin.back.vo.TourImGroupVo;
 import com.tourism.webadmin.back.vo.TourImMemberVo;
 import com.tourism.webadmin.enums.MyAttentionStatus;
-import com.tourism.webadmin.ws.utils.AESUtils;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.xml.bind.DatatypeConverter;
@@ -97,8 +96,6 @@ public class TourGroupController {
     private TourImMessageService tourImMessageService;
     @Autowired
     private TourUserService tourUserService;
-    @Autowired
-    private AESUtils aesUtil;
 
 
     /**
@@ -253,8 +250,8 @@ public class TourGroupController {
         //对ID进行加密
         for (TourImMemberVo vo : vos) {
             String id = vo.getUserId();
-            String encrypt = aesUtil.encrypt(id);
-            vo.setPass(encrypt);
+//            String encrypt = aesUtil.encrypt(id);
+            vo.setPass(id);
         }
         tourImGroupVo.setMemberList(vos);
 

+ 2 - 6
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourMemberController.java

@@ -29,11 +29,9 @@ import com.tourism.webadmin.back.service.TourUserService;
 import com.tourism.webadmin.back.vo.TourImMemberVo;
 import com.tourism.webadmin.enums.GroupRole;
 import com.tourism.webadmin.ws.handle.SystemMessageHandler;
-import com.tourism.webadmin.ws.utils.AESUtils;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.catalina.User;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -72,8 +70,6 @@ public class TourMemberController {
     @Autowired
     private TourGroupService tourGroupService;
     @Autowired
-    private AESUtils aesUtil;
-    @Autowired
     private SystemMessageHandler systemMessageHandler;
     /**
      * 获取群成员信息
@@ -335,8 +331,8 @@ public class TourMemberController {
             //对ID进行加密
             for (GroupUserListVo vo : groupUserListVos) {
                 String id = vo.getUserId();
-                String encrypt = aesUtil.encrypt(id);
-                vo.setPass(encrypt);
+//                String encrypt = aesUtil.encrypt(id);
+                vo.setPass(id);
             }
             return ResponseResult.success(collect1);
         }

+ 4 - 5
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourismUserController.java

@@ -22,7 +22,6 @@ import com.tourism.webadmin.app.website.dto.WebsiteTourUserDto;
 import com.tourism.webadmin.back.model.TourUser;
 import com.tourism.webadmin.back.service.TourUserService;
 import com.tourism.webadmin.back.vo.TourUserVo;
-import com.tourism.webadmin.ws.utils.AESUtils;
 import com.volcengine.util.AesUtil;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.servlet.http.HttpServletResponse;
@@ -53,8 +52,8 @@ public class TourismUserController {
     private UpDownloaderFactory upDownloaderFactory;
     @Autowired
     private TourUserService tourUserService;
-    @Autowired
-    private AESUtils aesUtil;
+//    @Autowired
+//    private AESUtils aesUtil;
 
     /**
      * 更新门户用户管理数据。
@@ -93,8 +92,8 @@ public class TourismUserController {
             return ResponseResult.error(ErrorCodeEnum.UNAUTHORIZED_LOGIN);
         }
         TourUserVo tourUserVo = MyModelUtil.copyTo(tourUser, TourUserVo.class);
-        String encrypt = aesUtil.encrypt(userId.toString());
-        tourUserVo.setPass(encrypt);
+//        String encrypt = aesUtil.encrypt(userId.toString());
+        tourUserVo.setPass(userId.toString());
         return ResponseResult.success(tourUserVo);
     }
 

+ 8 - 9
application-webadmin/src/main/java/com/tourism/webadmin/app/website/service/impl/TourMessageServiceImpl.java

@@ -37,7 +37,6 @@ import com.tourism.webadmin.back.model.constant.NoticeType;
 import com.tourism.webadmin.back.service.*;
 import com.tourism.webadmin.enums.GroupRole;
 import com.tourism.webadmin.enums.SystemDefaultHead;
-import com.tourism.webadmin.ws.utils.AESUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -60,8 +59,8 @@ public class TourMessageServiceImpl extends ServiceImpl<TourImMessageMapper, Tou
     private TourImMessageMapper tourImMessageMapper;
     @Autowired
     private TourImMessageService messageService;
-    @Autowired
-    private AESUtils aesUtil;
+//    @Autowired
+//    private AESUtils aesUtil;
     @Autowired
     private TourMemberService tourMemberService;
     @Autowired
@@ -147,8 +146,8 @@ public class TourMessageServiceImpl extends ServiceImpl<TourImMessageMapper, Tou
 
         //对消息发送人进行加密
         for (GroupMessageVo groupMessageVo : list) {
-            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
-            groupMessageVo.setSendUserId(encrypt);
+//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
+            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
         }
         resultMap.put("data",list);
         resultMap.put("count",count);
@@ -372,8 +371,8 @@ public class TourMessageServiceImpl extends ServiceImpl<TourImMessageMapper, Tou
 
         //对消息发送人进行加密
         for (GroupMessageVo groupMessageVo : dataList) {
-            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
-            groupMessageVo.setSendUserId(encrypt);
+//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
+            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
         }
         groupMessageVoMyPageData.setDataList(dataList);
         return groupMessageVoMyPageData;
@@ -630,8 +629,8 @@ public class TourMessageServiceImpl extends ServiceImpl<TourImMessageMapper, Tou
         }
         //对消息发送人进行加密
         for (GroupMessageVo groupMessageVo : groupMessageVos) {
-            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
-            groupMessageVo.setSendUserId(encrypt);
+//            String encrypt = aesUtil.encrypt(groupMessageVo.getCreateUserId());
+            groupMessageVo.setSendUserId(groupMessageVo.getCreateUserId());
         }
         return groupMessageVos.stream().filter(o -> !o.getId().equals(messageId)).collect(Collectors.toList());
     }

+ 2 - 3
application-webadmin/src/main/java/com/tourism/webadmin/ws/handle/SystemMessageHandler.java

@@ -14,7 +14,6 @@ import com.tourism.webadmin.enums.MessageLimitType;
 import com.tourism.webadmin.enums.NoticeType;
 import com.tourism.webadmin.ws.service.IMessageService;
 import com.tourism.webadmin.ws.service.impl.IGroupMessageServiceImpl;
-import com.tourism.webadmin.ws.utils.AESUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationContext;
@@ -52,7 +51,7 @@ public class SystemMessageHandler extends AbstractWebSocketHandler {
 
     private TourImMemberMapper tourImMemberMapper;
 
-    private AESUtils aesUtil;
+//    private AESUtils aesUtil;
 
     private static Map<String, WebSocketSession> sessionMap = new ConcurrentHashMap<>();
 
@@ -64,7 +63,7 @@ public class SystemMessageHandler extends AbstractWebSocketHandler {
 
     public SystemMessageHandler(ApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
-        this.aesUtil = applicationContext.getBean(AESUtils.class);
+//        this.aesUtil = applicationContext.getBean(AESUtils.class);
         this.tourMemberService= applicationContext.getBean(TourMemberService.class);
         this.tourUserService = applicationContext.getBean(TourUserService.class);
         this.tourImGroupService = applicationContext.getBean(TourImGroupService.class);

+ 3 - 4
application-webadmin/src/main/java/com/tourism/webadmin/ws/intercept/SystemMessageInterceptor.java

@@ -1,6 +1,5 @@
 package com.tourism.webadmin.ws.intercept;
 
-import com.tourism.webadmin.ws.utils.AESUtils;
 import jakarta.servlet.http.HttpServletRequest;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
@@ -25,9 +24,9 @@ public class SystemMessageInterceptor implements HandshakeInterceptor {
             if (StringUtils.isBlank(userId)){
                 return false;
             }
-            AESUtils bean = this.applicationContext.getBean(AESUtils.class);
-            String decrypt = bean.decrypt(userId);
-            attributes.put("userId", decrypt);
+//            AESUtils bean = this.applicationContext.getBean(AESUtils.class);
+//            String decrypt = bean.decrypt(userId);
+            attributes.put("userId", userId);
             return true;
         }
         return false;

+ 3 - 3
application-webadmin/src/main/java/com/tourism/webadmin/ws/service/impl/IGroupMessageServiceImpl.java

@@ -6,7 +6,7 @@ import com.tourism.webadmin.app.website.dto.MessageDTO;
 import com.tourism.webadmin.back.model.TourImMessage;
 import com.tourism.webadmin.back.service.TourImMessageService;
 import com.tourism.webadmin.ws.service.IMessageService;
-import com.tourism.webadmin.ws.utils.AESUtils;
+//import com.tourism.webadmin.ws.utils.AESUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
 
@@ -18,11 +18,11 @@ public class IGroupMessageServiceImpl implements IMessageService {
 
     private TourImMessageService tourImMessageService;
 
-    private AESUtils aesUtil;
+//    private AESUtils aesUtil;
 
     public IGroupMessageServiceImpl(ApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
-        this.aesUtil=applicationContext.getBean(AESUtils.class);
+//        this.aesUtil=applicationContext.getBean(AESUtils.class);
         this.tourImMessageService=applicationContext.getBean(TourImMessageService.class);
     }
     @Override

+ 31 - 31
application-webadmin/src/main/java/com/tourism/webadmin/ws/utils/AESUtils.java

@@ -1,31 +1,31 @@
-package com.tourism.webadmin.ws.utils;
-
-import cn.hutool.crypto.Mode;
-import cn.hutool.crypto.Padding;
-import cn.hutool.crypto.symmetric.AES;
-import com.tourism.common.additional.uuid.IdUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class AESUtils {
-    private String key = IdUtils.simpleUUID().substring(0,16);
-    private String iv = IdUtils.simpleUUID().substring(0,16);
-    @Bean
-    public AES instance(){
-        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());
-        return aes;
-    }
-    @Autowired
-    private AES aes;
-    public String encrypt(String content){
-        String encrypted = aes.encryptHex(content);
-        return encrypted;
-    }
-    public String decrypt(String encrypted){
-        String decryptStr = aes.decryptStr(encrypted);
-        return decryptStr;
-    }
-
-}
+//package com.tourism.webadmin.ws.utils;
+//
+//import cn.hutool.crypto.Mode;
+//import cn.hutool.crypto.Padding;
+//import cn.hutool.crypto.symmetric.AES;
+//import com.tourism.common.additional.uuid.IdUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//
+//@Configuration
+//public class AESUtils {
+//    private String key = IdUtils.simpleUUID().substring(0,16);
+//    private String iv = IdUtils.simpleUUID().substring(0,16);
+//    @Bean
+//    public AES instance(){
+//        AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), iv.getBytes());
+//        return aes;
+//    }
+//    @Autowired
+//    private AES aes;
+//    public String encrypt(String content){
+//        String encrypted = aes.encryptHex(content);
+//        return encrypted;
+//    }
+//    public String decrypt(String encrypted){
+//        String decryptStr = aes.decryptStr(encrypted);
+//        return decryptStr;
+//    }
+//
+//}