Search in sources :

Example 1 with RunAsCollection

use of org.eclipse.jetty.plus.annotation.RunAsCollection in project jetty.project by eclipse.

the class RunAsAnnotationHandler method doHandle.

public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        return;
    javax.annotation.security.RunAs runAs = (javax.annotation.security.RunAs) clazz.getAnnotation(javax.annotation.security.RunAs.class);
    if (runAs != null) {
        String role = runAs.value();
        if (role != null) {
            ServletHolder holder = getServletHolderForClass(clazz);
            if (holder != null) {
                MetaData metaData = _context.getMetaData();
                Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.run-as");
                //let the annotation override it
                if (d == null) {
                    metaData.setOrigin(holder.getName() + ".servlet.run-as", runAs, clazz);
                    org.eclipse.jetty.plus.annotation.RunAs ra = new org.eclipse.jetty.plus.annotation.RunAs();
                    ra.setTargetClassName(clazz.getCanonicalName());
                    ra.setRoleName(role);
                    RunAsCollection raCollection = (RunAsCollection) _context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
                    if (raCollection == null) {
                        raCollection = new RunAsCollection();
                        _context.setAttribute(RunAsCollection.RUNAS_COLLECTION, raCollection);
                    }
                    raCollection.add(ra);
                }
            }
        } else
            LOG.warn("Bad value for @RunAs annotation on class " + clazz.getName());
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) RunAsCollection(org.eclipse.jetty.plus.annotation.RunAsCollection) MetaData(org.eclipse.jetty.webapp.MetaData) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 2 with RunAsCollection

use of org.eclipse.jetty.plus.annotation.RunAsCollection in project jetty.project by eclipse.

the class PlusDecorator method decorate.

public Object decorate(Object o) {
    RunAsCollection runAses = (RunAsCollection) _context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
    if (runAses != null)
        runAses.setRunAs(o);
    InjectionCollection injections = (InjectionCollection) _context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
    if (injections != null)
        injections.inject(o);
    LifeCycleCallbackCollection callbacks = (LifeCycleCallbackCollection) _context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
    if (callbacks != null) {
        try {
            callbacks.callPostConstructCallback(o);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    return o;
}
Also used : InjectionCollection(org.eclipse.jetty.plus.annotation.InjectionCollection) LifeCycleCallbackCollection(org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection) RunAsCollection(org.eclipse.jetty.plus.annotation.RunAsCollection)

Example 3 with RunAsCollection

use of org.eclipse.jetty.plus.annotation.RunAsCollection in project jetty.project by eclipse.

the class PlusDescriptorProcessor method start.

/**
     * @see org.eclipse.jetty.webapp.IterativeDescriptorProcessor#start(WebAppContext, org.eclipse.jetty.webapp.Descriptor)
     */
public void start(WebAppContext context, Descriptor descriptor) {
    InjectionCollection injections = (InjectionCollection) context.getAttribute(InjectionCollection.INJECTION_COLLECTION);
    if (injections == null) {
        injections = new InjectionCollection();
        context.setAttribute(InjectionCollection.INJECTION_COLLECTION, injections);
    }
    LifeCycleCallbackCollection callbacks = (LifeCycleCallbackCollection) context.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION);
    if (callbacks == null) {
        callbacks = new LifeCycleCallbackCollection();
        context.setAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION, callbacks);
    }
    RunAsCollection runAsCollection = (RunAsCollection) context.getAttribute(RunAsCollection.RUNAS_COLLECTION);
    if (runAsCollection == null) {
        runAsCollection = new RunAsCollection();
        context.setAttribute(RunAsCollection.RUNAS_COLLECTION, runAsCollection);
    }
}
Also used : InjectionCollection(org.eclipse.jetty.plus.annotation.InjectionCollection) LifeCycleCallbackCollection(org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection) RunAsCollection(org.eclipse.jetty.plus.annotation.RunAsCollection)

Aggregations

RunAsCollection (org.eclipse.jetty.plus.annotation.RunAsCollection)3 InjectionCollection (org.eclipse.jetty.plus.annotation.InjectionCollection)2 LifeCycleCallbackCollection (org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection)2 Servlet (javax.servlet.Servlet)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 Descriptor (org.eclipse.jetty.webapp.Descriptor)1 MetaData (org.eclipse.jetty.webapp.MetaData)1