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