use of org.glassfish.jersey.server.model.AnnotatedMethod in project dropwizard by dropwizard.
the class PolymorphicAuthDynamicFeature method configure.
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
final Class<?>[] parameterTypes = am.getParameterTypes();
final Type[] parameterGenericTypes = am.getGenericParameterTypes();
for (int i = 0; i < parameterAnnotations.length; i++) {
final Class<?> type = parameterTypes[i];
// If the parameter type is an Optional, extract its type
// parameter. Otherwise, use the parameter type itself.
final Type paramType = type == Optional.class ? ((ParameterizedType) parameterGenericTypes[i]).getActualTypeArguments()[0] : type;
for (final Annotation annotation : parameterAnnotations[i]) {
if (annotation instanceof Auth && authFilterMap.containsKey(paramType)) {
final ContainerRequestFilter filter = authFilterMap.get(paramType);
context.register(type == Optional.class ? new WebApplicationExceptionCatchingFilter(filter) : filter);
return;
}
}
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project drill by axbaretto.
the class AuthDynamicFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
return;
}
// path's doesn't go through AuthCheckFilter.
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project drill by axbaretto.
the class AuthDynamicFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
return;
}
// PermitAll takes precedence over RolesAllowed on the class
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project dropwizard by dropwizard.
the class AuthDynamicFeature method configure.
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
final Class<?>[] parameterTypes = am.getParameterTypes();
// First, check for any @Auth annotations on the method.
for (int i = 0; i < parameterAnnotations.length; i++) {
if (containsAuthAnnotation(parameterAnnotations[i])) {
// Optional auth requires that a concrete AuthFilter be provided.
if (parameterTypes[i].equals(Optional.class) && authFilter != null) {
context.register(new WebApplicationExceptionCatchingFilter(authFilter));
} else {
registerAuthFilter(context);
}
return;
}
}
// Second, check for any authorization annotations on the class or method.
// Note that @DenyAll shouldn't be attached to classes.
final boolean annotationOnClass = (resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class) != null) || (resourceInfo.getResourceClass().getAnnotation(PermitAll.class) != null);
final boolean annotationOnMethod = am.isAnnotationPresent(RolesAllowed.class) || am.isAnnotationPresent(DenyAll.class) || am.isAnnotationPresent(PermitAll.class);
if (annotationOnClass || annotationOnMethod) {
registerAuthFilter(context);
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project dropwizard by dropwizard.
the class CacheControlledResponseFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// check to see if it has cache control annotation
final CacheControl cc = am.getAnnotation(CacheControl.class);
if (cc != null) {
configuration.register(new CacheControlledResponseFilter(cc));
}
}
Aggregations