聊天室信息发送
This commit is contained in:
parent
10773f4f5a
commit
d6b62f282b
|
|
@ -21,7 +21,7 @@ public class WhiteListHandler {
|
||||||
"/link",
|
"/link",
|
||||||
"/auth/login",
|
"/auth/login",
|
||||||
"/event/**",
|
"/event/**",
|
||||||
"/chat/room/**"
|
// "/chat/room/**"
|
||||||
};
|
};
|
||||||
|
|
||||||
public void handle(HttpSecurity http) throws Exception {
|
public void handle(HttpSecurity http) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ import com.zhangshu.chat.demo.service.RoomCache;
|
||||||
import com.zhangshu.chat.demo.vo.UserMessageVo;
|
import com.zhangshu.chat.demo.vo.UserMessageVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.websocket.*;
|
import javax.websocket.*;
|
||||||
import javax.websocket.server.PathParam;
|
import javax.websocket.server.PathParam;
|
||||||
import javax.websocket.server.ServerEndpoint;
|
import javax.websocket.server.ServerEndpoint;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.security.Principal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -37,11 +39,15 @@ public class ChatRoom {
|
||||||
*/
|
*/
|
||||||
@OnOpen
|
@OnOpen
|
||||||
public void onOpen(Session session, @PathParam("roomId") String roomId) {
|
public void onOpen(Session session, @PathParam("roomId") String roomId) {
|
||||||
if (getRoomCache().createSuccess(roomId)) {
|
// if (getRoomCache().createSuccess(roomId)) {
|
||||||
this.sendMessage("无此房间,拒绝连接", session);
|
// this.sendMessage("无此房间,拒绝连接", session);
|
||||||
return;
|
// 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())) {
|
if (Objects.isNull(userInfo) || !getRoomCache().isExistUser(userInfo.getId())) {
|
||||||
this.sendMessage("用户验证失败或者房间内无此用户,拒绝连接", session);
|
this.sendMessage("用户验证失败或者房间内无此用户,拒绝连接", session);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue