use of com.sequenceiq.authorization.info.model.CheckRightV4Request in project cloudbreak by hortonworks.
the class UtilAuthorizationServiceTest method testCheckRight.
@Test
public void testCheckRight() {
when(grpcUmsClient.hasRights(anyString(), any(), any(), any())).thenReturn(Lists.newArrayList(Boolean.TRUE, Boolean.FALSE));
CheckRightV4Request rightReq = new CheckRightV4Request();
rightReq.setRights(Lists.newArrayList(RightV4.ENV_CREATE, RightV4.DISTROX_READ));
CheckRightV4Response rightResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRights(rightReq));
rightResult.getResponses().forEach(checkRightV4SingleResponse -> {
if (checkRightV4SingleResponse.getRight().equals(RightV4.ENV_CREATE)) {
assertTrue(checkRightV4SingleResponse.getResult());
}
if (checkRightV4SingleResponse.getRight().equals(RightV4.DISTROX_READ)) {
assertFalse(checkRightV4SingleResponse.getResult());
}
});
verify(grpcUmsClient, times(1)).hasRights(anyString(), any(), any(), any());
}
use of com.sequenceiq.authorization.info.model.CheckRightV4Request in project cloudbreak by hortonworks.
the class CheckRightAction method action.
@Override
public CheckRightTestDto action(TestContext testContext, CheckRightTestDto testDto, CloudbreakClient cloudbreakClient) throws Exception {
CheckRightV4Request checkRightV4Request = new CheckRightV4Request();
checkRightV4Request.setRights(testDto.getRightsToCheck());
testDto.setResponse(cloudbreakClient.getDefaultClient().authorizationUtilEndpoint().checkRightInAccount(checkRightV4Request));
Log.whenJson(LOGGER, "check rights in account response:\n", testDto.getResponse());
return testDto;
}
use of com.sequenceiq.authorization.info.model.CheckRightV4Request in project cloudbreak by hortonworks.
the class UtilAuthorizationService method checkRights.
public CheckRightV4Response checkRights(CheckRightV4Request rightReq) {
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
List<AuthorizationProto.RightCheck> rightChecks = rightReq.getRights().stream().map(rightV4 -> createRightCheckObject(umsRightProvider.getRight(rightV4.getAction()), null)).collect(Collectors.toList());
List<Boolean> results = grpcUmsClient.hasRights(userCrn, rightChecks, MDCUtils.getRequestId(), regionAwareInternalCrnGeneratorFactory);
return new CheckRightV4Response(rightReq.getRights().stream().map(rightV4 -> new CheckRightV4SingleResponse(rightV4, results.get(rightReq.getRights().indexOf(rightV4)))).collect(Collectors.toList()));
}
Aggregations