![JAR search and dependency download from the Maven repository](/logo.png)
org.lognet.springboot.grpc.security.GrpcSecurityMetadataSource Maven / Gradle / Ivy
package org.lognet.springboot.grpc.security;
import io.grpc.MethodDescriptor;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.lognet.springboot.grpc.GRpcServicesRegistry;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.method.MethodSecurityMetadataSource;
public class GrpcSecurityMetadataSource implements MethodSecurityMetadataSource {
private Map, List> methodDescriptorAttributes;
private GRpcServicesRegistry registry;
public GrpcSecurityMetadataSource(
GRpcServicesRegistry registry,
Map, List> methodDescriptorAttributes) {
this.methodDescriptorAttributes = methodDescriptorAttributes;
this.registry = registry;
}
@Override
public Collection getAttributes(Object object) throws IllegalArgumentException {
final MethodDescriptor methodDescriptor =
SecurityInterceptor.GrpcMethodInvocation.class.cast(object).getCall().getMethodDescriptor();
return methodDescriptorAttributes.get(methodDescriptor);
}
@Override
public Collection getAllConfigAttributes() {
return methodDescriptorAttributes.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
@Override
public boolean supports(Class> clazz) {
return SecurityInterceptor.GrpcMethodInvocation.class.isAssignableFrom(clazz);
}
@Override
public Collection getAttributes(Method method, Class> targetClass) {
final MethodDescriptor, ?> methodDescriptor = registry.getMethodDescriptor(method);
return methodDescriptorAttributes.get(methodDescriptor);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy