1
0

feature/use-case-acceptance-tests-2 (#117)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/117
Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
Michael Hoennig
2024-11-05 13:58:31 +01:00
parent 3b94f117fb
commit 63af33d003
36 changed files with 1008 additions and 140 deletions

View File

@ -1,44 +0,0 @@
package net.hostsharing.hsadminng.reflection;
import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Optional;
import static java.util.Optional.empty;
@UtilityClass
public class AnnotationFinder {
@SneakyThrows
public static <T extends Annotation> Optional<T> findCallerAnnotation(
final Class<T> annotationClassToFind,
final Class<? extends Annotation> annotationClassToStopLookup
) {
for (var element : Thread.currentThread().getStackTrace()) {
final var clazz = Class.forName(element.getClassName());
final var method = getMethodFromStackElement(clazz, element);
// Check if the method is annotated with the desired annotation
if (method != null) {
if (method.isAnnotationPresent(annotationClassToFind)) {
return Optional.of(method.getAnnotation(annotationClassToFind));
} else if (method.isAnnotationPresent(annotationClassToStopLookup)) {
return empty();
}
}
}
return empty();
}
private static Method getMethodFromStackElement(Class<?> clazz, StackTraceElement element) {
for (var method : clazz.getDeclaredMethods()) {
if (method.getName().equals(element.getMethodName())) {
return method;
}
}
return null;
}
}

View File

@ -7,7 +7,7 @@ get:
parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles'
- name: name
- name: iban
in: query
required: false
schema: