1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.plus.annotation;
20
21 import javax.servlet.ServletException;
22
23 import org.eclipse.jetty.servlet.ServletHolder;
24
25 /**
26 * RunAs
27 * <p/>
28 * Represents a <run-as> element in web.xml, or a runAs annotation.
29 */
30 public class RunAs
31 {
32 private String _className;
33 private String _roleName;
34
35 public RunAs()
36 {}
37
38
39 public void setTargetClassName (String className)
40 {
41 _className = className;
42 }
43
44 public String getTargetClassName()
45 {
46 return _className;
47 }
48
49 public void setRoleName (String roleName)
50 {
51 _roleName = roleName;
52 }
53
54 public String getRoleName ()
55 {
56 return _roleName;
57 }
58
59
60 public void setRunAs (ServletHolder holder)
61 throws ServletException
62 {
63 if (holder == null)
64 return;
65 String className = holder.getClassName();
66
67 if (className.equals(_className))
68 {
69 //Only set the RunAs if it has not already been set, presumably by web/web-fragment.xml
70 if (holder.getRegistration().getRunAsRole() == null)
71 holder.getRegistration().setRunAsRole(_roleName);
72 }
73
74 }
75 }