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