Top Description Inners Fields Constructors Methods
org.springframework.messaging.simp.user

public Class DefaultUserDestinationResolver

extends Object
implements UserDestinationResolver
Class Inheritance
All Implemented Interfaces
org.springframework.messaging.simp.user.UserDestinationResolver
Imports
java.security.Principal, java.util.Collections, .HashSet, .Set, org.apache.commons.logging.Log, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageHeaders, org.springframework.messaging.simp.SimpLogging, .SimpMessageHeaderAccessor, .SimpMessageType, org.springframework.util.Assert, .StringUtils

A default implementation of UserDestinationResolver that relies on a SimpUserRegistry to find active sessions for a user.

When a user attempts to subscribe, e.g. to "/user/queue/position-updates", the "/user" prefix is removed and a unique suffix added based on the session id, e.g. "/queue/position-updates-useri9oqdfzo" to ensure different users can subscribe to the same logical destination without colliding.

When sending to a user, e.g. "/user/{username}/queue/position-updates", the "/user/{username}" prefix is removed and a suffix based on active session id's is added, e.g. "/queue/position-updates-useri9oqdfzo".

Authors
Rossen Stoyanchev, Brian Clozel
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DefaultUserDestinationResolver.ParseResult

A temporary placeholder for a parsed source "user" destination.

Field Summary

Modifier and TypeField and Description
private static final Log
private String
private boolean
private final SimpUserRegistry

Constructor Summary

AccessConstructor and Description
public
DefaultUserDestinationResolver(SimpUserRegistry
the registry, never null
userRegistry
)

Create an instance that will access user session id information through the provided registry.

Method Summary

Modifier and TypeMethod and Description
protected boolean
checkDestination(String destination, String requiredPrefix)

public String
getDestinationPrefix()

Return the configured prefix for user destinations.

private Set<String>
getSessionIdsByUser(String userName, String sessionId)

public SimpUserRegistry
getSimpUserRegistry()

Return the configured SimpUserRegistry.

protected String

Returns:

a target destination, or null if none
getTargetDestination
(String
the source destination from the input message.
sourceDestination
,
String
a subset of the destination without any user prefix.
actualDestination
,
String
the id of an active user session, never null.
sessionId
,
String
the target user, possibly null, e.g if not authenticated.
user
)

This method determines how to translate the source "user" destination to an actual target destination for the given active user session.

public boolean
isRemoveLeadingSlash()

Whether to remove the leading slash from target destinations.

private DefaultUserDestinationResolver.ParseResult
parse(Message<?> message)

private DefaultUserDestinationResolver.ParseResult
parseMessage(MessageHeaders headers, String sourceDest)

private DefaultUserDestinationResolver.ParseResult
parseSubscriptionMessage(Message<?> message, String sourceDestination)

public UserDestinationResult
resolveDestination(Message<?>
the message to try to resolve
message
)

Implements org.springframework.messaging.simp.user.UserDestinationResolver.resolveDestination.

Resolve the given message with a user destination to one or more messages with actual destinations, one for each active user session.
public void
setRemoveLeadingSlash(boolean
whether to remove the leading slash
remove
)

Use this property to indicate whether the leading slash from translated user destinations should be removed or not.

public void
setUserDestinationPrefix(String
the prefix to use
prefix
)

The prefix used to identify user destinations.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

loggerback to summary
private static final Log logger
prefixback to summary
private String prefix
removeLeadingSlashback to summary
private boolean removeLeadingSlash
userRegistryback to summary
private final SimpUserRegistry userRegistry

Constructor Detail

DefaultUserDestinationResolverback to summary
public DefaultUserDestinationResolver(SimpUserRegistry userRegistry)

Create an instance that will access user session id information through the provided registry.

Parameters
userRegistry:SimpUserRegistry

the registry, never null

Method Detail

checkDestinationback to summary
protected boolean checkDestination(String destination, String requiredPrefix)
getDestinationPrefixback to summary
public String getDestinationPrefix()

Return the configured prefix for user destinations.

getSessionIdsByUserback to summary
private Set<String> getSessionIdsByUser(String userName, String sessionId)
getSimpUserRegistryback to summary
public SimpUserRegistry getSimpUserRegistry()

Return the configured SimpUserRegistry.

