@Test public void testGetParameterWithIncorrectlyParametrizedMethod() throws NoSuchMethodException { when(methodSignature.getMethod()) .thenReturn(ExampleAuthorizationResourceClass.class.getMethod("exampleMethodWithParamAnnotation", String.class, String.class)); when(proceedingJoinPoint.getArgs()).thenReturn(new Object[]{0L, "other"}); IllegalStateException exception = Assert.assertThrows(IllegalStateException.class, () -> { underTest.getParameter(proceedingJoinPoint, methodSignature, ResourceName.class, String.class); }); assertEquals("The type of the annotated parameter does not match with the expected type String", exception.getMessage()); }
public <T> T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target) { List<Parameter> parameters = Lists.newArrayList(methodSignature.getMethod().getParameters()); List<Parameter> matchingParameters = parameters.stream() .filter(parameter -> parameter.isAnnotationPresent(annotation)) .collect(Collectors.toList()); if (matchingParameters.size() != 1) { throw new IllegalStateException(String.format("Your controller method %s should have one and only one parameter with the annotation %s", methodSignature.getMethod().getName(), annotation.getSimpleName())); } Object result = proceedingJoinPoint.getArgs()[parameters.indexOf(matchingParameters.iterator().next())]; if (!target.isInstance(result)) { throw new IllegalStateException( String.format("The type of the annotated parameter does not match with the expected type %s", target.getSimpleName())); } return (T) result; }
CommonPermissionCheckingUtils { public <T> T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target) { List<Parameter> parameters = Lists.newArrayList(methodSignature.getMethod().getParameters()); List<Parameter> matchingParameters = parameters.stream() .filter(parameter -> parameter.isAnnotationPresent(annotation)) .collect(Collectors.toList()); if (matchingParameters.size() != 1) { throw new IllegalStateException(String.format("Your controller method %s should have one and only one parameter with the annotation %s", methodSignature.getMethod().getName(), annotation.getSimpleName())); } Object result = proceedingJoinPoint.getArgs()[parameters.indexOf(matchingParameters.iterator().next())]; if (!target.isInstance(result)) { throw new IllegalStateException( String.format("The type of the annotated parameter does not match with the expected type %s", target.getSimpleName())); } return (T) result; } }
CommonPermissionCheckingUtils { public <T> T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target) { List<Parameter> parameters = Lists.newArrayList(methodSignature.getMethod().getParameters()); List<Parameter> matchingParameters = parameters.stream() .filter(parameter -> parameter.isAnnotationPresent(annotation)) .collect(Collectors.toList()); if (matchingParameters.size() != 1) { throw new IllegalStateException(String.format("Your controller method %s should have one and only one parameter with the annotation %s", methodSignature.getMethod().getName(), annotation.getSimpleName())); } Object result = proceedingJoinPoint.getArgs()[parameters.indexOf(matchingParameters.iterator().next())]; if (!target.isInstance(result)) { throw new IllegalStateException( String.format("The type of the annotated parameter does not match with the expected type %s", target.getSimpleName())); } return (T) result; }  }
CommonPermissionCheckingUtils { public <T> T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target) { List<Parameter> parameters = Lists.newArrayList(methodSignature.getMethod().getParameters()); List<Parameter> matchingParameters = parameters.stream() .filter(parameter -> parameter.isAnnotationPresent(annotation)) .collect(Collectors.toList()); if (matchingParameters.size() != 1) { throw new IllegalStateException(String.format("Your controller method %s should have one and only one parameter with the annotation %s", methodSignature.getMethod().getName(), annotation.getSimpleName())); } Object result = proceedingJoinPoint.getArgs()[parameters.indexOf(matchingParameters.iterator().next())]; if (!target.isInstance(result)) { throw new IllegalStateException( String.format("The type of the annotated parameter does not match with the expected type %s", target.getSimpleName())); } return (T) result; }  @PostConstruct void init(); boolean legacyAuthorizationNeeded(); ResourceBasedCrnProvider getResourceBasedCrnProvider(AuthorizationResourceAction action); void checkPermissionForUser(AuthorizationResourceAction action, String userCrn); void checkPermissionForUserOnResource(Map<String, AuthorizationResourceAction> resourcesWithActions, String userCrn); void checkPermissionForUserOnResource(AuthorizationResourceAction action, String userCrn, String resourceCrn); void checkPermissionForUserOnResources(AuthorizationResourceAction action,
            String userCrn, Collection<String> resourceCrns); Map<String, Boolean> getPermissionsForUserOnResources(AuthorizationResourceAction action,
            String userCrn, List<String> resourceCrns); Object proceed(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime); boolean isAuthorizationDisabled(ProceedingJoinPoint proceedingJoinPoint); boolean isInternalOnly(ProceedingJoinPoint proceedingJoinPoint); T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target); }
CommonPermissionCheckingUtils { public <T> T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target) { List<Parameter> parameters = Lists.newArrayList(methodSignature.getMethod().getParameters()); List<Parameter> matchingParameters = parameters.stream() .filter(parameter -> parameter.isAnnotationPresent(annotation)) .collect(Collectors.toList()); if (matchingParameters.size() != 1) { throw new IllegalStateException(String.format("Your controller method %s should have one and only one parameter with the annotation %s", methodSignature.getMethod().getName(), annotation.getSimpleName())); } Object result = proceedingJoinPoint.getArgs()[parameters.indexOf(matchingParameters.iterator().next())]; if (!target.isInstance(result)) { throw new IllegalStateException( String.format("The type of the annotated parameter does not match with the expected type %s", target.getSimpleName())); } return (T) result; }  @PostConstruct void init(); boolean legacyAuthorizationNeeded(); ResourceBasedCrnProvider getResourceBasedCrnProvider(AuthorizationResourceAction action); void checkPermissionForUser(AuthorizationResourceAction action, String userCrn); void checkPermissionForUserOnResource(Map<String, AuthorizationResourceAction> resourcesWithActions, String userCrn); void checkPermissionForUserOnResource(AuthorizationResourceAction action, String userCrn, String resourceCrn); void checkPermissionForUserOnResources(AuthorizationResourceAction action,
            String userCrn, Collection<String> resourceCrns); Map<String, Boolean> getPermissionsForUserOnResources(AuthorizationResourceAction action,
            String userCrn, List<String> resourceCrns); Object proceed(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, long startTime); boolean isAuthorizationDisabled(ProceedingJoinPoint proceedingJoinPoint); boolean isInternalOnly(ProceedingJoinPoint proceedingJoinPoint); T getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation, Class<T> target);  }