Skip to content

Commit

Permalink
ref #296
Browse files Browse the repository at this point in the history
  • Loading branch information
afurer committed Jun 9, 2022
1 parent dee03c0 commit b0f9401
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -93,43 +94,50 @@ public class Registry {
this.servicesRegistry = servicesRegistry;
}

public AuthorizedMethod anyMethod() {
ServiceDescriptor[] allServices = servicesRegistry.getBeanNameToServiceBeanMap()
.values()
.stream()
.map(BindableService::bindService)
.map(ServerServiceDefinition::getServiceDescriptor)
.toArray(ServiceDescriptor[]::new);
return new AuthorizedMethod(allServices);

}

public GrpcSecurity withoutSecuredAnnotation() {
return withSecuredAnnotation(false);
}

public AuthorizedMethod anyMethod() {
return anyMethodExcluding(s->false);
}

public AuthorizedMethod anyMethodExcluding(MethodDescriptor<?, ?>... methodDescriptor) {
List<MethodDescriptor> excludedMethods = Arrays.asList(methodDescriptor);
MethodDescriptor[] allMethods = servicesRegistry.getBeanNameToServiceBeanMap()
List<MethodDescriptor<?,?>> excludedMethods = Arrays.asList(methodDescriptor);
return anyMethodExcluding(excludedMethods::contains);

}


public AuthorizedMethod anyMethodExcluding(Predicate<MethodDescriptor<?, ?>> excludePredicate) {
MethodDescriptor<?,?>[] allMethods = servicesRegistry.getBeanNameToServiceBeanMap()
.values()
.stream()
.map(BindableService::bindService)
.map(ServerServiceDefinition::getServiceDescriptor)
.map(ServiceDescriptor::getMethods)
.flatMap(Collection::stream)
.filter(method -> !excludedMethods.contains(method))
.filter(excludePredicate.negate())
.toArray(MethodDescriptor[]::new);
return new AuthorizedMethod(allMethods);
}


public AuthorizedMethod anyService() {
return anyServiceExcluding(s-> false);
}
public AuthorizedMethod anyServiceExcluding(ServiceDescriptor... serviceDescriptor) {
List<ServiceDescriptor> excludedServices = Arrays.asList(serviceDescriptor);
return anyServiceExcluding(excludedServices::contains);
}
public AuthorizedMethod anyServiceExcluding(Predicate<ServiceDescriptor> excludePredicate) {

ServiceDescriptor[] allServices = servicesRegistry.getBeanNameToServiceBeanMap()
.values()
.stream()
.map(BindableService::bindService)
.map(ServerServiceDefinition::getServiceDescriptor)
.filter(service -> !excludedServices.contains(service))
.filter(excludePredicate.negate())
.toArray(ServiceDescriptor[]::new);
return new AuthorizedMethod(allServices);
}
Expand Down

0 comments on commit b0f9401

Please sign in to comment.