聊天室信息发送

This commit is contained in:
chanbook 2022-08-08 16:34:13 +08:00
parent 10773f4f5a
commit d6b62f282b
2 changed files with 11 additions and 5 deletions

View File

@ -21,7 +21,7 @@ public class WhiteListHandler {
"/link",
"/auth/login",
"/event/**",
"/chat/room/**"
// "/chat/room/**"
};
public void handle(HttpSecurity http) throws Exception {

View File

@ -10,12 +10,14 @@ import com.zhangshu.chat.demo.service.RoomCache;
import com.zhangshu.chat.demo.vo.UserMessageVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.security.Principal;
import java.util.*;
@Slf4j
@ -37,11 +39,15 @@ public class ChatRoom {
*/
@OnOpen
public void onOpen(Session session, @PathParam("roomId") String roomId) {
if (getRoomCache().createSuccess(roomId)) {
this.sendMessage("无此房间,拒绝连接", session);
return;
// if (getRoomCache().createSuccess(roomId)) {
// this.sendMessage("无此房间,拒绝连接", session);
// return;
// }
Principal userPrincipal = session.getUserPrincipal();
if (Objects.isNull(userPrincipal)) {
this.sendMessage("用户验证失败,拒绝连接", session);
}
UserDetailsImpl userInfo = (UserDetailsImpl) session.getUserPrincipal();
UserDetailsImpl userInfo = (UserDetailsImpl)((Authentication) userPrincipal).getPrincipal();
if (Objects.isNull(userInfo) || !getRoomCache().isExistUser(userInfo.getId())) {
this.sendMessage("用户验证失败或者房间内无此用户,拒绝连接", session);
return;