View Javadoc

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