@Test public void testHasPermissionIfAuthorizationDisabled() throws NoSuchMethodException { when(methodSignature.getMethod()).thenReturn(ExampleClass.class.getMethod("disabledAuthorization")); when(commonPermissionCheckingUtils.proceed(any(), any(), anyLong())).thenReturn(null); ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.hasPermission(proceedingJoinPoint)); verify(permissionChecker, times(0)).checkPermissions(any(), anyString(), any(), any(), anyLong()); }
public Object hasPermission(ProceedingJoinPoint proceedingJoinPoint) { long startTime = System.currentTimeMillis(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); LOGGER.debug("Permission check started at {} (method: {})", startTime, methodSignature.getMethod().getDeclaringClass().getSimpleName() + "#" + methodSignature.getMethod().getName()); Optional<Object> initiatorUserCrn = reflectionUtil.getParameter(proceedingJoinPoint, methodSignature, InitiatorUserCrn.class); if (InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn()) && initiatorUserCrn.isPresent() && initiatorUserCrn.get() instanceof String && Crn.isCrn((String) initiatorUserCrn.get())) { String newUserCrn = (String) initiatorUserCrn.get(); internalUserModifier.persistModifiedInternalUser(crnUserDetailsService.loadUserByUsername(newUserCrn)); return ThreadBasedUserCrnProvider.doAs(newUserCrn, () -> commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime)); } if (commonPermissionCheckingUtils.isAuthorizationDisabled(proceedingJoinPoint) || InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn())) { return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } checkPrerequisitesOnClass(proceedingJoinPoint, methodSignature); return checkPermission(proceedingJoinPoint, methodSignature, startTime); }
PermissionCheckService { public Object hasPermission(ProceedingJoinPoint proceedingJoinPoint) { long startTime = System.currentTimeMillis(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); LOGGER.debug("Permission check started at {} (method: {})", startTime, methodSignature.getMethod().getDeclaringClass().getSimpleName() + "#" + methodSignature.getMethod().getName()); Optional<Object> initiatorUserCrn = reflectionUtil.getParameter(proceedingJoinPoint, methodSignature, InitiatorUserCrn.class); if (InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn()) && initiatorUserCrn.isPresent() && initiatorUserCrn.get() instanceof String && Crn.isCrn((String) initiatorUserCrn.get())) { String newUserCrn = (String) initiatorUserCrn.get(); internalUserModifier.persistModifiedInternalUser(crnUserDetailsService.loadUserByUsername(newUserCrn)); return ThreadBasedUserCrnProvider.doAs(newUserCrn, () -> commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime)); } if (commonPermissionCheckingUtils.isAuthorizationDisabled(proceedingJoinPoint) || InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn())) { return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } checkPrerequisitesOnClass(proceedingJoinPoint, methodSignature); return checkPermission(proceedingJoinPoint, methodSignature, startTime); } }
PermissionCheckService { public Object hasPermission(ProceedingJoinPoint proceedingJoinPoint) { long startTime = System.currentTimeMillis(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); LOGGER.debug("Permission check started at {} (method: {})", startTime, methodSignature.getMethod().getDeclaringClass().getSimpleName() + "#" + methodSignature.getMethod().getName()); Optional<Object> initiatorUserCrn = reflectionUtil.getParameter(proceedingJoinPoint, methodSignature, InitiatorUserCrn.class); if (InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn()) && initiatorUserCrn.isPresent() && initiatorUserCrn.get() instanceof String && Crn.isCrn((String) initiatorUserCrn.get())) { String newUserCrn = (String) initiatorUserCrn.get(); internalUserModifier.persistModifiedInternalUser(crnUserDetailsService.loadUserByUsername(newUserCrn)); return ThreadBasedUserCrnProvider.doAs(newUserCrn, () -> commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime)); } if (commonPermissionCheckingUtils.isAuthorizationDisabled(proceedingJoinPoint) || InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn())) { return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } checkPrerequisitesOnClass(proceedingJoinPoint, methodSignature); return checkPermission(proceedingJoinPoint, methodSignature, startTime); }  }
PermissionCheckService { public Object hasPermission(ProceedingJoinPoint proceedingJoinPoint) { long startTime = System.currentTimeMillis(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); LOGGER.debug("Permission check started at {} (method: {})", startTime, methodSignature.getMethod().getDeclaringClass().getSimpleName() + "#" + methodSignature.getMethod().getName()); Optional<Object> initiatorUserCrn = reflectionUtil.getParameter(proceedingJoinPoint, methodSignature, InitiatorUserCrn.class); if (InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn()) && initiatorUserCrn.isPresent() && initiatorUserCrn.get() instanceof String && Crn.isCrn((String) initiatorUserCrn.get())) { String newUserCrn = (String) initiatorUserCrn.get(); internalUserModifier.persistModifiedInternalUser(crnUserDetailsService.loadUserByUsername(newUserCrn)); return ThreadBasedUserCrnProvider.doAs(newUserCrn, () -> commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime)); } if (commonPermissionCheckingUtils.isAuthorizationDisabled(proceedingJoinPoint) || InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn())) { return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } checkPrerequisitesOnClass(proceedingJoinPoint, methodSignature); return checkPermission(proceedingJoinPoint, methodSignature, startTime); }  @PostConstruct void populatePermissionCheckMap(); Object hasPermission(ProceedingJoinPoint proceedingJoinPoint); }
PermissionCheckService { public Object hasPermission(ProceedingJoinPoint proceedingJoinPoint) { long startTime = System.currentTimeMillis(); MethodSignature methodSignature = (MethodSignature) proceedingJoinPoint.getSignature(); LOGGER.debug("Permission check started at {} (method: {})", startTime, methodSignature.getMethod().getDeclaringClass().getSimpleName() + "#" + methodSignature.getMethod().getName()); Optional<Object> initiatorUserCrn = reflectionUtil.getParameter(proceedingJoinPoint, methodSignature, InitiatorUserCrn.class); if (InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn()) && initiatorUserCrn.isPresent() && initiatorUserCrn.get() instanceof String && Crn.isCrn((String) initiatorUserCrn.get())) { String newUserCrn = (String) initiatorUserCrn.get(); internalUserModifier.persistModifiedInternalUser(crnUserDetailsService.loadUserByUsername(newUserCrn)); return ThreadBasedUserCrnProvider.doAs(newUserCrn, () -> commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime)); } if (commonPermissionCheckingUtils.isAuthorizationDisabled(proceedingJoinPoint) || InternalCrnBuilder.isInternalCrn(ThreadBasedUserCrnProvider.getUserCrn())) { return commonPermissionCheckingUtils.proceed(proceedingJoinPoint, methodSignature, startTime); } checkPrerequisitesOnClass(proceedingJoinPoint, methodSignature); return checkPermission(proceedingJoinPoint, methodSignature, startTime); }  @PostConstruct void populatePermissionCheckMap(); Object hasPermission(ProceedingJoinPoint proceedingJoinPoint);  }