0

我正在开发一个带有 spring-messaging 和 STOMP over sockJs 的服务器。我想通过 websockets 进行授权。所以从客户端我确实发送了一些令牌,然后我通过令牌获取针用户,我想将我的会话与这个用户相关联,我接下来做了:

private void authorizeUser(Profile profile) {

    SignedUser signedUser = new SignedUser(profile);
    List<GrantedAuthority> authorities = Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));

    UsernamePasswordAuthenticationToken authentication =
            new UsernamePasswordAuthenticationToken(signedUser, null, authorities);


    SecurityContextHolder.getContext().setAuthentication(authentication);
}

但是会话没有关联,有人可以帮我解决这个问题吗?

谢谢。

4

1 回答 1

0

按照下面的链接。Spring Security 4.0 允许开箱即用的 Web Socket 支持。

https://spring.io/blog/2014/09/16/preview-spring-security-websocket-support-sessions

http://spring.io/blog/2014/08/21/preview-spring-security-websocket-support

于 2015-04-06T03:29:20.187 回答