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".
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.
|
boolean |
isRemoveLeadingSlash()
Whether to remove the leading slash from target destinations.
|
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)
Deprecated.
as of 4.3.14 this property is no longer used and is replaced
by
setRemoveLeadingSlash(boolean) that indicates more explicitly
whether to keep the leading slash which may or may not be the case
regardless of how the PathMatcher is configured. |
void |
setRemoveLeadingSlash(boolean remove)
Use this property to indicate whether the leading slash from translated
user destinations should be removed or not.
|
void |
setUserDestinationPrefix(java.lang.String prefix)
The prefix used to identify user destinations.
|
java.lang.String |
toString() |
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 setRemoveLeadingSlash(boolean remove)
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.
remove
- whether to remove the leading slashpublic boolean isRemoveLeadingSlash()
@Deprecated public void setPathMatcher(@Nullable PathMatcher pathMatcher)
setRemoveLeadingSlash(boolean)
that indicates more explicitly
whether to keep the leading slash which may or may not be the case
regardless of how the PathMatcher
is configured.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 destinations@Nullable public 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.protected boolean checkDestination(java.lang.String destination, java.lang.String requiredPrefix)
@Nullable protected java.lang.String getTargetDestination(java.lang.String sourceDestination, java.lang.String actualDestination, java.lang.String sessionId, @Nullable 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