优化websocket

This commit is contained in:
zhou-hao
2017-11-24 14:22:11 +08:00
parent baf88d1e59
commit 3f4d6abbd6
4 changed files with 4 additions and 59 deletions

View File

@@ -1,53 +0,0 @@
package org.hswebframework.web.socket.handler;
import org.hswebframework.web.authorization.Authentication;
import org.hswebframework.web.authorization.token.UserTokenManager;
import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.WebSocketSession;
import java.util.*;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public class WebSocketUtils {
public static Authentication getAuthentication(UserTokenManager container, WebSocketSession session) {
Authentication authentication = Authentication
.current()
.orElseGet(() -> ((Authentication) session.getAttributes().get(Authentication.class.getName())));
if (authentication != null) {
return authentication;
}
HttpHeaders headers = session.getHandshakeHeaders();
List<String> cookies = headers.get("Cookie");
if (cookies == null || cookies.isEmpty()) {
return null;
}
String[] cookie = cookies.get(0).split("[;]");
Map<String, Set<String>> sessionId = new HashMap<>();
for (String aCookie : cookie) {
String[] tmp = aCookie.split("[=]");
if (tmp.length == 2) {
sessionId.computeIfAbsent(tmp[0].trim(), k -> new HashSet<>())
.add(tmp[1].trim());
}
}
// TODO: 2017/7/12 修改权限获取方式
throw new UnsupportedOperationException();
// Function<Set<String>, Optional<Authentication>> userGetter = set ->
// set == null ? Optional.empty() : set.stream()
// .map(token::getByToken)
// .filter(Objects::nonNull)
// .findFirst();
//
// return userGetter.apply(sessionId.get("SESSION"))
// .orElseGet(() -> userGetter.apply(sessionId.get("JSESSIONID")).orElse(null));
}
}

View File

@@ -4,8 +4,6 @@ import org.hswebframework.web.socket.WebSocketSessionListener;
import org.springframework.web.socket.WebSocketSession;
/**
* TODO 完成注释
*
* @author zhouhao
*/
public interface WebSocketMessager extends WebSocketSessionListener {

View File

@@ -12,7 +12,9 @@ public interface CommandProcessor {
void execute(CommandRequest command);
void init();
default void init() {
}
void destroy();
default void destroy() {
}
}

View File

@@ -24,8 +24,6 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
import java.util.List;
/**
* TODO 完成注释
*
* @author zhouhao
*/
@Configuration