Search in sources :

Example 1 with CrnsByCategory

use of com.sequenceiq.authorization.service.defaults.CrnsByCategory in project cloudbreak by hortonworks.

the class DefaultImageCheckerTest method shouldReturnDefaultCrnsWithLegacy.

@Test
public void shouldReturnDefaultCrnsWithLegacy() {
    CrnsByCategory result = underTest.getDefaultResourceCrns(List.of(DEFAULT_CRN, OTHER_CRN));
    assertEquals(List.of(DEFAULT_CRN), result.getDefaultResourceCrns());
    assertEquals(List.of(OTHER_CRN), result.getNotDefaultResourceCrns());
}
Also used : CrnsByCategory(com.sequenceiq.authorization.service.defaults.CrnsByCategory) Test(org.junit.Test)

Example 2 with CrnsByCategory

use of com.sequenceiq.authorization.service.defaults.CrnsByCategory in project cloudbreak by hortonworks.

the class CommonPermissionCheckingUtils method getPermissionsForUserOnResources.

public Map<String, Boolean> getPermissionsForUserOnResources(AuthorizationResourceAction action, String userCrn, List<String> resourceCrns) {
    DefaultResourceChecker defaultResourceChecker = defaultResourceCheckerMap.get(umsRightProvider.getResourceType(action));
    if (defaultResourceChecker == null) {
        return umsResourceAuthorizationService.getRightOfUserOnResources(userCrn, action, resourceCrns);
    } else {
        CrnsByCategory crnsByCategory = defaultResourceChecker.getDefaultResourceCrns(resourceCrns);
        Map<String, Boolean> result = new HashMap<>();
        if (!crnsByCategory.getDefaultResourceCrns().isEmpty()) {
            result.putAll(crnsByCategory.getDefaultResourceCrns().stream().collect(toMap(Function.identity(), s -> defaultResourceChecker.isAllowedAction(action))));
        }
        if (!crnsByCategory.getNotDefaultResourceCrns().isEmpty()) {
            result.putAll(umsResourceAuthorizationService.getRightOfUserOnResources(userCrn, action, crnsByCategory.getNotDefaultResourceCrns()));
        }
        return result;
    }
}
Also used : CrnsByCategory(com.sequenceiq.authorization.service.defaults.CrnsByCategory) HashMap(java.util.HashMap) DefaultResourceChecker(com.sequenceiq.authorization.service.defaults.DefaultResourceChecker)

Aggregations

CrnsByCategory (com.sequenceiq.authorization.service.defaults.CrnsByCategory)2 DefaultResourceChecker (com.sequenceiq.authorization.service.defaults.DefaultResourceChecker)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1