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());
}
}
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;
}
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);
}
}
Aggregations