Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token-based WebSocket Authentication Documentation Inaccuracy [SPR-15863] #20418

spring-issuemaster opened this issue Aug 14, 2017 · 0 comments


Copy link

@spring-issuemaster spring-issuemaster commented Aug 14, 2017

Steve Roy opened SPR-15863 and commented

The Spring documentation to register a custom websocket authentication interceptor has an inaccuracy. For custom OAuth authentication ( or any custom authentication ), the sample code indicates a security Principal should be set on the StompHeaderAccessor. However, the downstream Spring Security code expects the object set on the StompHeaderAccessor to be of type Authentication rather than Principal. ( Note, Authentication is a sub-interface of Principal. )

26.4.11 Token-based Authentication

Code example from documentation:

if (StompCommand.CONNECT.equals(accessor.getCommand())) {
    Principal user = ... ; // access authentication header(s)

Current Spring Security Code:

See Line 125

Authentication authentication;
if ((user instanceof Authentication)) {
     authentication = (Authentication) user;
else {
     authentication = this.anonymous;

When setting an object of type Principal, the check fails and the security context is set to an anonymous user.

Reference URL:

Referenced from: commits 8b64ad3, 181f002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.