View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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 org.eclipse.jetty.servlet.ServletHolder;
22  
23  /**
24   * RunAs
25   * <p/>
26   * Represents a &lt;run-as&gt; element in web.xml, or a runAs annotation.
27   */
28  public class RunAs
29  {
30      private String _className;
31      private String _roleName;
32  
33      public RunAs()
34      {}
35  
36  
37      public void setTargetClassName (String className)
38      {
39          _className = className;
40      }
41      
42      public String getTargetClassName()
43      {
44          return _className;
45      }
46  
47      public void setRoleName (String roleName)
48      {
49          _roleName = roleName;
50      }
51  
52      public String getRoleName ()
53      {
54          return _roleName;
55      }
56  
57  
58      /**
59       * @param holder
60       */
61      public void setRunAs (ServletHolder holder)
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  }