MCPcopy Create free account
hub / github.com/grpc/grpc-java / parsePrincipal

Method parsePrincipal

xds/src/main/java/io/grpc/xds/RbacFilter.java:263–301  ·  view source on GitHub ↗
(Principal principal)

Source from the content-addressed store, hash-verified

261 }
262
263 private static Matcher parsePrincipal(Principal principal) {
264 switch (principal.getIdentifierCase()) {
265 case OR_IDS:
266 return parsePrincipalList(principal.getOrIds().getIdsList());
267 case AND_IDS:
268 List<Matcher> nextMatchers = new ArrayList<>();
269 for (Principal next : principal.getAndIds().getIdsList()) {
270 nextMatchers.add(parsePrincipal(next));
271 }
272 return AndMatcher.create(nextMatchers);
273 case ANY:
274 return AlwaysTrueMatcher.INSTANCE;
275 case AUTHENTICATED:
276 return parseAuthenticatedMatcher(principal.getAuthenticated());
277 case DIRECT_REMOTE_IP:
278 return createSourceIpMatcher(principal.getDirectRemoteIp());
279 case REMOTE_IP:
280 return createSourceIpMatcher(principal.getRemoteIp());
281 case SOURCE_IP: {
282 // gRFC A41 has identical handling of source_ip as remote_ip and direct_remote_ip and
283 // pre-dates the deprecation.
284 @SuppressWarnings("deprecation")
285 CidrRange sourceIp = principal.getSourceIp();
286 return createSourceIpMatcher(sourceIp);
287 }
288 case HEADER:
289 return parseHeaderMatcher(principal.getHeader());
290 case NOT_ID:
291 return InvertMatcher.create(parsePrincipal(principal.getNotId()));
292 case URL_PATH:
293 return parsePathMatcher(principal.getUrlPath());
294 case METADATA: // hard coded, never match.
295 return InvertMatcher.create(AlwaysTrueMatcher.INSTANCE);
296 case IDENTIFIER_NOT_SET:
297 default:
298 throw new IllegalArgumentException(
299 "Unknown principal identifier case: " + principal.getIdentifierCase());
300 }
301 }
302
303 private static PathMatcher parsePathMatcher(
304 io.envoyproxy.envoy.type.matcher.v3.PathMatcher proto) {

Callers 1

parsePrincipalListMethod · 0.95

Calls 10

parsePrincipalListMethod · 0.95
createMethod · 0.95
createSourceIpMatcherMethod · 0.95
parseHeaderMatcherMethod · 0.95
createMethod · 0.95
parsePathMatcherMethod · 0.95
getSourceIpMethod · 0.80
getHeaderMethod · 0.80
addMethod · 0.65

Tested by

no test coverage detected