@Test void testEnvironmentAccessCheckerChecksRightRightChecks() { EnvironmentAccessChecker underTest = environmentAccessCheckerFactory.create(ENV_CRN); ArgumentCaptor<List<AuthorizationProto.RightCheck>> argumentCaptor = ArgumentCaptor.forClass((Class) List.class); when(grpcUmsClient.hasRights( anyString(), eq(MEMBER_CRN), anyList(), any(Optional.class))).thenReturn(List.of(true, true)); underTest.hasAccess(MEMBER_CRN, Optional.empty()); verify(grpcUmsClient).hasRights(eq(INTERNAL_ACTOR_CRN), eq(MEMBER_CRN), argumentCaptor.capture(), any()); List<AuthorizationProto.RightCheck> capturedRightChecks = argumentCaptor.getValue(); assertEquals(2, capturedRightChecks.size()); AuthorizationProto.RightCheck hasAccess = capturedRightChecks.get(0); Assertions.assertEquals(UserSyncConstants.ACCESS_ENVIRONMENT, hasAccess.getRight()); assertEquals(ENV_CRN, hasAccess.getResource()); AuthorizationProto.RightCheck isAdmin = capturedRightChecks.get(1); assertEquals(UserSyncConstants.ADMIN_FREEIPA, isAdmin.getRight()); }
public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } }
EnvironmentAccessChecker { public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } } }
EnvironmentAccessChecker { public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } } EnvironmentAccessChecker(GrpcUmsClient grpcUmsClient, String environmentCrn, List<RightCheck> rightChecks); }
EnvironmentAccessChecker { public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } } EnvironmentAccessChecker(GrpcUmsClient grpcUmsClient, String environmentCrn, List<RightCheck> rightChecks); EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId); }
EnvironmentAccessChecker { public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) { requireNonNull(memberCrn, "memberCrn is null"); requireNonNull(requestId, "requestId is null"); try { List<Boolean> hasRights = grpcUmsClient.hasRights(INTERNAL_ACTOR_CRN, memberCrn, rightChecks, requestId); return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1)); } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage()); return new EnvironmentAccessRights(false, false); } else { throw e; } } } EnvironmentAccessChecker(GrpcUmsClient grpcUmsClient, String environmentCrn, List<RightCheck> rightChecks); EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId);  }