Search in sources :

Example 1 with HttpResponse

use of org.jboss.resteasy.spi.HttpResponse in project candlepin by candlepin.

the class VerifyAuthorizationFilter method getArguments.

protected Map<Verify, Object> getArguments(HttpRequest request, Method method) {
    ResteasyProviderFactory resourceFactory = ResteasyProviderFactory.getInstance();
    InjectorFactory injectorFactory = resourceFactory.getInjectorFactory();
    ResourceLocator locator = locatorMap.get(method);
    if (null == locator) {
        throw new IseException("Method " + method.getName() + " not registered as RESTful.");
    }
    MethodInjector methodInjector = injectorFactory.createMethodInjector(locator, resourceFactory);
    HttpResponse response = ResteasyProviderFactory.popContextData(HttpResponse.class);
    Object[] args = methodInjector.injectArguments(request, response);
    // LinkedHashMap preserves insertion order
    Map<Verify, Object> argMap = new LinkedHashMap<>();
    Annotation[][] allAnnotations = method.getParameterAnnotations();
    // Any occurrence of the Verify annotation means the method is not superadmin exclusive.
    for (int i = 0; i < allAnnotations.length; i++) {
        for (Annotation a : allAnnotations[i]) {
            if (a instanceof Verify) {
                Verify v = (Verify) a;
                if (!v.nullable() && args[i] == null) {
                    throw new IllegalStateException("Null passed to a non-nullable Verify annotation.");
                } else {
                    argMap.put(v, args[i]);
                }
            }
        }
    }
    return argMap;
}
Also used : HttpResponse(org.jboss.resteasy.spi.HttpResponse) Annotation(java.lang.annotation.Annotation) LinkedHashMap(java.util.LinkedHashMap) MethodInjector(org.jboss.resteasy.spi.MethodInjector) IseException(org.candlepin.common.exceptions.IseException) InjectorFactory(org.jboss.resteasy.spi.InjectorFactory) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Verify(org.candlepin.auth.Verify) ResourceLocator(org.jboss.resteasy.spi.metadata.ResourceLocator)

Aggregations

Annotation (java.lang.annotation.Annotation)1 LinkedHashMap (java.util.LinkedHashMap)1 Verify (org.candlepin.auth.Verify)1 IseException (org.candlepin.common.exceptions.IseException)1 HttpResponse (org.jboss.resteasy.spi.HttpResponse)1 InjectorFactory (org.jboss.resteasy.spi.InjectorFactory)1 MethodInjector (org.jboss.resteasy.spi.MethodInjector)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 ResourceLocator (org.jboss.resteasy.spi.metadata.ResourceLocator)1