|
@@ -1,7 +1,8 @@
|
|
|
package com.flow.common.websocket.core;
|
|
|
|
|
|
-import com.flow.common.core.util.ApplicationContextUtil;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.Ordered;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.messaging.Message;
|
|
@@ -14,6 +15,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.Objects;
|
|
@@ -23,8 +25,12 @@ import java.util.Objects;
|
|
|
* 客户端入站通道拦截器
|
|
|
*/
|
|
|
@Order(Ordered.HIGHEST_PRECEDENCE + 99)
|
|
|
-@Slf4j
|
|
|
+@Component
|
|
|
public class ClientInboundChannelInterceptor implements ChannelInterceptor {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ClientInboundChannelInterceptor.class);
|
|
|
+ @Autowired
|
|
|
+ private TokenStore tokenStore;
|
|
|
+
|
|
|
/**
|
|
|
* 实际消息发送频道之前调用
|
|
|
*
|
|
@@ -38,7 +44,7 @@ public class ClientInboundChannelInterceptor implements ChannelInterceptor {
|
|
|
if (Objects.nonNull(accessor)) {
|
|
|
StompPrincipal user = (StompPrincipal) accessor.getUser();
|
|
|
if (Objects.nonNull(user)) {
|
|
|
- OAuth2Authentication auth2Authentication = ApplicationContextUtil.getBean(TokenStore.class).readAuthentication(user.getToken());
|
|
|
+ OAuth2Authentication auth2Authentication = tokenStore.readAuthentication(user.getToken());
|
|
|
SecurityContextHolder.getContext().setAuthentication(auth2Authentication);
|
|
|
}
|
|
|
if (Objects.nonNull(accessor.getCommand())) {
|
|
@@ -48,7 +54,7 @@ public class ClientInboundChannelInterceptor implements ChannelInterceptor {
|
|
|
if (!StringUtils.isEmpty(authorization)) {
|
|
|
try {
|
|
|
String token = authorization.replace("Bearer ", "");
|
|
|
- OAuth2Authentication oAuth2Authentication = ApplicationContextUtil.getBean(TokenStore.class).readAuthentication(token);
|
|
|
+ OAuth2Authentication oAuth2Authentication = tokenStore.readAuthentication(token);
|
|
|
SecurityContextHolder.getContext().setAuthentication(oAuth2Authentication);
|
|
|
UserDetails userDetails = (UserDetails) oAuth2Authentication.getPrincipal();
|
|
|
// 设置当前访问器的认证用户
|