1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.annotations;
20
21 import javax.annotation.security.DeclareRoles;
22 import javax.servlet.Servlet;
23
24 import org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler;
25 import org.eclipse.jetty.security.ConstraintSecurityHandler;
26 import org.eclipse.jetty.webapp.WebAppContext;
27
28
29
30
31
32
33 public class DeclareRolesAnnotationHandler extends AbstractIntrospectableAnnotationHandler
34 {
35
36 protected WebAppContext _context;
37
38
39
40
41 public DeclareRolesAnnotationHandler(WebAppContext context)
42 {
43 super(false);
44 _context = context;
45 }
46
47
48
49
50
51 public void doHandle(Class clazz)
52 {
53 if (!Servlet.class.isAssignableFrom(clazz))
54 return;
55
56 DeclareRoles declareRoles = (DeclareRoles) clazz.getAnnotation(DeclareRoles.class);
57 if (declareRoles == null)
58 return;
59
60 String[] roles = declareRoles.value();
61
62 if (roles != null && roles.length > 0)
63 {
64 for (String r:roles)
65 ((ConstraintSecurityHandler)_context.getSecurityHandler()).addRole(r);
66 }
67 }
68
69 }