Skip to content

Commit 097f3b9

Browse files
Move @secured authenticated logic into processSecuredAnnotation()
1 parent 6d1b4b7 commit 097f3b9

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ public GrpcServiceAuthorizationConfigurer.Registry hasAnyRole(String... roles) {
7474
}
7575

7676
public GrpcServiceAuthorizationConfigurer.Registry hasAnyAuthority(String... authorities) {
77-
if (authorities.length == 0) {
78-
// Authenticate request
79-
GrpcServiceAuthorizationConfigurer.this.registry.map(methods);
80-
} else {
81-
for (String auth : authorities) {
82-
GrpcServiceAuthorizationConfigurer.this.registry.map(auth, methods);
83-
}
77+
for (String auth : authorities) {
78+
GrpcServiceAuthorizationConfigurer.this.registry.map(auth, methods);
8479
}
8580
return GrpcServiceAuthorizationConfigurer.this.registry;
8681
}
@@ -145,7 +140,13 @@ private void processSecuredAnnotation() {
145140
.filter(m -> m.getName().equalsIgnoreCase(methodDefinition.getMethodDescriptor().getBareMethodName()))
146141
.findFirst()
147142
.flatMap(m -> Optional.ofNullable(AnnotationUtils.findAnnotation(m, Secured.class)))
148-
.ifPresent(secured -> new AuthorizedMethod(methodDefinition.getMethodDescriptor()).hasAnyAuthority(secured.value()));
143+
.ifPresent(secured -> {
144+
if (secured.value().length == 0) {
145+
new AuthorizedMethod(methodDefinition.getMethodDescriptor()).authenticated();
146+
} else {
147+
new AuthorizedMethod(methodDefinition.getMethodDescriptor()).hasAnyAuthority(secured.value());
148+
}
149+
});
149150

150151
}
151152
}

0 commit comments

Comments
 (0)