Exemple #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);
    }
  }
Exemple #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);
 }
Exemple #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);
  }
Exemple #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);
    }
  }
Exemple #5
0
 public Enumeration getTaglibs() {
   return tagLibs.keys();
 }
Exemple #6
0
 public void addInitParameter(String name, String value) {
   initializationParameters.put(name, value);
 }
Exemple #7
0
 public void removeAttribute(String name) {
   attributes.remove(name);
 }
Exemple #8
0
 public String getErrorPage(String errorCode) {
   return (String) errorPages.get(errorCode);
 }
Exemple #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);
 }
Exemple #10
0
 public String getTaglibLocation(String uri) {
   return (String) tagLibs.get(uri);
 }
Exemple #11
0
 public Container getContainer(String path) {
   return (Container) containers.get(path);
 }
Exemple #12
0
 /** Remove the servlet with a specific name */
 public void removeServletByName(String servletName) throws TomcatException {
   servlets.remove(servletName);
 }
Exemple #13
0
 public Enumeration getContainers() {
   return containers.elements();
 }
Exemple #14
0
 public String getInitParameter(String name) {
   return (String) initializationParameters.get(name);
 }
Exemple #15
0
 public Enumeration getEnvEntries() {
   return envEntryTypes.keys();
 }
Exemple #16
0
 public String getEnvEntryValue(String name) {
   return (String) envEntryValues.get(name);
 }
Exemple #17
0
 public String getEnvEntryType(String name) {
   return (String) envEntryTypes.get(name);
 }
Exemple #18
0
 public Enumeration getContainerLocations() {
   return containers.keys();
 }
Exemple #19
0
 public Enumeration getInitParameterNames() {
   return initializationParameters.keys();
 }
Exemple #20
0
 public void removeContainer(Container ct) {
   containers.remove(ct.getPath());
 }
Exemple #21
0
 public Enumeration getAttributeNames() {
   return attributes.keys();
 }
Exemple #22
0
 public ServletWrapper getServletByName(String servletName) {
   return (ServletWrapper) servlets.get(servletName);
 }
Exemple #23
0
 public void setAttribute(String name, Object object) {
   attributes.put(name, object);
 }
Exemple #24
0
 public Enumeration getServletNames() {
   return servlets.keys();
 }
Exemple #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);
 }