getTargetDestinationback to summary
protected String getTargetDestination(String sourceDestination, String actualDestination, String sessionId, String user)

This method determines how to translate the source "user" destination to an actual target destination for the given active user session.

Parameters
sourceDestination:String

the source destination from the input message.

actualDestination:String

a subset of the destination without any user prefix.

sessionId:String

the id of an active user session, never null.

user:String

the target user, possibly null, e.g if not authenticated.

Returns:String

a target destination, or null if none

Annotations
@SuppressWarnings:unused
@Nullable
isRemoveLeadingSlashback to summary
public boolean isRemoveLeadingSlash()

Whether to remove the leading slash from target destinations.

Since
4.3.14
parseback to summary
private DefaultUserDestinationResolver.ParseResult parse(Message<?> message)
Annotations
@Nullable
parseMessageback to summary
private DefaultUserDestinationResolver.ParseResult parseMessage(MessageHeaders headers, String sourceDest)
parseSubscriptionMessageback to summary
private DefaultUserDestinationResolver.ParseResult parseSubscriptionMessage(Message<?> message, String sourceDestination)
Annotations
@Nullable
resolveDestinationback to summary
public UserDestinationResult resolveDestination(Message<?> message)

Implements org.springframework.messaging.simp.user.UserDestinationResolver.resolveDestination.

Doc from org.springframework.messaging.simp.user.UserDestinationResolver.resolveDestination.

Resolve the given message with a user destination to one or more messages with actual destinations, one for each active user session.

Parameters
message:Message<?>

the message to try to resolve

Returns:UserDestinationResult

0 or more target messages (one for each active session), or null if the source message does not contain a user destination.

Annotations
@Override
@Nullable
setRemoveLeadingSlashback to summary
public void setRemoveLeadingSlash(boolean remove)

Use this property to indicate whether the leading slash from translated user destinations should be removed or not. This depends on the destination prefixes the message broker is configured with.

By default this is set to false, i.e. "do not change the target destination", although AbstractMessageBrokerConfiguration may change that to true if the configured destinations do not have a leading slash.

Parameters
remove:boolean

whether to remove the leading slash

Since
4.3.14
setUserDestinationPrefixback to summary
public void setUserDestinationPrefix(String prefix)

The prefix used to identify user destinations. Any destinations that do not start with the given prefix are not be resolved.

The default prefix is "/user/".

Parameters
prefix:String

the prefix to use

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.messaging.simp.user back to summary

private Class DefaultUserDestinationResolver.ParseResult

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.simp.user.DefaultUserDestinationResolver.ParseResult

A temporary placeholder for a parsed source "user" destination.

Field Summary

Modifier and TypeField and Description
private final String
private final Set<String>
private final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
ParseResult(String sourceDest, String actualDest, String subscribeDest, Set<String> sessionIds, String user)

Method Summary

Modifier and TypeMethod and Description
public String
getActualDestination()

The actual destination, without any user prefix, e.g. "/queue/position-updates".

public Set<String>
getSessionIds()

The session id or id's for the user.

public String
getSourceDestination()

The destination from the source message, e.g. "/user/{user}/queue/position-updates".

public String
getSubscribeDestination()

The user destination as it would be on a subscription, "/user/queue/position-updates".

public String
getUser()

The name of the user associated with the session.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualDestinationback to summary
private final String actualDestination
sessionIdsback to summary
private final Set<String> sessionIds
sourceDestinationback to summary
private final String sourceDestination
subscribeDestinationback to summary
private final String subscribeDestination
userback to summary
private final String user
Annotations
@Nullable

Constructor Detail

ParseResultback to summary
public ParseResult(String sourceDest, String actualDest, String subscribeDest, Set<String> sessionIds, String user)

Method Detail

getActualDestinationback to summary
public String getActualDestination()

The actual destination, without any user prefix, e.g. "/queue/position-updates".

getSessionIdsback to summary
public Set<String> getSessionIds()

The session id or id's for the user.

getSourceDestinationback to summary
public String getSourceDestination()

The destination from the source message, e.g. "/user/{user}/queue/position-updates".

getSubscribeDestinationback to summary
public String getSubscribeDestination()

The user destination as it would be on a subscription, "/user/queue/position-updates".

getUserback to summary
public String getUser()

The name of the user associated with the session.

Annotations
@Nullable