1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.annotations;
15
16 import java.util.List;
17
18 import org.eclipse.jetty.annotations.AnnotationParser.AnnotationHandler;
19 import org.eclipse.jetty.annotations.AnnotationParser.Value;
20 import org.eclipse.jetty.plus.annotation.RunAsCollection;
21 import org.eclipse.jetty.util.log.Log;
22 import org.eclipse.jetty.webapp.WebAppContext;
23
24 public class RunAsAnnotationHandler implements AnnotationHandler
25 {
26 protected WebAppContext _wac;
27
28 public RunAsAnnotationHandler (WebAppContext wac)
29 {
30 _wac = wac;
31 }
32
33 public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
34 List<Value> values)
35 {
36 RunAsCollection runAsCollection = (RunAsCollection)_wac.getAttribute(RunAsCollection.RUNAS_COLLECTION);
37
38 try
39 {
40 if (values != null && values.size() == 1)
41 {
42 String role = (String)values.get(0).getValue();
43 if (role != null)
44 {
45 org.eclipse.jetty.plus.annotation.RunAs ra = new org.eclipse.jetty.plus.annotation.RunAs();
46 ra.setTargetClassName(className);
47 ra.setRoleName(role);
48 runAsCollection.add(ra);
49 }
50 }
51 else
52 Log.warn("Bad value for @RunAs annotation on class "+className);
53 }
54 catch (Exception e)
55 {
56 Log.warn(e);
57 }
58
59 }
60
61 public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
62 List<Value> values)
63 {
64 Log.warn ("@RunAs annotation not applicable for fields: "+className+"."+fieldName);
65 }
66
67 public void handleMethod(String className, String methodName, int access, String params, String signature, String[] exceptions, String annotation,
68 List<Value> values)
69 {
70 Log.warn("@RunAs annotation ignored on method: "+className+"."+methodName+" "+signature);
71 }
72
73 }