ifs-security/src/test/java/org/innovateuk/ifs/commons/AbstractServiceSecurityAnnotationsTest.java
/**
     * Test that all methods and classes that need descriptive {@link SecuredBySpring} {@link Annotation}s have them.
     * This is considered to be the case if they have a Spring security {@link Annotation} with simple rules that will
     * not invoke any of the {@link RootCustomPermissionEvaluator} functionality, see
     * {@link AbstractServiceSecurityAnnotationsTest#requiresSecuredBySpringAnnotation}
     * <p>
     * See also {@link AbstractDocumentingServiceSecurityAnnotationsTest}
     *
     * @throws Exception
     */
Test that all methods and classes that need descriptive  SecuredBySpring  Annotations have them.
This is considered to be the case if they have a Spring security  Annotation with simple rules that will
not invoke any of the  RootCustomPermissionEvaluator functionality, see
AbstractServiceSecurityAnnotationsTest#requiresSecuredBySpringAnnotation

See also  AbstractDocumentingServiceSecurityAnnotationsTest

@throws Exception
Test that all methods and classes that need descriptive SecuredBySpring Annotations have them . This is considered to be the case if they have a Spring security Annotation with simple rules that will not invoke any of the RootCustomPermissionEvaluator functionality see AbstractServiceSecurityAnnotationsTest#requiresSecuredBySpringAnnotation See also AbstractDocumentingServiceSecurityAnnotationsTest @throws Exception
@Test
    public void testServiceMethodsHaveSecurityDocumentationAnnotations() throws Exception {
        Collection<Object> services = servicesToTest();
        assertNotNull(services);
        assertFalse(services.isEmpty());
        List<Class<?>> classLevelFailures = new ArrayList<>();
        List<Method> methodLevelFailures = new ArrayList<>();
        for (Object service : services) {
            if (isSecuredAtClassLevel(service)) {
                Class<?> serviceClass = service.getClass();
                if (!hasOneOf(serviceClass, Collections.singletonList(SecuredBySpring.class))) {
                    classLevelFailures.add(serviceClass);
                }
            }
            for (Method method : service.getClass().getMethods()) {
                if (methodNeedsSecuring(method)) {
                    if (requiresSecuredBySpringAnnotation(method) && !hasOneOf(method, Collections.singletonList(SecuredBySpring.class))) {
                        methodLevelFailures.add(method);
                    }
                }
            }
        }
        if (!classLevelFailures.isEmpty() || !methodLevelFailures.isEmpty()) {
            fail(classFailureMessage("The following classes need to have a SecuredBySpring annotation:", classLevelFailures) + "\n" +
                    methodFailureMessage("The following methods need to have a SecuredBySpring annotation:", methodLevelFailures));
        }
    }
@ Test public void testServiceMethodsHaveSecurityDocumentationAnnotations ( ) throws Exception { Collection < Object > services = servicesToTest ( ) ; assertNotNull ( services ) ; assertFalse ( services . isEmpty ( ) ) ; List < Class < ? > > classLevelFailures = new ArrayList < > ( ) ; List < Method > methodLevelFailures = new ArrayList < > ( ) ; for ( Object service : services ) { if ( isSecuredAtClassLevel ( service ) ) { Class < ? > serviceClass = service . getClass ( ) ; if ( ! hasOneOf ( serviceClass , Collections . singletonList ( SecuredBySpring . class ) ) ) { classLevelFailures . add ( serviceClass ) ; } } for ( Method method : service . getClass ( ) . getMethods ( ) ) { if ( methodNeedsSecuring ( method ) ) { if ( requiresSecuredBySpringAnnotation ( method ) && ! hasOneOf ( method , Collections . singletonList ( SecuredBySpring . class ) ) ) { methodLevelFailures . add ( method ) ; } } } } if ( ! classLevelFailures . isEmpty ( ) || ! methodLevelFailures . isEmpty ( ) ) { fail ( classFailureMessage ( "The following classes need to have a SecuredBySpring annotation:" , classLevelFailures ) + "\n" + methodFailureMessage ( "The following methods need to have a SecuredBySpring annotation:" , methodLevelFailures ) ) ; } }
Test that all methods and classes that need descriptive {@link SecuredBySpring} {@link Annotation}s have them.
Test that all methods and classes that need descriptive { @link SecuredBySpring } { @link Annotation } s have them .
// Assert that we actually have some services. // First check at class level // Currently if its secured at class level we need a SecuredBySpring annotation. // Now for all of the methods // Output all of the errors