https://github.com/spring-projects/spring-framework/blob/master/src/docs/asciidoc/web/web-websocket.adoc#token-based-authenticationに従ってトークンベースの認証を実装しようとしています。SockJS/STOMP Webソケット用のSpringセキュリティ「トークンベースの認証」
私はHTTP認証のためにBasic Authを使用しています。したがって、認証が成功すると、Springはx-auth-tokenを返します。 STOMP CONNECTコマンドにこのトークンを追加します。
@Configuration
@EnableWebSocketMessageBroker
public class MyConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.setInterceptors(new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
StompHeaderAccessor accessor =
MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if (StompCommand.CONNECT.equals(accessor.getCommand())) {
String authToken = accessor.getFirstNativeHeader("X-Auth-Token");
log.debug("webSocket token is {}", authToken);
Principal user = ... ; // access authentication header(s)
accessor.setUser(user);
}
return message;
}
});
}
}
しかし、私は "Principal user = ...;"でどのように行うのかは全く分かりません。トークンを使ってどのようにPrincipleを得ることができますか?いずれかの人が光を当てることができますか?
助けることができています[WebSocket Authentication and Authorization in Spring]の複製(https://stackoverflow.com/questions/45405332/websocket-authentication-and-authorization-in-spring) –