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-projects-issues opened this issue Aug 14, 2017 · 0 comments
in: web type: task


Copy link

spring-projects-issues 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
in: web type: task
None yet

No branches or pull requests

2 participants