diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java index 923c7002932..2e4381ad5dc 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/RunAsAnnotationHandler.java @@ -21,7 +21,6 @@ package org.eclipse.jetty.annotations; import javax.servlet.Servlet; import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler; -import org.eclipse.jetty.plus.annotation.RunAsCollection; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -64,14 +63,7 @@ public class RunAsAnnotationHandler extends AbstractIntrospectableAnnotationHand 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(clazz.getName(), role); - RunAsCollection raCollection = (RunAsCollection)_context.getAttribute(RunAsCollection.RUNAS_COLLECTION); - if (raCollection == null) - { - raCollection = new RunAsCollection(); - _context.setAttribute(RunAsCollection.RUNAS_COLLECTION, raCollection); - } - raCollection.add(ra); + holder.setRunAsRole(role); } } } diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestRunAsAnnotation.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestRunAsAnnotation.java new file mode 100644 index 00000000000..e79a4ffb286 --- /dev/null +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestRunAsAnnotation.java @@ -0,0 +1,60 @@ +// +// ======================================================================== +// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + +package org.eclipse.jetty.annotations; + +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.webapp.WebAppContext; +import org.eclipse.jetty.webapp.WebDescriptor; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestRunAsAnnotation +{ + @Test + public void testRunAsAnnotation() throws Exception + { + WebAppContext wac = new WebAppContext(); + + //pre-add a servlet but not by descriptor + ServletHolder holder = new ServletHolder(); + holder.setName("foo1"); + holder.setHeldClass(ServletC.class); + holder.setInitOrder(1); //load on startup + wac.getServletHandler().addServletWithMapping(holder, "/foo/*"); + + //add another servlet of the same class, but as if by descriptor + ServletHolder holder2 = new ServletHolder(); + holder2.setName("foo2"); + holder2.setHeldClass(ServletC.class); + holder2.setInitOrder(1); + wac.getServletHandler().addServletWithMapping(holder2, "/foo2/*"); + wac.getMetaData().setOrigin(holder2.getName() + ".servlet.run-as", new WebDescriptor(null)); + + AnnotationIntrospector parser = new AnnotationIntrospector(); + RunAsAnnotationHandler handler = new RunAsAnnotationHandler(wac); + parser.registerHandler(handler); + parser.introspect(ServletC.class); + + assertEquals("admin", holder.getRunAsRole()); + assertEquals(null, holder2.getRunAsRole()); + + + } +} diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAs.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAs.java index 09169337700..b5ccfb71738 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAs.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAs.java @@ -26,7 +26,9 @@ import org.eclipse.jetty.servlet.ServletHolder; * RunAs *
* Represents a <run-as>
element in web.xml, or a @RunAs
annotation.
+ * @deprecated unused as of 9.4.28 due for removal in 10.0.0
*/
+@Deprecated
public class RunAs
{
private String _className;
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAsCollection.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAsCollection.java
index 86f7dd682ff..ad43dd080c3 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAsCollection.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/RunAsCollection.java
@@ -27,7 +27,9 @@ import org.eclipse.jetty.util.log.Logger;
/**
* RunAsCollection
+ * @deprecated class unused as of 9.4.28 due for removal in 10.0.0
*/
+@Deprecated
public class RunAsCollection
{
private static final Logger LOG = Log.getLogger(RunAsCollection.class);
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDecorator.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDecorator.java
index be30c521292..b93d91764f6 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDecorator.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDecorator.java
@@ -20,7 +20,6 @@ package org.eclipse.jetty.plus.webapp;
import org.eclipse.jetty.plus.annotation.InjectionCollection;
import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
-import org.eclipse.jetty.plus.annotation.RunAsCollection;
import org.eclipse.jetty.util.Decorator;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -43,11 +42,6 @@ public class PlusDecorator implements Decorator
@Override
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);
diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDescriptorProcessor.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDescriptorProcessor.java
index 410a61cba73..c434ade24b5 100644
--- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDescriptorProcessor.java
+++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/webapp/PlusDescriptorProcessor.java
@@ -20,7 +20,6 @@ package org.eclipse.jetty.plus.webapp;
import java.util.Iterator;
import java.util.Objects;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameNotFoundException;
@@ -33,7 +32,6 @@ import org.eclipse.jetty.plus.annotation.LifeCycleCallback;
import org.eclipse.jetty.plus.annotation.LifeCycleCallbackCollection;
import org.eclipse.jetty.plus.annotation.PostConstructCallback;
import org.eclipse.jetty.plus.annotation.PreDestroyCallback;
-import org.eclipse.jetty.plus.annotation.RunAsCollection;
import org.eclipse.jetty.plus.jndi.EnvEntry;
import org.eclipse.jetty.plus.jndi.Link;
import org.eclipse.jetty.plus.jndi.NamingEntry;
@@ -93,13 +91,6 @@ public class PlusDescriptorProcessor extends IterativeDescriptorProcessor
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);
- }
}
/**
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
index 28c4974ba6f..8a39f77b83e 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java
@@ -392,18 +392,6 @@ public class ServletHolder extends Holder