Search in sources :

Example 1 with PDSStep

use of com.mercedesbenz.sechub.pds.usecase.PDSStep in project sechub by mercedes-benz.

the class PDSUseCaseModelDataCollector method collectAnnotationInfo.

private <T extends Annotation> void collectAnnotationInfo(UseCaseModel model, Class<T> useCaseAnnotationClazz) {
    if (DEBUG) {
        LOG.info("start collecting annotation info:{}", useCaseAnnotationClazz);
    }
    Set<Method> methodsAnnotated = reflections.getMethodsAnnotatedWith(useCaseAnnotationClazz);
    if (DEBUG) {
        LOG.info("found methods annotated with:{} - {}", useCaseAnnotationClazz, methodsAnnotated);
    }
    for (Method method : methodsAnnotated) {
        List<RolesAllowed> rolesAllowed = fetchAllAllowedRoles(method);
        T[] annosFound = method.getAnnotationsByType(useCaseAnnotationClazz);
        if (DEBUG) {
            LOG.info("inspect method:{}\n - roles found:{}\n - annos found:{}", method, rolesAllowed, annosFound);
        }
        for (T anno : annosFound) {
            UseCaseEntry useCaseEntry = model.ensureUseCase(anno.getClass());
            try {
                Method valueMethod = anno.getClass().getMethod("value");
                Object value = valueMethod.invoke(anno);
                if (value instanceof PDSStep) {
                    String location = "method `" + method.getName() + "` in class `" + method.getDeclaringClass().getName() + "`";
                    useCaseEntry.addStep((PDSStep) value, rolesAllowed, location);
                }
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : RolesAllowed(javax.annotation.security.RolesAllowed) UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry) Method(java.lang.reflect.Method) PDSStep(com.mercedesbenz.sechub.pds.usecase.PDSStep)

Aggregations

UseCaseEntry (com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry)1 PDSStep (com.mercedesbenz.sechub.pds.usecase.PDSStep)1 Method (java.lang.reflect.Method)1 RolesAllowed (javax.annotation.security.RolesAllowed)1