@Test public void testCheckPermissionsWithResourceObjectWithFieldAnnotationOnNameStringField() { when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new DatahubResourceObjectWithNameAnnotation()); String datahubCrn = "crn:cdp:datalake:us-west-1:460c0d8f-ae8e-4dce-9cd7-2351762eb9ac:datahub:614a791a-a100-4f83-8c65-968fe9b06d47"; when(resourceBasedCrnProvider.getResourceCrnByResourceName(anyString())).thenReturn(datahubCrn); String envCrn = "crn:cdp:environments:us-west-1:460c0d8f-ae8e-4dce-9cd7-2351762eb9ac:environment:6b2b1600-8ac6-4c26-aa34-dab36f4bd243"; when(resourceBasedCrnProvider.getEnvironmentCrnByResourceCrn(eq(datahubCrn))).thenReturn(Optional.of(envCrn)); doNothing().when(commonPermissionCheckingUtils).checkPermissionForUserOnResource(any(), anyString()); underTest.checkPermissions(getAnnotation(false), USER_CRN, null, null, 0L); verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceObject.class), eq(Object.class)); ArgumentCaptor<Map<String, AuthorizationResourceAction>> captor = ArgumentCaptor.forClass(Map.class); verify(commonPermissionCheckingUtils).checkPermissionForUserOnResource(captor.capture(), eq(USER_CRN)); Map<String, AuthorizationResourceAction> capturedActions = captor.getValue(); assertEquals(2, capturedActions.keySet().size()); assertThat(capturedActions, IsMapContaining.hasEntry(datahubCrn, AuthorizationResourceAction.DELETE_DATAHUB)); assertThat(capturedActions, IsMapContaining.hasEntry(envCrn, AuthorizationResourceAction.DELETE_DATAHUB)); verify(resourceBasedCrnProvider).getResourceCrnByResourceName(eq("resource")); }
@Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceObject methodAnnotation = (CheckPermissionByResourceObject) rawMethodAnnotation; Object resourceObject = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceObject.class, Object.class); checkPermissionOnResourceObjectFields(userCrn, resourceObject, methodAnnotation.deepSearchNeeded()); }
ResourceObjectPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceObject> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceObject methodAnnotation = (CheckPermissionByResourceObject) rawMethodAnnotation; Object resourceObject = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceObject.class, Object.class); checkPermissionOnResourceObjectFields(userCrn, resourceObject, methodAnnotation.deepSearchNeeded()); } }
ResourceObjectPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceObject> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceObject methodAnnotation = (CheckPermissionByResourceObject) rawMethodAnnotation; Object resourceObject = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceObject.class, Object.class); checkPermissionOnResourceObjectFields(userCrn, resourceObject, methodAnnotation.deepSearchNeeded()); }  }
ResourceObjectPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceObject> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceObject methodAnnotation = (CheckPermissionByResourceObject) rawMethodAnnotation; Object resourceObject = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceObject.class, Object.class); checkPermissionOnResourceObjectFields(userCrn, resourceObject, methodAnnotation.deepSearchNeeded()); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceObject> supportedAnnotation(); }
ResourceObjectPermissionChecker extends ResourcePermissionChecker<CheckPermissionByResourceObject> { @Override public <T extends Annotation> void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime) { CheckPermissionByResourceObject methodAnnotation = (CheckPermissionByResourceObject) rawMethodAnnotation; Object resourceObject = getCommonPermissionCheckingUtils().getParameter(proceedingJoinPoint, methodSignature, ResourceObject.class, Object.class); checkPermissionOnResourceObjectFields(userCrn, resourceObject, methodAnnotation.deepSearchNeeded()); }  @Override void checkPermissions(T rawMethodAnnotation, String userCrn, ProceedingJoinPoint proceedingJoinPoint,
            MethodSignature methodSignature, long startTime); @Override Class<CheckPermissionByResourceObject> supportedAnnotation();  }