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