@Test public void testCheckPermissions() { when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(USER_CRN); ResourceBasedCrnProvider resourceBasedCrnProvider = mock(ResourceBasedCrnProvider.class); when(resourceBasedCrnProvider.getEnvironmentCrnByResourceCrn(anyString())).thenReturn(Optional.empty()); when(commonPermissionCheckingUtils.getResourceBasedCrnProvider(AuthorizationResourceAction.EDIT_CREDENTIAL)).thenReturn(resourceBasedCrnProvider); CheckPermissionByResourceCrn rawMethodAnnotation = new CheckPermissionByResourceCrn() { @Override public AuthorizationResourceAction action() { return AuthorizationResourceAction.EDIT_CREDENTIAL; } @Override public Class<? extends Annotation> annotationType() { return CheckPermissionByResourceCrn.class; } }; underTest.checkPermissions(rawMethodAnnotation, USER_CRN, null, null, 0L); verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceCrn.class), eq(String.class)); verify(commonPermissionCheckingUtils, times(0)).checkPermissionForUser(any(), anyString()); ArgumentCaptor<Map<String, AuthorizationResourceAction>> captor = ArgumentCaptor.forClass(Map.class); verify(commonPermissionCheckingUtils).checkPermissionForUserOnResource(captor.capture(), eq(USER_CRN)); Map<String, AuthorizationResourceAction> capturedActions = captor.getValue(); assertEquals(1, capturedActions.keySet().size()); assertThat(capturedActions, IsMapContaining.hasEntry(USER_CRN, AuthorizationResourceAction.EDIT_CREDENTIAL)); }
@Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceCrn methodAnnotation = (CheckPermissionByResourceCrn) rawMethodAnnotation; String resourceCrn = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceCrn.class, String.class); AuthorizationResourceAction action = methodAnnotation.action(); Map<String, AuthorizationResourceAction> authorizationActions = getAuthorizationActions(resourceCrn, action); getCommonPermissionCheckingUtils().checkPermissionForUserOnResource(authorizationActions, userCrn); }
ResourceCrnPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceCrn> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceCrn methodAnnotation = (CheckPermissionByResourceCrn) rawMethodAnnotation; String resourceCrn = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceCrn.class, String.class); AuthorizationResourceAction action = methodAnnotation.action(); Map<String, AuthorizationResourceAction> authorizationActions = getAuthorizationActions(resourceCrn, action); getCommonPermissionCheckingUtils().checkPermissionForUserOnResource(authorizationActions, userCrn); } }
ResourceCrnPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceCrn> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceCrn methodAnnotation = (CheckPermissionByResourceCrn) rawMethodAnnotation; String resourceCrn = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceCrn.class, String.class); AuthorizationResourceAction action = methodAnnotation.action(); Map<String, AuthorizationResourceAction> authorizationActions = getAuthorizationActions(resourceCrn, action); getCommonPermissionCheckingUtils().checkPermissionForUserOnResource(authorizationActions, userCrn); }  }
ResourceCrnPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceCrn> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceCrn methodAnnotation = (CheckPermissionByResourceCrn) rawMethodAnnotation; String resourceCrn = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceCrn.class, String.class); AuthorizationResourceAction action = methodAnnotation.action(); Map<String, AuthorizationResourceAction> authorizationActions = getAuthorizationActions(resourceCrn, action); getCommonPermissionCheckingUtils().checkPermissionForUserOnResource(authorizationActions, userCrn); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceCrn> supportedAnnotation(); }
ResourceCrnPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceCrn> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceCrn methodAnnotation = (CheckPermissionByResourceCrn) rawMethodAnnotation; String resourceCrn = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceCrn.class, String.class); AuthorizationResourceAction action = methodAnnotation.action(); Map<String, AuthorizationResourceAction> authorizationActions = getAuthorizationActions(resourceCrn, action); getCommonPermissionCheckingUtils().checkPermissionForUserOnResource(authorizationActions, userCrn); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceCrn> supportedAnnotation();  }