public class DefaultUserDestinationResolver extends java.lang.Object implements UserDestinationResolver
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".
Modifier and Type | Class and Description |
---|---|
private static class |
DefaultUserDestinationResolver.ParseResult
A temporary placeholder for a parsed source "user" destination.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
keepLeadingSlash |
private static Log |
logger |
private java.lang.String |
prefix |
private SimpUserRegistry |
userRegistry |
Constructor and Description |
---|
DefaultUserDestinationResolver(SimpUserRegistry userRegistry)
Create an instance that will access user session id information through
the provided registry.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkDestination(java.lang.String destination,
java.lang.String requiredPrefix) |
java.lang.String |
getDestinationPrefix()
Return the configured prefix for user destinations.
|
SimpUserRegistry |
getSimpUserRegistry()
Return the configured
SimpUserRegistry . |
protected java.lang.String |
getTargetDestination(java.lang.String sourceDestination,
java.lang.String actualDestination,
java.lang.String sessionId,
java.lang.String user)
This method determines how to translate the source "user" destination to an
actual target destination for the given active user session.
|
private DefaultUserDestinationResolver.ParseResult |
parse(Message<?> message) |
UserDestinationResult |
resolveDestination(Message<?> message)
Resolve the given message with a user destination to one or more messages
with actual destinations, one for each active user session.
|
void |
setPathMatcher(PathMatcher pathMatcher)
Provide the
PathMatcher in use for working with destinations
which in turn helps to determine whether the leading slash should be
kept in actual destinations after removing the
userDestinationPrefix . |
void |
setUserDestinationPrefix(java.lang.String prefix)
The prefix used to identify user destinations.
|
java.lang.String |
toString() |
private static final Log logger
private final SimpUserRegistry userRegistry
private java.lang.String prefix
private boolean keepLeadingSlash
public DefaultUserDestinationResolver(SimpUserRegistry userRegistry)
userRegistry
- the registry, never null
public SimpUserRegistry getSimpUserRegistry()
SimpUserRegistry
.public void setUserDestinationPrefix(java.lang.String prefix)
The default prefix is "/user/".
prefix
- the prefix to usepublic java.lang.String getDestinationPrefix()
public void setPathMatcher(PathMatcher pathMatcher)
PathMatcher
in use for working with destinations
which in turn helps to determine whether the leading slash should be
kept in actual destinations after removing the
userDestinationPrefix
.
By default actual destinations have a leading slash, e.g.
/queue/position-updates
which makes sense with brokers that
support destinations with slash as separator. When a PathMatcher
is provided that supports an alternative separator, then resulting
destinations won't have a leading slash, e.g. jms.queue.position-updates
.
pathMatcher
- the PathMatcher used to work with destinationspublic UserDestinationResult resolveDestination(Message<?> message)
UserDestinationResolver
resolveDestination
in interface UserDestinationResolver
message
- the message to try to resolvenull
if the source message does not contain a user destination.private DefaultUserDestinationResolver.ParseResult parse(Message<?> message)
protected boolean checkDestination(java.lang.String destination, java.lang.String requiredPrefix)
protected java.lang.String getTargetDestination(java.lang.String sourceDestination, java.lang.String actualDestination, java.lang.String sessionId, java.lang.String user)
sourceDestination
- the source destination from the input message.actualDestination
- a subset of the destination without any user prefix.sessionId
- the id of an active user session, never null
.user
- the target user, possibly null
, e.g if not authenticated.null
if nonepublic java.lang.String toString()
toString
in class java.lang.Object