Skip to content

Commit 79e3121

Browse files
committed
ref #267
1 parent c11b0b5 commit 79e3121

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

grpc-spring-boot-starter-demo/src/main/java/org/lognet/springboot/grpc/demo/SecuredGreeterService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
@Secured("SCOPE_profile")
2121
public class SecuredGreeterService extends SecuredGreeterGrpc.SecuredGreeterImplBase{
2222

23+
@Override
24+
public void securedMethodsWithUnderScoRes(Empty request, StreamObserver<Empty> responseObserver) {
25+
responseObserver.onNext(Empty.newBuilder().build());
26+
responseObserver.onCompleted();
27+
}
28+
29+
@Override
30+
public void anotherSecuredMethodsWithUnderScoRes(Empty request, StreamObserver<Empty> responseObserver) {
31+
responseObserver.onNext(Empty.newBuilder().build());
32+
responseObserver.onCompleted();
33+
}
34+
2335
@Override
2436
public void sayAuthHello(Empty request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) {
2537
final Authentication auth = GrpcSecurity.AUTHENTICATION_CONTEXT_KEY.get();

grpc-spring-boot-starter-demo/src/main/proto/greeter.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ service SecuredGreeter {
1919
rpc SayAuthHello ( google.protobuf.Empty) returns ( HelloReply) {}
2020
rpc SayAuthHello2 ( google.protobuf.Empty) returns ( HelloReply) {}
2121

22+
rpc secured_methods_with_UnderScoRes(google.protobuf.Empty) returns (google.protobuf.Empty){}
23+
rpc AnotherSecured_methods_with_UnderScoRes(google.protobuf.Empty) returns (google.protobuf.Empty){}
24+
2225

2326
}
2427

grpc-spring-boot-starter-demo/src/test/java/org/lognet/springboot/grpc/auth/UserDetailsAuthTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import io.grpc.ClientInterceptors;
77
import io.grpc.Status;
88
import io.grpc.StatusRuntimeException;
9-
import io.grpc.examples.CalculatorGrpc;
10-
import io.grpc.examples.CalculatorOuterClass;
11-
import io.grpc.examples.GreeterGrpc;
12-
import io.grpc.examples.SecuredCalculatorGrpc;
9+
import io.grpc.examples.*;
1310
import io.grpc.stub.StreamObserver;
11+
import org.hamcrest.CoreMatchers;
1412
import org.hamcrest.Matchers;
1513
import org.junit.Test;
1614
import org.junit.runner.RunWith;
@@ -19,6 +17,7 @@
1917
import org.lognet.springboot.grpc.demo.DemoApp;
2018
import org.lognet.springboot.grpc.demo.DemoAppConfiguration;
2119
import org.lognet.springboot.grpc.demo.NotSpringBeanInterceptor;
20+
import org.lognet.springboot.grpc.demo.SecuredGreeterService;
2221
import org.lognet.springboot.grpc.security.AuthClientInterceptor;
2322
import org.lognet.springboot.grpc.security.AuthHeader;
2423
import org.lognet.springboot.grpc.security.GrpcSecurity;
@@ -77,6 +76,7 @@ public static UserDetails user() {
7776
.username("user1")
7877
.password(pwd)
7978
.roles("reader")
79+
.authorities("SCOPE_profile")
8080
.build();
8181
}
8282

@@ -127,6 +127,16 @@ public void shouldFailWithPermissionDenied() {
127127
assertThat(statusRuntimeException.getStatus().getCode(), Matchers.is(Status.Code.PERMISSION_DENIED));
128128
}
129129

130+
@Test
131+
public void methodNameWithUnderscore() {
132+
Empty response = SecuredGreeterGrpc.newBlockingStub(selectedChanel)
133+
.anotherSecuredMethodsWithUnderScoRes(Empty.newBuilder().build());
134+
assertThat(response, CoreMatchers.notNullValue(Empty.class));
135+
136+
response = SecuredGreeterGrpc.newBlockingStub(selectedChanel)
137+
.securedMethodsWithUnderScoRes(Empty.newBuilder().build());
138+
assertThat(response, CoreMatchers.notNullValue(Empty.class));
139+
}
130140

131141
@Test
132142
public void serviceLevelSecurityAuthenticationWithoutAuthorization() {

grpc-spring-boot-starter/src/main/java/org/lognet/springboot/grpc/GRpcServicesRegistry.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
import java.lang.annotation.Annotation;
1818
import java.lang.reflect.Method;
1919
import java.lang.reflect.Modifier;
20-
import java.util.Collection;
21-
import java.util.Collections;
22-
import java.util.HashMap;
23-
import java.util.Map;
24-
import java.util.Set;
20+
import java.util.*;
2521
import java.util.function.Function;
2622
import java.util.function.Supplier;
2723
import java.util.stream.Collectors;
@@ -127,7 +123,9 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
127123
final Map<MethodDescriptor<?, ?>, GrpcServiceMethod> map = new HashMap<>();
128124

129125
Function<String, ReflectionUtils.MethodFilter> filterFactory = name ->
130-
method -> method.getName().equalsIgnoreCase(name) ;
126+
method ->
127+
method.getName().equalsIgnoreCase(name.replaceAll("_",""));
128+
131129

132130
for (BindableService service : getBeanNameToServiceBeanMap().values()) {
133131
final ServerServiceDefinition serviceDefinition = service.bindService();

0 commit comments

Comments
 (0)