use of com.sequenceiq.authorization.info.model.ResourceRightsV4 in project cloudbreak by hortonworks.
the class CheckResourceRightAction method action.
@Override
public CheckResourceRightTestDto action(TestContext testContext, CheckResourceRightTestDto testDto, CloudbreakClient cloudbreakClient) throws Exception {
CheckResourceRightsV4Request checkRightByCrnV4Request = new CheckResourceRightsV4Request();
checkRightByCrnV4Request.setResourceRights(testDto.getRightsToCheck().entrySet().stream().map(entry -> {
ResourceRightsV4 resourceRightsV4 = new ResourceRightsV4();
resourceRightsV4.setResourceCrn(entry.getKey());
resourceRightsV4.setRights(entry.getValue());
return resourceRightsV4;
}).collect(Collectors.toList()));
testDto.setResponse(cloudbreakClient.getDefaultClient().authorizationUtilEndpoint().checkRightByCrn(checkRightByCrnV4Request));
Log.whenJson(LOGGER, "checking right on resources response:\n", testDto.getResponse());
return testDto;
}
use of com.sequenceiq.authorization.info.model.ResourceRightsV4 in project cloudbreak by hortonworks.
the class UtilAuthorizationServiceTest method createResourceRightV4.
private ResourceRightsV4 createResourceRightV4(String crn, RightV4... rights) {
ResourceRightsV4 resourceRightsV4 = new ResourceRightsV4();
resourceRightsV4.setResourceCrn(crn);
resourceRightsV4.setRights(Lists.newArrayList(rights));
return resourceRightsV4;
}
use of com.sequenceiq.authorization.info.model.ResourceRightsV4 in project cloudbreak by hortonworks.
the class UtilAuthorizationServiceTest method testCheckResourceRightFallback.
@Test
public void testCheckResourceRightFallback() {
when(grpcUmsClient.hasRights(anyString(), any(), any(), any())).thenReturn(Lists.newLinkedList(Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE)));
CheckResourceRightsV4Request rightReq = new CheckResourceRightsV4Request();
List<ResourceRightsV4> resourceRights = new LinkedList<>();
resourceRights.add(createResourceRightV4("envCrn", RightV4.ENV_STOP, RightV4.ENV_START));
resourceRights.add(createResourceRightV4("dhCrn", RightV4.DH_START, RightV4.DH_STOP));
rightReq.setResourceRights(resourceRights);
CheckResourceRightsV4Response rightResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRightsOnResources(rightReq));
rightResult.getResponses().forEach(checkResourceRightV4SingleResponse -> checkResourceRightV4SingleResponse.getRights().forEach(checkRightV4SingleResponse -> {
if (checkRightV4SingleResponse.getRight().equals(RightV4.ENV_STOP) || checkRightV4SingleResponse.getRight().equals(RightV4.DH_STOP)) {
assertTrue(checkRightV4SingleResponse.getResult());
}
if (checkRightV4SingleResponse.getRight().equals(RightV4.DH_START) || checkRightV4SingleResponse.getRight().equals(RightV4.ENV_START)) {
assertFalse(checkRightV4SingleResponse.getResult());
}
}));
verify(grpcUmsClient, times(1)).hasRights(anyString(), any(), any(), any());
}
Aggregations