1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.plus.annotation;
15
16 import java.util.HashMap;
17
18 import javax.servlet.ServletException;
19
20 import org.eclipse.jetty.security.SecurityHandler;
21 import org.eclipse.jetty.servlet.ServletHolder;
22 import org.eclipse.jetty.util.log.Log;
23 import org.eclipse.jetty.webapp.WebAppContext;
24
25
26
27
28
29
30
31 public class RunAsCollection
32 {
33 public static final String RUNAS_COLLECTION = "org.eclipse.jetty.runAsCollection";
34 private HashMap _runAsMap = new HashMap();
35
36
37
38 public void add (RunAs runAs)
39 {
40 if ((runAs==null) || (runAs.getTargetClassName()==null))
41 return;
42
43 if (Log.isDebugEnabled())
44 Log.debug("Adding run-as for class="+runAs.getTargetClassName());
45 _runAsMap.put(runAs.getTargetClassName(), runAs);
46 }
47
48 public RunAs getRunAs (Object o)
49 throws ServletException
50 {
51 if (o==null)
52 return null;
53
54 return (RunAs)_runAsMap.get(o.getClass().getCanonicalName());
55 }
56
57 public void setRunAs(Object o)
58 throws ServletException
59 {
60 if (o == null)
61 return;
62
63 if (!ServletHolder.class.isAssignableFrom(o.getClass()))
64 return;
65
66 RunAs runAs = (RunAs)_runAsMap.get(o.getClass().getName());
67 if (runAs == null)
68 return;
69
70 runAs.setRunAs((ServletHolder)o);
71 }
72
73 }