Skip to content

Commit d61d0d4

Browse files
committed
Merge branch '5.3.x' into main
2 parents b56815f + 34cb5df commit d61d0d4

File tree

8 files changed

+67
-28
lines changed

8 files changed

+67
-28
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,10 +84,11 @@ public List<HandlerMethodArgumentResolver> getResolvers() {
8484
}
8585

8686
/**
87-
* Clear the list of configured resolvers.
87+
* Clear the list of configured resolvers and the resolver cache.
8888
*/
8989
public void clear() {
9090
this.argumentResolvers.clear();
91+
this.argumentResolverCache.clear();
9192
}
9293

9394

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -86,10 +86,11 @@ public List<HandlerMethodArgumentResolver> getResolvers() {
8686
}
8787

8888
/**
89-
* Clear the list of configured resolvers.
89+
* Clear the list of configured resolvers and the resolver cache.
9090
*/
9191
public void clear() {
9292
this.argumentResolvers.clear();
93+
this.argumentResolverCache.clear();
9394
}
9495

9596

spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -211,9 +211,18 @@ public SslInfo getSslInfo() {
211211
*/
212212
String getLogPrefix() {
213213
if (this.logPrefix == null) {
214-
this.logPrefix = "[" + getId() + "] ";
214+
this.logPrefix = "[" + initLogPrefix() + "] ";
215215
}
216216
return this.logPrefix;
217217
}
218218

219+
/**
220+
* Subclasses can override this to provide the prefix to use for log messages.
221+
* <p>By default, this is {@link #getId()}.
222+
* @since 5.3.15
223+
*/
224+
protected String initLogPrefix() {
225+
return getId();
226+
}
227+
219228
}

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public ReactorServerHttpRequest(HttpServerRequest request, NettyDataBufferFactor
7878

7979
private static URI initUri(HttpServerRequest request) throws URISyntaxException {
8080
Assert.notNull(request, "HttpServerRequest must not be null");
81-
return new URI(resolveBaseUrl(request).toString() + resolveRequestUri(request));
81+
return new URI(resolveBaseUrl(request) + resolveRequestUri(request));
8282
}
8383

8484
private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
@@ -203,14 +203,26 @@ public <T> T getNativeRequest() {
203203
@Override
204204
@Nullable
205205
protected String initId() {
206+
if (this.request instanceof Connection) {
207+
return ((Connection) this.request).channel().id().asShortText() +
208+
"-" + logPrefixIndex.incrementAndGet();
209+
}
210+
return null;
211+
}
212+
213+
@Override
214+
protected String initLogPrefix() {
206215
if (reactorNettyRequestChannelOperationsIdPresent) {
207-
return (ChannelOperationsIdHelper.getId(this.request));
216+
String id = (ChannelOperationsIdHelper.getId(this.request));
217+
if (id != null) {
218+
return id;
219+
}
208220
}
209221
if (this.request instanceof Connection) {
210222
return ((Connection) this.request).channel().id().asShortText() +
211223
"-" + logPrefixIndex.incrementAndGet();
212224
}
213-
return null;
225+
return getId();
214226
}
215227

216228

spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,6 +65,16 @@ public HttpStatus getStatusCode() {
6565
return getDelegate().getStatusCode();
6666
}
6767

68+
@Override
69+
public boolean setRawStatusCode(@Nullable Integer value) {
70+
return getDelegate().setRawStatusCode(value);
71+
}
72+
73+
@Override
74+
public Integer getRawStatusCode() {
75+
return getDelegate().getRawStatusCode();
76+
}
77+
6878
@Override
6979
public HttpHeaders getHeaders() {
7080
return getDelegate().getHeaders();

spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,11 +85,12 @@ public List<HandlerMethodArgumentResolver> getResolvers() {
8585
}
8686

8787
/**
88-
* Clear the list of configured resolvers.
88+
* Clear the list of configured resolvers and the resolver cache.
8989
* @since 4.3
9090
*/
9191
public void clear() {
9292
this.argumentResolvers.clear();
93+
this.argumentResolverCache.clear();
9394
}
9495

9596

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,10 +83,11 @@ public List<HandlerMethodArgumentResolver> getResolvers() {
8383
}
8484

8585
/**
86-
* Clear the list of configured resolvers.
86+
* Clear the list of configured resolvers and the resolver cache.
8787
*/
8888
public void clear() {
8989
this.argumentResolvers.clear();
90+
this.argumentResolverCache.clear();
9091
}
9192

9293

src/docs/asciidoc/web/websocket.adoc

+17-13
Original file line numberDiff line numberDiff line change
@@ -1724,19 +1724,11 @@ HTTP session (which is then associated with WebSocket or SockJS sessions created
17241724
for that user) and results in a user header being stamped on every `Message` flowing
17251725
through the application.
17261726

1727-
Note that the STOMP protocol does have `login` and `passcode` headers
1728-
on the `CONNECT` frame. Those were originally designed for and are still needed,
1729-
for example, for STOMP over TCP. However, for STOMP over WebSocket, by default,
1730-
Spring ignores authorization headers at the STOMP protocol level, assumes that
1731-
the user is already authenticated at the HTTP transport level, and expects that
1732-
the WebSocket or SockJS session contain the authenticated user.
1733-
1734-
NOTE: Spring Security provides
1735-
https://docs.spring.io/spring-security/reference/servlet/integrations/websocket.html#websocket-authorization[WebSocket sub-protocol authorization]
1736-
that uses a `ChannelInterceptor` to authorize messages based on the user header in them.
1737-
Also, Spring Session provides
1738-
https://docs.spring.io/spring-session/reference/web-socket.html[WebSocket integration]
1739-
that ensures the user's HTTP session does not expire while the WebSocket session is still active.
1727+
The STOMP protocol does have `login` and `passcode` headers on the `CONNECT` frame.
1728+
Those were originally designed for and are needed for STOMP over TCP. However, for STOMP
1729+
over WebSocket, by default, Spring ignores authentication headers at the STOMP protocol
1730+
level, and assumes that the user is already authenticated at the HTTP transport level.
1731+
The expectation is that the WebSocket or SockJS session contain the authenticated user.
17401732

17411733

17421734

@@ -1814,6 +1806,18 @@ its own implementation of `WebSocketMessageBrokerConfigurer` that is marked with
18141806

18151807

18161808

1809+
[[websocket-stomp-authorization]]
1810+
=== Authorization
1811+
1812+
Spring Security provides
1813+
https://docs.spring.io/spring-security/reference/servlet/integrations/websocket.html#websocket-authorization[WebSocket sub-protocol authorization]
1814+
that uses a `ChannelInterceptor` to authorize messages based on the user header in them.
1815+
Also, Spring Session provides
1816+
https://docs.spring.io/spring-session/reference/web-socket.html[WebSocket integration]
1817+
that ensures the user's HTTP session does not expire while the WebSocket session is still active.
1818+
1819+
1820+
18171821
[[websocket-stomp-user-destination]]
18181822
=== User Destinations
18191823

0 commit comments

Comments
 (0)