Skip to content

Commit b19164b

Browse files
committed
Check secure sample works
1 parent 11895ff commit b19164b

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

samples/grpc-secure/src/main/java/org/springframework/grpc/sample/GrpcServerApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.grpc.server.GlobalServerInterceptor;
99
import org.springframework.grpc.server.security.GrpcSecurity;
10-
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
1110
import org.springframework.security.core.userdetails.User;
1211
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
1312

1413
import io.grpc.Metadata;
1514
import io.grpc.ServerInterceptor;
1615

1716
@SpringBootApplication
18-
@EnableGlobalAuthentication
1917
class GrpcServerApplication {
2018

2119
public static final Metadata.Key<String> USER_KEY = Metadata.Key.of("X-USER", Metadata.ASCII_STRING_MARSHALLER);
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
spring.application.name=grpc-server
22
logging.level.org.springframework.security=debug
3-
4-
debug=true

samples/grpc-secure/src/test/java/org/springframework/grpc/sample/GrpcServerApplicationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.concurrent.atomic.AtomicReference;
88

99
import org.awaitility.Awaitility;
10-
import org.junit.jupiter.api.Disabled;
1110
import org.junit.jupiter.api.Test;
1211
import org.springframework.beans.factory.annotation.Autowired;
1312
import org.springframework.beans.factory.annotation.Qualifier;
@@ -55,10 +54,9 @@ void contextLoads() {
5554
}
5655

5756
@Test
58-
@Disabled("Code is coming back PERMISSION_DENIED NOT UNAUTHENTICATED")
5957
void unauthenticated() {
6058
assertThatExceptionOfType(StatusRuntimeException.class)
61-
.isThrownBy(() -> basic.streamHello(HelloRequest.newBuilder().setName("Alien").build()).next())
59+
.isThrownBy(() -> stub.sayHello(HelloRequest.newBuilder().setName("Alien").build()))
6260
.extracting("status.code")
6361
.isEqualTo(Code.UNAUTHENTICATED);
6462
}

samples/grpc-tomcat-secure/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.5.5</version>
9+
<version>4.0.0-RC2</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>org.springframework.grpc</groupId>
@@ -59,7 +59,12 @@
5959
</dependency>
6060
<dependency>
6161
<groupId>org.springframework.grpc</groupId>
62-
<artifactId>spring-grpc-test</artifactId>
62+
<artifactId>spring-grpc-test-spring-boot-autoconfigure</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-starter-test</artifactId>
6368
<scope>test</scope>
6469
</dependency>
6570
</dependencies>

samples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<module>grpc-reactive</module>
2222
<module>grpc-secure</module>
2323
<module>grpc-server</module>
24-
<!-- <module>grpc-server-kotlin</module>-->
24+
<module>grpc-server-kotlin</module>
2525
<module>grpc-server-netty-shaded</module>
2626
<module>grpc-tomcat</module>
2727
<!-- <module>grpc-tomcat-secure</module>-->

spring-grpc-server-spring-boot-autoconfigure/src/main/java/org/springframework/boot/grpc/server/autoconfigure/security/GrpcSecurityAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.security.config.ObjectPostProcessor;
4444
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
4545
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
46+
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
4647
import org.springframework.security.web.SecurityFilterChain;
4748

4849
import io.grpc.internal.GrpcUtil;
@@ -78,6 +79,7 @@ GrpcExceptionHandler accessExceptionHandler() {
7879
@ConditionalOnBean(ObjectPostProcessor.class)
7980
@ConditionalOnGrpcNativeServer
8081
@Configuration(proxyBeanMethods = false)
82+
@EnableGlobalAuthentication
8183
static class GrpcNativeSecurityConfigurerConfiguration {
8284

8385
@Bean

0 commit comments

Comments
 (0)