use of com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response in project cloudbreak by hortonworks.
the class UtilAuthorizationServiceTest method testHasRightsOnResources.
@Test
public void testHasRightsOnResources() {
CheckRightOnResourcesV4Request request = new CheckRightOnResourcesV4Request();
request.setRight(RightV4.DH_DESCRIBE);
request.setResourceCrns(List.of(DATAHUB_CRN));
when(entitlementService.listFilteringEnabled(eq("1234"))).thenReturn(true);
doAnswer(invocation -> ((List<String>) invocation.getArgument(1)).stream().map(crn -> new Resource(crn, Optional.empty())).collect(Collectors.toList())).when(authorizationResourceProvider).findResources(anyString(), anyList());
doAnswer(invocation -> ((Function<Predicate<String>, List<CheckResourceRightV4Response>>) invocation.getArgument(3)).apply(crn -> true)).when(resourceFilteringService).filter(any(), any(), anyList(), any());
CheckRightOnResourcesV4Response response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRightOnResources(request));
assertEquals(RightV4.DH_DESCRIBE, response.getRight());
assertEquals(1, response.getResponses().size());
CheckResourceRightV4Response checkResourceRightV4Response = response.getResponses().get(0);
assertTrue(checkResourceRightV4Response.isResult());
assertEquals(DATAHUB_CRN, checkResourceRightV4Response.getResourceCrn());
}
use of com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response in project cloudbreak by hortonworks.
the class UtilAuthorizationService method checkRightOnResources.
private CheckRightOnResourcesV4Response checkRightOnResources(Crn userCrn, CheckRightOnResourcesV4Request request, ResourceListProvider authorizationResourceProvider) {
List<Resource> resources = authorizationResourceProvider.findResources(userCrn.getAccountId(), request.getResourceCrns());
List<CheckResourceRightV4Response> responses = resourceFilteringService.filter(userCrn, request.getRight().getAction(), resources, hasRightPredicate -> request.getResourceCrns().stream().map(resourceCrn -> {
CheckResourceRightV4Response checkResourceRightV4Response = new CheckResourceRightV4Response();
checkResourceRightV4Response.setResourceCrn(resourceCrn);
checkResourceRightV4Response.setResult(hasRightPredicate.test(resourceCrn));
return checkResourceRightV4Response;
}).collect(Collectors.toList()));
CheckRightOnResourcesV4Response response = new CheckRightOnResourcesV4Response();
response.setRight(request.getRight());
response.setResponses(responses);
return response;
}
Aggregations