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
24
25
26
27
28
29
30 public class RunAsCollection
31 {
32 public static final String RUNAS_COLLECTION = "org.eclipse.jetty.runAsCollection";
33 private HashMap _runAsMap = new HashMap();
34
35
36 public void add (RunAs runAs)
37 {
38 if ((runAs==null) || (runAs.getTargetClassName()==null))
39 return;
40
41 if (Log.isDebugEnabled())
42 Log.debug("Adding run-as for class="+runAs.getTargetClassName());
43 _runAsMap.put(runAs.getTargetClassName(), runAs);
44 }
45
46 public RunAs getRunAs (Object o)
47 throws ServletException
48 {
49 if (o==null)
50 return null;
51
52 if (!(o instanceof ServletHolder))
53 return null;
54
55 ServletHolder holder = (ServletHolder)o;
56
57 String className = holder.getClassName();
58 return (RunAs)_runAsMap.get(className);
59 }
60
61 public void setRunAs(Object o, SecurityHandler securityHandler)
62 throws ServletException
63 {
64 if (o==null)
65 return;
66
67 if (!(o instanceof ServletHolder))
68 return;
69
70 ServletHolder holder = (ServletHolder)o;
71
72 String className = holder.getClassName();
73 RunAs runAs = (RunAs)_runAsMap.get(className);
74 if (runAs == null)
75 return;
76
77 runAs.setRunAs(holder, securityHandler);
78 }
79
80 }