1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
67
67
* @param userRegistry the registry, never {@code null}
68
68
*/
69
69
public DefaultUserDestinationResolver (SimpUserRegistry userRegistry ) {
70
- Assert .notNull (userRegistry , "'userRegistry' must not be null" );
70
+ Assert .notNull (userRegistry , "SimpUserRegistry must not be null" );
71
71
this .userRegistry = userRegistry ;
72
72
}
73
73
@@ -86,8 +86,8 @@ public SimpUserRegistry getSimpUserRegistry() {
86
86
* @param prefix the prefix to use
87
87
*/
88
88
public void setUserDestinationPrefix (String prefix ) {
89
- Assert .hasText (prefix , "prefix must not be empty" );
90
- this .prefix = prefix .endsWith ("/" ) ? prefix : prefix + "/" ;
89
+ Assert .hasText (prefix , "Prefix must not be empty" );
90
+ this .prefix = ( prefix .endsWith ("/" ) ? prefix : prefix + "/" ) ;
91
91
}
92
92
93
93
/**
@@ -101,11 +101,11 @@ public String getDestinationPrefix() {
101
101
* Use this property to indicate whether the leading slash from translated
102
102
* user destinations should be removed or not. This depends on the
103
103
* destination prefixes the message broker is configured with.
104
- * <p>By default this is set to {@code false}, i.e. "do not change the
105
- * target destination", although
104
+ * <p>By default this is set to {@code false}, i.e.
105
+ * "do not change the target destination", although
106
106
* {@link org.springframework.messaging.simp.config.AbstractMessageBrokerConfiguration
107
- * AbstractMessageBrokerConfiguration} may change that to {@code true} if
108
- * the configured destinations do not have a leading slash.
107
+ * AbstractMessageBrokerConfiguration} may change that to {@code true}
108
+ * if the configured destinations do not have a leading slash.
109
109
* @param remove whether to remove the leading slash
110
110
* @since 4.3.14
111
111
*/
@@ -115,6 +115,7 @@ public void setRemoveLeadingSlash(boolean remove) {
115
115
116
116
/**
117
117
* Whether to remove the leading slash from target destinations.
118
+ * @since 4.3.14
118
119
*/
119
120
public boolean isRemoveLeadingSlash () {
120
121
return this .removeLeadingSlash ;
@@ -198,18 +199,18 @@ private ParseResult parseSubscriptionMessage(Message<?> message, String sourceDe
198
199
Principal principal = SimpMessageHeaderAccessor .getUser (headers );
199
200
String user = (principal != null ? principal .getName () : null );
200
201
Set <String > sessionIds = Collections .singleton (sessionId );
201
- return new ParseResult (sourceDestination , actualDestination , sourceDestination ,
202
- sessionIds , user );
202
+ return new ParseResult (sourceDestination , actualDestination , sourceDestination , sessionIds , user );
203
203
}
204
204
205
- private ParseResult parseMessage (MessageHeaders headers , String sourceDestination ) {
205
+ private ParseResult parseMessage (MessageHeaders headers , String sourceDest ) {
206
206
int prefixEnd = this .prefix .length ();
207
- int userEnd = sourceDestination .indexOf ('/' , prefixEnd );
207
+ int userEnd = sourceDest .indexOf ('/' , prefixEnd );
208
208
Assert .isTrue (userEnd > 0 , "Expected destination pattern \" /user/{userId}/**\" " );
209
- String actualDestination = sourceDestination .substring (userEnd );
210
- String subscribeDestination = this .prefix .substring (0 , prefixEnd - 1 ) + actualDestination ;
211
- String userName = sourceDestination .substring (prefixEnd , userEnd );
209
+ String actualDest = sourceDest .substring (userEnd );
210
+ String subscribeDest = this .prefix .substring (0 , prefixEnd - 1 ) + actualDest ;
211
+ String userName = sourceDest .substring (prefixEnd , userEnd );
212
212
userName = StringUtils .replace (userName , "%2F" , "/" );
213
+
213
214
String sessionId = SimpMessageHeaderAccessor .getSessionId (headers );
214
215
Set <String > sessionIds ;
215
216
if (userName .equals (sessionId )) {
@@ -219,11 +220,11 @@ private ParseResult parseMessage(MessageHeaders headers, String sourceDestinatio
219
220
else {
220
221
sessionIds = getSessionIdsByUser (userName , sessionId );
221
222
}
223
+
222
224
if (isRemoveLeadingSlash ()) {
223
- actualDestination = actualDestination .substring (1 );
225
+ actualDest = actualDest .substring (1 );
224
226
}
225
- return new ParseResult (sourceDestination , actualDestination , subscribeDestination ,
226
- sessionIds , userName );
227
+ return new ParseResult (sourceDest , actualDest , subscribeDest , sessionIds , userName );
227
228
}
228
229
229
230
private Set <String > getSessionIdsByUser (String userName , String sessionId ) {
@@ -288,7 +289,6 @@ private static class ParseResult {
288
289
289
290
private final String user ;
290
291
291
-
292
292
public ParseResult (String sourceDest , String actualDest , String subscribeDest ,
293
293
Set <String > sessionIds , String user ) {
294
294
@@ -299,7 +299,6 @@ public ParseResult(String sourceDest, String actualDest, String subscribeDest,
299
299
this .user = user ;
300
300
}
301
301
302
-
303
302
public String getSourceDestination () {
304
303
return this .sourceDestination ;
305
304
}
0 commit comments