@Test public void testIncompatibleSetFiltering() { when(commonPermissionCheckingUtils.proceed(any(), any(), anyLong())).thenReturn( Sets.newHashSet(RESOURCE_CRN1, RESOURCE_CRN2, RESOURCE_CRN3)); thrown.expect(IllegalStateException.class); thrown.expectMessage("Items of your response list or set should implement ResourceCrnAwareApiModel interface"); underTest.checkPermissions(getAnnotation(), null, null, null, 0L); }
public Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { AuthorizationResourceAction action = methodAnnotation.action(); if (commonPermissionCheckingUtils.legacyAuthorizationNeeded()) { commonPermissionCheckingUtils.checkPermissionForUser(action, userCrn); return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } List<String> allResourceCrns = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action).getResourceCrnsInAccount(); Set<String> filteredResourceCrns = commonPermissionCheckingUtils.getPermissionsForUserOnResources(action, userCrn, allResourceCrns) .entrySet() .stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .collect(Collectors.toSet()); Object result = commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); switch (ListResponseFilteringType.getByClass(result.getClass())) { case SET: return filterSet(filteredResourceCrns, (Set) result); case LIST: return filterList(filteredResourceCrns, (List) result); case FILTERABLE_RESPONSE_MODEL: return filterAuthorizationFilterableResponse(filteredResourceCrns, (AuthorizationFilterableResponseCollection) result); case UNSUPPORTED: default: throw new IllegalStateException("Response of list API should be List, Set or an instance of " + "AuthorizationFilterableResponseCollection interface"); } }
ListPermissionChecker { public Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { AuthorizationResourceAction action = methodAnnotation.action(); if (commonPermissionCheckingUtils.legacyAuthorizationNeeded()) { commonPermissionCheckingUtils.checkPermissionForUser(action, userCrn); return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } List<String> allResourceCrns = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action).getResourceCrnsInAccount(); Set<String> filteredResourceCrns = commonPermissionCheckingUtils.getPermissionsForUserOnResources(action, userCrn, allResourceCrns) .entrySet() .stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .collect(Collectors.toSet()); Object result = commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); switch (ListResponseFilteringType.getByClass(result.getClass())) { case SET: return filterSet(filteredResourceCrns, (Set) result); case LIST: return filterList(filteredResourceCrns, (List) result); case FILTERABLE_RESPONSE_MODEL: return filterAuthorizationFilterableResponse(filteredResourceCrns, (AuthorizationFilterableResponseCollection) result); case UNSUPPORTED: default: throw new IllegalStateException("Response of list API should be List, Set or an instance of " + "AuthorizationFilterableResponseCollection interface"); } } }
ListPermissionChecker { public Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { AuthorizationResourceAction action = methodAnnotation.action(); if (commonPermissionCheckingUtils.legacyAuthorizationNeeded()) { commonPermissionCheckingUtils.checkPermissionForUser(action, userCrn); return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } List<String> allResourceCrns = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action).getResourceCrnsInAccount(); Set<String> filteredResourceCrns = commonPermissionCheckingUtils.getPermissionsForUserOnResources(action, userCrn, allResourceCrns) .entrySet() .stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .collect(Collectors.toSet()); Object result = commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); switch (ListResponseFilteringType.getByClass(result.getClass())) { case SET: return filterSet(filteredResourceCrns, (Set) result); case LIST: return filterList(filteredResourceCrns, (List) result); case FILTERABLE_RESPONSE_MODEL: return filterAuthorizationFilterableResponse(filteredResourceCrns, (AuthorizationFilterableResponseCollection) result); case UNSUPPORTED: default: throw new IllegalStateException("Response of list API should be List, Set or an instance of " + "AuthorizationFilterableResponseCollection interface"); } }  }
ListPermissionChecker { public Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { AuthorizationResourceAction action = methodAnnotation.action(); if (commonPermissionCheckingUtils.legacyAuthorizationNeeded()) { commonPermissionCheckingUtils.checkPermissionForUser(action, userCrn); return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } List<String> allResourceCrns = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action).getResourceCrnsInAccount(); Set<String> filteredResourceCrns = commonPermissionCheckingUtils.getPermissionsForUserOnResources(action, userCrn, allResourceCrns) .entrySet() .stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .collect(Collectors.toSet()); Object result = commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); switch (ListResponseFilteringType.getByClass(result.getClass())) { case SET: return filterSet(filteredResourceCrns, (Set) result); case LIST: return filterList(filteredResourceCrns, (List) result); case FILTERABLE_RESPONSE_MODEL: return filterAuthorizationFilterableResponse(filteredResourceCrns, (AuthorizationFilterableResponseCollection) result); case UNSUPPORTED: default: throw new IllegalStateException("Response of list API should be List, Set or an instance of " + "AuthorizationFilterableResponseCollection interface"); } }  Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn,
            ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime); }
ListPermissionChecker { public Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { AuthorizationResourceAction action = methodAnnotation.action(); if (commonPermissionCheckingUtils.legacyAuthorizationNeeded()) { commonPermissionCheckingUtils.checkPermissionForUser(action, userCrn); return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } List<String> allResourceCrns = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action).getResourceCrnsInAccount(); Set<String> filteredResourceCrns = commonPermissionCheckingUtils.getPermissionsForUserOnResources(action, userCrn, allResourceCrns) .entrySet() .stream() .filter(Map.Entry::getValue) .map(Map.Entry::getKey) .collect(Collectors.toSet()); Object result = commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); switch (ListResponseFilteringType.getByClass(result.getClass())) { case SET: return filterSet(filteredResourceCrns, (Set) result); case LIST: return filterList(filteredResourceCrns, (List) result); case FILTERABLE_RESPONSE_MODEL: return filterAuthorizationFilterableResponse(filteredResourceCrns, (AuthorizationFilterableResponseCollection) result); case UNSUPPORTED: default: throw new IllegalStateException("Response of list API should be List, Set or an instance of " + "AuthorizationFilterableResponseCollection interface"); } }  Object checkPermissions(FilterListBasedOnPermissions methodAnnotation, String userCrn,
            ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime);  }