View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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 <code>&lt;run-as&gt;</code> element in web.xml, or a <code>&#064;RunAs</code> 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      public void setRunAs (ServletHolder holder)
58      {
59          if (holder == null)
60              return;
61          String className = holder.getClassName();
62  
63          if (className.equals(_className))
64          {
65              //Only set the RunAs if it has not already been set, presumably by web/web-fragment.xml
66              if (holder.getRegistration().getRunAsRole() == null)
67                  holder.getRegistration().setRunAsRole(_roleName);
68          }
69      }
70  }