StompHandshakeHandler.java
780 Bytes
package com.huaheng.pc.stompwebsocket;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.pc.system.user.domain.User;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import java.security.Principal;
import java.util.Map;
public class StompHandshakeHandler extends DefaultHandshakeHandler {
@Override
protected Principal determineUser(ServerHttpRequest request,
WebSocketHandler wsHandler,
Map<String, Object> attributes) {
User user = ShiroUtils.getUser();
return new StompPrincipal(user.getLoginName());
}
}