@Test public void testCheckPermissions() { doNothing().when(commonPermissionCheckingUtils).checkPermissionForUserOnResources(any(), anyString(), any()); when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(Lists.newArrayList("resource", "resource")); when(resourceBasedCrnProvider.getResourceCrnListByResourceNameList(anyList())).thenReturn(Lists.newArrayList(USER_CRN, USER_CRN)); CheckPermissionByResourceNameList rawMethodAnnotation = new CheckPermissionByResourceNameList() { @Override public AuthorizationResourceAction action() { return AuthorizationResourceAction.EDIT_CREDENTIAL; } @Override public Class<? extends Annotation> annotationType() { return CheckPermissionByResourceNameList.class; } }; underTest.checkPermissions(rawMethodAnnotation, USER_CRN, null, null, 0L); verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceNameList.class), eq(Collection.class)); verify(commonPermissionCheckingUtils, times(0)).checkPermissionForUser(any(), anyString()); verify(commonPermissionCheckingUtils).checkPermissionForUserOnResources(eq(AuthorizationResourceAction.EDIT_CREDENTIAL), eq(USER_CRN), any()); }
@Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceNameList methodAnnotation = (CheckPermissionByResourceNameList) rawMethodAnnotation; AuthorizationResourceAction action = methodAnnotation.action(); Collection<String> resourceNames = commonPermissionCheckingUtils .getParameter(proceedingJoinPoint, methodSignature, ResourceNameList.class, Collection.class); List<String> resourceCrnList = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action) .getResourceCrnListByResourceNameList(getNotNullResourceNames(resourceNames)); commonPermissionCheckingUtils.checkPermissionForUserOnResources(action, userCrn, resourceCrnList); }
ResourceNameListPermissionChecker implements PermissionChecker<CheckPermissionByResourceNameList> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceNameList methodAnnotation = (CheckPermissionByResourceNameList) rawMethodAnnotation; AuthorizationResourceAction action = methodAnnotation.action(); Collection<String> resourceNames = commonPermissionCheckingUtils .getParameter(proceedingJoinPoint, methodSignature, ResourceNameList.class, Collection.class); List<String> resourceCrnList = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action) .getResourceCrnListByResourceNameList(getNotNullResourceNames(resourceNames)); commonPermissionCheckingUtils.checkPermissionForUserOnResources(action, userCrn, resourceCrnList); } }
ResourceNameListPermissionChecker implements PermissionChecker<CheckPermissionByResourceNameList> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceNameList methodAnnotation = (CheckPermissionByResourceNameList) rawMethodAnnotation; AuthorizationResourceAction action = methodAnnotation.action(); Collection<String> resourceNames = commonPermissionCheckingUtils .getParameter(proceedingJoinPoint, methodSignature, ResourceNameList.class, Collection.class); List<String> resourceCrnList = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action) .getResourceCrnListByResourceNameList(getNotNullResourceNames(resourceNames)); commonPermissionCheckingUtils.checkPermissionForUserOnResources(action, userCrn, resourceCrnList); }  }
ResourceNameListPermissionChecker implements PermissionChecker<CheckPermissionByResourceNameList> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceNameList methodAnnotation = (CheckPermissionByResourceNameList) rawMethodAnnotation; AuthorizationResourceAction action = methodAnnotation.action(); Collection<String> resourceNames = commonPermissionCheckingUtils .getParameter(proceedingJoinPoint, methodSignature, ResourceNameList.class, Collection.class); List<String> resourceCrnList = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action) .getResourceCrnListByResourceNameList(getNotNullResourceNames(resourceNames)); commonPermissionCheckingUtils.checkPermissionForUserOnResources(action, userCrn, resourceCrnList); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceNameList> supportedAnnotation(); }
ResourceNameListPermissionChecker implements PermissionChecker<CheckPermissionByResourceNameList> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceNameList methodAnnotation = (CheckPermissionByResourceNameList) rawMethodAnnotation; AuthorizationResourceAction action = methodAnnotation.action(); Collection<String> resourceNames = commonPermissionCheckingUtils .getParameter(proceedingJoinPoint, methodSignature, ResourceNameList.class, Collection.class); List<String> resourceCrnList = commonPermissionCheckingUtils.getResourceBasedCrnProvider(action) .getResourceCrnListByResourceNameList(getNotNullResourceNames(resourceNames)); commonPermissionCheckingUtils.checkPermissionForUserOnResources(action, userCrn, resourceCrnList); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceNameList> supportedAnnotation();  }