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