Merge branch '6.1.x'

This commit is contained in:
Sébastien Deleuze
2024-03-25 11:04:49 +01:00
59 changed files with 106 additions and 23 deletions

View File

@@ -257,6 +257,7 @@ public class WebSocketHttpHeaders extends HttpHeaders {
}
@Override
@Nullable
public List<String> get(Object key) {
return this.headers.get(key);
}

View File

@@ -114,6 +114,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
}
@Override
@Nullable
public String getAcceptedProtocol() {
checkNativeSessionInitialized();
return this.acceptedProtocol;
@@ -126,6 +127,7 @@ public class JettyWebSocketSession extends AbstractWebSocketSession<Session> {
}
@Override
@Nullable
public Principal getPrincipal() {
return this.user;
}

View File

@@ -129,6 +129,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
}
@Override
@Nullable
public String getAcceptedProtocol() {
checkNativeSessionInitialized();
return this.acceptedProtocol;
@@ -141,6 +142,7 @@ public class StandardWebSocketSession extends AbstractWebSocketSession<Session>
}
@Override
@Nullable
public Principal getPrincipal() {
return this.user;
}

View File

@@ -21,6 +21,7 @@ import java.util.List;
import jakarta.websocket.Extension;
import org.springframework.lang.Nullable;
import org.springframework.web.socket.WebSocketExtension;
/**
@@ -46,6 +47,7 @@ public class WebSocketToStandardExtensionAdapter implements Extension {
return paramName;
}
@Override
@Nullable
public String getValue() {
return extension.getParameters().get(paramName);
}

View File

@@ -133,6 +133,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) {
Object source = context.extractSource(element);
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);

View File

@@ -96,21 +96,25 @@ public class WebSocketSessionDecorator implements WebSocketSession {
}
@Override
@Nullable
public Principal getPrincipal() {
return this.delegate.getPrincipal();
}
@Override
@Nullable
public InetSocketAddress getLocalAddress() {
return this.delegate.getLocalAddress();
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
return this.delegate.getRemoteAddress();
}
@Override
@Nullable
public String getAcceptedProtocol() {
return this.delegate.getAcceptedProtocol();
}

View File

@@ -110,6 +110,7 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
}
@Override
@Nullable
public Principal getPrincipal() {
return this.request.getUser();
}

View File

@@ -207,6 +207,7 @@ public class RestTemplateXhrTransport extends AbstractXhrTransport {
}
@Override
@Nullable
public Object extractData(ClientHttpResponse response) throws IOException {
HttpStatusCode httpStatus = response.getStatusCode();
if (httpStatus != HttpStatus.OK) {

View File

@@ -74,18 +74,21 @@ public class WebSocketClientSockJsSession extends AbstractClientSockJsSession im
}
@Override
@Nullable
public InetSocketAddress getLocalAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getLocalAddress();
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getRemoteAddress();
}
@Override
@Nullable
public String getAcceptedProtocol() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getAcceptedProtocol();

View File

@@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
@@ -96,17 +97,20 @@ public class XhrClientSockJsSession extends AbstractClientSockJsSession {
}
@Override
@Nullable
public InetSocketAddress getLocalAddress() {
return null;
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
URI uri = getUri();
return (uri != null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : null);
}
@Override
@Nullable
public String getAcceptedProtocol() {
return null;
}

View File

@@ -341,6 +341,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
* @since 4.1.2
*/
@SuppressWarnings("ConstantConditions")
@Nullable
public Collection<String> getAllowedOrigins() {
return this.corsConfiguration.getAllowedOrigins();
}
@@ -363,6 +364,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
* @since 5.3.2
*/
@SuppressWarnings("ConstantConditions")
@Nullable
public Collection<String> getAllowedOriginPatterns() {
return this.corsConfiguration.getAllowedOriginPatterns();
}
@@ -415,8 +417,8 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
else if (sockJsPath.matches("/iframe[0-9-.a-z_]*.html")) {
if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") ||
!getAllowedOriginPatterns().isEmpty()) {
if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") ||
!CollectionUtils.isEmpty(getAllowedOriginPatterns())) {
if (requestInfo != null) {
logger.debug("Iframe support is disabled when an origin check is required. " +
"Ignoring transport request: " + requestInfo);
@@ -424,7 +426,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
response.setStatusCode(HttpStatus.NOT_FOUND);
return;
}
if (getAllowedOrigins().isEmpty()) {
if (CollectionUtils.isEmpty(getAllowedOrigins())) {
response.getHeaders().add(XFRAME_OPTIONS_HEADER, "SAMEORIGIN");
}
if (requestInfo != null) {

View File

@@ -346,8 +346,8 @@ public class TransportHandlingSockJsService extends AbstractSockJsService implem
return false;
}
if (!getAllowedOrigins().isEmpty() && !getAllowedOrigins().contains("*") ||
!getAllowedOriginPatterns().isEmpty()) {
if (!CollectionUtils.isEmpty(getAllowedOrigins()) && !getAllowedOrigins().contains("*") ||
!CollectionUtils.isEmpty(getAllowedOriginPatterns())) {
TransportType transportType = TransportType.fromValue(transport);
if (transportType == null || !transportType.supportsOrigin()) {
if (logger.isWarnEnabled()) {

View File

@@ -83,24 +83,28 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen
}
@Override
@Nullable
public Principal getPrincipal() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getPrincipal();
}
@Override
@Nullable
public InetSocketAddress getLocalAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getLocalAddress();
}
@Override
@Nullable
public InetSocketAddress getRemoteAddress() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getRemoteAddress();
}
@Override
@Nullable
public String getAcceptedProtocol() {
Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized");
return this.webSocketSession.getAcceptedProtocol();