Beispiel #1
0
  public Object getAttribute(String name) {
    if (name.startsWith("org.apache.tomcat")) {
      // XXX XXX XXX XXX Security - servlets may get too much access !!!
      // right now we don't check because we need JspServlet to
      // be able to access classloader and classpath

      if (name.equals("org.apache.tomcat.jsp_classpath")) {
        String cp = getServletLoader().getClassPath();
        return cp;
      }
      if (name.equals("org.apache.tomcat.protection_domain")) {
        return getProtectionDomain();
      }
      if (name.equals("org.apache.tomcat.classloader")) {
        return this.getServletLoader().getClassLoader();
      }
      if (name.equals(FacadeManager.FACADE_ATTRIBUTE)) {
        if (!allowAttribute(name)) return null;
        return this.getFacadeManager();
      }
      return null; // org.apache.tomcat namespace is reserved in tomcat
    } else {
      Object o = attributes.get(name);
      return attributes.get(name);
    }
  }
Beispiel #2
0
 /**
  * Add a servlet with the given name to the container. The servlet will be loaded by the
  * container's class loader and instantiated using the given class name.
  *
  * <p>Called to add a new servlet from web.xml
  */
 public void addServlet(ServletWrapper wrapper) throws TomcatException {
   wrapper.setContext(this);
   String name = wrapper.getServletName();
   //	System.out.println("Adding servlet " + name  + " " + wrapper);
   // check for duplicates
   if (servlets.get(name) != null) {
     log("Removing duplicate servlet " + name + " " + wrapper);
     removeServletByName(name);
     //	    getServletByName(name).destroy();
   }
   servlets.put(name, wrapper);
 }
Beispiel #3
0
  /**
   * Maps a named servlet to a particular path or extension. If the named servlet is unregistered,
   * it will be added and subsequently mapped.
   *
   * <p>Note that the order of resolution to handle a request is:
   *
   * <p>exact mapped servlet (eg /catalog) prefix mapped servlets (eg /foo/bar/*) extension mapped
   * servlets (eg *jsp) default servlet
   */
  public void addServletMapping(String path, String servletName) throws TomcatException {
    if (mappings.get(path) != null) {
      log("Removing duplicate " + path + " -> " + mappings.get(path));
      mappings.remove(path);
      Container ct = (Container) containers.get(path);
      removeContainer(ct);
    }
    ServletWrapper sw = (ServletWrapper) servlets.get(servletName);
    if (sw == null) {
      // Workaround for frequent "bug" in web.xmls
      // Declare a default mapping
      log("Mapping with unregistered servlet " + servletName);
      sw = addServlet(servletName, servletName);
    }
    if ("/".equals(path)) defaultServlet = sw;

    mappings.put(path, sw);

    Container map = new Container();
    map.setContext(this);
    map.setHandler(sw);
    map.setPath(path);
    contextM.addContainer(map);
    containers.put(path, map);
  }
Beispiel #4
0
  /**
   * Will add a new security constraint: For all paths: if( match(path) && match(method) && match(
   * transport ) ) then require("roles")
   *
   * <p>This is equivalent with adding a Container with the path, method and transport. If the
   * container will be matched, the request will have to pass the security constraints.
   */
  public void addSecurityConstraint(
      String path[], String methods[], String roles[], String transport) throws TomcatException {
    for (int i = 0; i < path.length; i++) {
      Container ct = new Container();
      ct.setContext(this);
      ct.setTransport(transport);
      ct.setRoles(roles);
      ct.setPath(path[i]);
      ct.setMethods(methods);

      // XXX check if exists, merge if true.
      constraints.put(path[i], ct);
      // contextM.addSecurityConstraint( this, path[i], ct);
      contextM.addContainer(ct);
    }
  }
Beispiel #5
0
 public Enumeration getTaglibs() {
   return tagLibs.keys();
 }
Beispiel #6
0
 public void addInitParameter(String name, String value) {
   initializationParameters.put(name, value);
 }
Beispiel #7
0
 public void removeAttribute(String name) {
   attributes.remove(name);
 }
Beispiel #8
0
 public String getErrorPage(String errorCode) {
   return (String) errorPages.get(errorCode);
 }
Beispiel #9
0
 /** Add Env-entry to this context */
 public void addEnvEntry(String name, String type, String value, String description) {
   System.out.println("Add env-entry " + name + "  " + type + " " + value + " " + description);
   if (name == null || type == null) throw new IllegalArgumentException();
   envEntryTypes.put(name, type);
   if (value != null) envEntryValues.put(name, value);
 }
Beispiel #10
0
 public String getTaglibLocation(String uri) {
   return (String) tagLibs.get(uri);
 }
Beispiel #11
0
 public Container getContainer(String path) {
   return (Container) containers.get(path);
 }
Beispiel #12
0
 /** Remove the servlet with a specific name */
 public void removeServletByName(String servletName) throws TomcatException {
   servlets.remove(servletName);
 }
Beispiel #13
0
 public Enumeration getContainers() {
   return containers.elements();
 }
Beispiel #14
0
 public String getInitParameter(String name) {
   return (String) initializationParameters.get(name);
 }
Beispiel #15
0
 public Enumeration getEnvEntries() {
   return envEntryTypes.keys();
 }
Beispiel #16
0
 public String getEnvEntryValue(String name) {
   return (String) envEntryValues.get(name);
 }
Beispiel #17
0
 public String getEnvEntryType(String name) {
   return (String) envEntryTypes.get(name);
 }
Beispiel #18
0
 public Enumeration getContainerLocations() {
   return containers.keys();
 }
Beispiel #19
0
 public Enumeration getInitParameterNames() {
   return initializationParameters.keys();
 }
Beispiel #20
0
 public void removeContainer(Container ct) {
   containers.remove(ct.getPath());
 }
Beispiel #21
0
 public Enumeration getAttributeNames() {
   return attributes.keys();
 }
Beispiel #22
0
 public ServletWrapper getServletByName(String servletName) {
   return (ServletWrapper) servlets.get(servletName);
 }
Beispiel #23
0
 public void setAttribute(String name, Object object) {
   attributes.put(name, object);
 }
Beispiel #24
0
 public Enumeration getServletNames() {
   return servlets.keys();
 }
Beispiel #25
0
 /** Add a taglib declaration for this context */
 public void addTaglib(String uri, String location) {
   //	System.out.println("Add taglib " + uri + "  " + location );
   tagLibs.put(uri, location);
 }