Merge branch '2.7.x'

pull/29263/head
Stephane Nicoll 3 years ago
commit e87b4cfb5b

@ -143,6 +143,7 @@ dependencies {
optional("org.springframework.security:spring-security-data") {
exclude group: "javax.xml.bind", module: "jaxb-api"
}
optional("org.springframework.security:spring-security-messaging")
optional("org.springframework.security:spring-security-oauth2-client")
optional("org.springframework.security:spring-security-oauth2-jose")
optional("org.springframework.security:spring-security-oauth2-resource-server")

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,10 +18,12 @@ package org.springframework.boot.autoconfigure.security.rsocket;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.rsocket.RSocketMessageHandlerCustomizer;
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.rsocket.EnableRSocketSecurity;
import org.springframework.security.messaging.handler.invocation.reactive.AuthenticationPrincipalArgumentResolver;
import org.springframework.security.rsocket.core.SecuritySocketAcceptorInterceptor;
/**
@ -30,6 +32,7 @@ import org.springframework.security.rsocket.core.SecuritySocketAcceptorIntercept
*
* @author Madhura Bhave
* @author Brian Clozel
* @author Guirong Hu
* @since 2.2.0
*/
@Configuration(proxyBeanMethods = false)
@ -42,4 +45,16 @@ public class RSocketSecurityAutoConfiguration {
return (server) -> server.interceptors((registry) -> registry.forSocketAcceptor(interceptor));
}
@ConditionalOnClass(AuthenticationPrincipalArgumentResolver.class)
@Configuration(proxyBeanMethods = false)
static class RSocketSecurityMessageHandlerConfiguration {
@Bean
RSocketMessageHandlerCustomizer rSocketAuthenticationPrincipalMessageHandlerCustomizer() {
return (messageHandler) -> messageHandler.getArgumentResolverConfigurer()
.addCustomResolver(new AuthenticationPrincipalArgumentResolver());
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,7 +26,9 @@ import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDeta
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.security.config.annotation.rsocket.RSocketSecurity;
import org.springframework.security.messaging.handler.invocation.reactive.AuthenticationPrincipalArgumentResolver;
import org.springframework.security.rsocket.core.SecuritySocketAcceptorInterceptor;
import static org.assertj.core.api.Assertions.assertThat;
@ -69,4 +71,14 @@ class RSocketSecurityAutoConfigurationTests {
});
}
@Test
void autoConfigurationAddsCustomizerForAuthenticationPrincipalArgumentResolver() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(RSocketMessageHandler.class);
RSocketMessageHandler handler = context.getBean(RSocketMessageHandler.class);
assertThat(handler.getArgumentResolverConfigurer().getCustomResolvers()).isNotEmpty()
.anyMatch((customResolver) -> customResolver instanceof AuthenticationPrincipalArgumentResolver);
});
}
}

Loading…
Cancel
Save