use of com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse 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()));
}
use of com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse in project cloudbreak by hortonworks.
the class UtilAuthorizationService method generateResponse.
private CheckResourceRightsV4Response generateResponse(Multimap<ImmutablePair<String, RightV4>, AuthorizationProto.RightCheck> resourceRightsChecks, Map<AuthorizationProto.RightCheck, Boolean> rightCheckResultMap) {
CheckResourceRightsV4Response response = new CheckResourceRightsV4Response(Lists.newArrayList());
Map<ImmutablePair<String, RightV4>, Boolean> rightCheckResults = new HashMap<>();
for (ImmutablePair<String, RightV4> resourceRight : resourceRightsChecks.keys()) {
Collection<AuthorizationProto.RightCheck> rightChecks = resourceRightsChecks.get(resourceRight);
Boolean hasRight = hasRight(rightCheckResultMap, rightChecks);
rightCheckResults.put(resourceRight, hasRight);
}
rightCheckResults.forEach((rightCheck, result) -> {
if (getResourceRightSingleResponse(response, rightCheck.getLeft()).isEmpty()) {
response.getResponses().add(new CheckResourceRightV4SingleResponse(rightCheck.getLeft(), Lists.newArrayList()));
}
CheckRightV4SingleResponse singleResponse = new CheckRightV4SingleResponse(rightCheck.getRight(), result);
getResourceRightSingleResponse(response, rightCheck.getLeft()).get().getRights().add(singleResponse);
});
return response;
}
Aggregations