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

Reliable detection of user change from interceptor in StompSubProtocolHandler #23160

Closed
liukaixiong opened this issue Jun 20, 2019 · 1 comment
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@liukaixiong
Copy link

StompSubProtocolHandler.java - handleMessageFromClient
Send connection type messages

SimpAttributesContextHolder.setAttributesFromMessage(message);
// Messages connected are forwarded through multiple threads.
boolean sent = outputChannel.send(message);
if (sent) {
    if (isConnect) {
   // After successful forwarding, add the user to Map , In case of slow execution,
    Principal user = headerAccessor.getUser();
	if (user != null && user != session.getPrincipal()) {
		this.stompAuthentications.put(session.getId(), user);
	    }
       } 
}

StompSubProtocolHandler.java - handleMessageToClient
Receive connection type messages ...

// get user
Principal user = getUser(session); // is null 
publishEvent(new SessionConnectedEvent(this, (Message<byte[]>) message, user));

private Principal getUser(WebSocketSession session) {
       // Get the user just connected from the Map above , But in case the Map above hasn't been completed by Put, it's null.
	Principal user = this.stompAuthentications.get(session.getId());
	return user != null ? user : session.getPrincipal();
}

There is a certain probability that after the message forwarding is completed, the user has not been added to the Map, resulting in no registration in the DefaultSimpUserRegistry object.

Can you help me to have a look? Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 20, 2019
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 25, 2019
@rstoyanchev rstoyanchev added this to the 5.1.9 milestone Jun 25, 2019
@rstoyanchev rstoyanchev self-assigned this Jun 25, 2019
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 25, 2019

It does look like a possibility. Using a callback to detect the authentication as soon as the user is set via preSend from an interceptor should help.

@rstoyanchev rstoyanchev changed the title stompAuthentications Getting User's Multithread Sequential Execution Problem , Reliable detection of user change from interceptor in StompSubProtocolHandler Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants