Esempio n. 1
0
  /**
   * Create an <code>ObjectName</code> for this <code>Manager</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param manager The Manager to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, Manager manager)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = manager.getContainer();

    if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=Manager");
    } else if (container instanceof Host) {
      name = new ObjectName(domain + ":type=Manager,host=" + container.getName());
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      name = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + host.getName());
    } else if (container == null) {
      DefaultContext defaultContext = manager.getDefaultContext();
      if (defaultContext != null) {
        Container parent = defaultContext.getParent();
        if (parent instanceof Engine) {
          name = new ObjectName(domain + ":type=DefaultManager");
        } else if (parent instanceof Host) {
          name = new ObjectName(domain + ":type=DefaultManager,host=" + parent.getName());
        }
      }
    }

    return (name);
  }
Esempio n. 2
0
  /** Register this Manager with JMX. */
  protected void registerManagerMBean() {
    try {
      MBeanServer server = getMBeanServer();

      String domain;
      if (container_ instanceof ContainerBase) {
        domain = ((ContainerBase) container_).getDomain();
      } else {
        domain = server.getDefaultDomain();
      }
      String hostName = ((Host) container_.getParent()).getName();
      hostName = (hostName == null) ? "localhost" : hostName;
      ObjectName clusterName =
          new ObjectName(
              domain
                  + ":type=Manager,host="
                  + hostName
                  + ",path="
                  + ((Context) container_).getPath());

      if (server.isRegistered(clusterName)) {
        log_.warn("MBean " + clusterName + " already registered");
        return;
      }

      objectName_ = clusterName;
      server.registerMBean(this, clusterName);

    } catch (Exception ex) {
      log_.error("Could not register " + getClass().getSimpleName() + " to MBeanServer", ex);
    }
  }
Esempio n. 3
0
  @Override
  public String getMBeanKeyProperties() {
    Container c = this;
    StringBuilder keyProperties = new StringBuilder();
    int containerCount = 0;

    // Work up container hierarchy, add a component to the name for
    // each container
    while (!(c instanceof Engine)) {
      if (c instanceof Context) {
        keyProperties.append(",context=");
        ContextName cn = new ContextName(c.getName(), false);
        keyProperties.append(cn.getDisplayName());
      } else if (c instanceof Host) {
        keyProperties.append(",host=");
        keyProperties.append(c.getName());
      } else if (c == null) {
        // May happen in unit testing and/or some embedding scenarios
        keyProperties.append(",container");
        keyProperties.append(containerCount++);
        keyProperties.append("=null");
        break;
      } else {
        // Should never happen...
        keyProperties.append(",container");
        keyProperties.append(containerCount++);
        keyProperties.append('=');
        keyProperties.append(c.getName());
      }
      c = c.getParent();
    }
    return keyProperties.toString();
  }
 /**
  * Return the Server object that is the ultimate parent for the container with which this Realm is
  * associated. If the server cannot be found (eg because the container hierarchy is not complete),
  * <code>null</code> is returned.
  */
 protected Server getServer() {
   Container c = container;
   if (c instanceof Context) {
     c = c.getParent();
   }
   if (c instanceof Host) {
     c = c.getParent();
   }
   if (c instanceof Engine) {
     Service s = ((Engine) c).getService();
     if (s != null) {
       return s.getServer();
     }
   }
   return null;
 }
Esempio n. 5
0
 /**
  * Retrieve the enclosing Engine for this Manager.
  *
  * @return an Engine object (or null).
  */
 public Engine getEngine() {
   Engine e = null;
   for (Container c = getContainer(); e == null && c != null; c = c.getParent()) {
     if (c != null && c instanceof Engine) {
       e = (Engine) c;
     }
   }
   return e;
 }
Esempio n. 6
0
  /** Return the name for this instance (built from container name) */
  public String getName() {
    if (name == null) {
      Container container = manager.getContainer();
      String contextName = container.getName();
      String hostName = "";
      String engineName = "";

      if (container.getParent() != null) {
        Container host = container.getParent();
        hostName = host.getName();
        if (host.getParent() != null) {
          engineName = host.getParent().getName();
        }
      }
      name = "/" + engineName + "/" + hostName + contextName;
    }
    return name;
  }
  /**
   * Prepare for the beginning of active use of the public methods of this component. This method
   * should be called after <code>configure()</code>, and before any of the public methods of the
   * component are utilized.
   *
   * @exception LifecycleException if this component detects a fatal error that prevents this
   *     component from being used
   */
  public void start() throws LifecycleException {

    // Validate and update our current component state
    if (started) throw new LifecycleException(sm.getString("authenticator.alreadyStarted"));
    lifecycle.fireLifecycleEvent(START_EVENT, null);
    if ("org.apache.catalina.core.StandardContext".equals(context.getClass().getName())) {
      try {
        Class paramTypes[] = new Class[0];
        Object paramValues[] = new Object[0];
        Method method = context.getClass().getMethod("getDebug", paramTypes);
        Integer result = (Integer) method.invoke(context, paramValues);
        setDebug(result.intValue());
      } catch (Exception e) {
        log("Exception getting debug value", e);
      }
    }
    started = true;

    // Look up the SingleSignOn implementation in our request processing
    // path, if there is one
    Container parent = context.getParent();
    while ((sso == null) && (parent != null)) {
      if (!(parent instanceof Pipeline)) {
        parent = parent.getParent();
        continue;
      }
      Valve valves[] = ((Pipeline) parent).getValves();
      for (int i = 0; i < valves.length; i++) {
        if (valves[i] instanceof SingleSignOn) {
          sso = (SingleSignOn) valves[i];
          break;
        }
      }
      if (sso == null) parent = parent.getParent();
    }
    if (debug >= 1) {
      if (sso != null) log("Found SingleSignOn Valve at " + sso);
      else log("No SingleSignOn Valve is present");
    }
  }
Esempio n. 8
0
  /**
   * Create an <code>ObjectName</code> for this <code>Valve</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param valve The Valve to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, GlassFishValve valve)
      throws MalformedObjectNameException {
    if (valve instanceof ValveBase) {
      ObjectName name = ((ValveBase) valve).getObjectName();
      if (name != null) return name;
    }

    ObjectName name = null;
    Container container = null;
    String className = valve.getClass().getName();
    int period = className.lastIndexOf('.');
    if (period >= 0) className = className.substring(period + 1);
    if (valve instanceof Contained) {
      container = ((Contained) valve).getContainer();
    }
    if (container == null) {
      throw new MalformedObjectNameException(
          "Cannot create mbean for non-contained valve " + valve);
    }
    if (container instanceof Engine) {
      String local = "";
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    } else if (container instanceof Host) {
      String local = ",host=" + container.getName();
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      String local = ",path=" + path + ",host=" + host.getName();
      int seq = getSeq(local);
      String ext = "";
      if (seq > 0) {
        ext = ",seq=" + seq;
      }
      name = new ObjectName(domain + ":type=Valve,name=" + className + ext + local);
    }

    return (name);
  }
Esempio n. 9
0
  /**
   * Create an <code>ObjectName</code> for this <code>Realm</code> object.
   *
   * @param domain Domain in which this name is to be created
   * @param realm The Realm to be named
   * @exception MalformedObjectNameException if a name cannot be created
   */
  static ObjectName createObjectName(String domain, Realm realm)
      throws MalformedObjectNameException {

    ObjectName name = null;
    Container container = realm.getContainer();

    if (container instanceof Engine) {
      name = new ObjectName(domain + ":type=Realm");
    } else if (container instanceof Host) {
      name = new ObjectName(domain + ":type=Realm,host=" + container.getName());
    } else if (container instanceof Context) {
      String path = ((Context) container).getPath();
      if (path.length() < 1) {
        path = "/";
      }
      Host host = (Host) container.getParent();
      name = new ObjectName(domain + ":type=Realm,path=" + path + ",host=" + host.getName());
    }

    return (name);
  }
Esempio n. 10
0
 private File getConfigBase() {
   File configBase = new File(System.getProperty("catalina.base"), "conf");
   Container container = context;
   Container host = null;
   Container engine = null;
   while (container != null) {
     if (container instanceof Host) {
       host = container;
     }
     if (container instanceof Engine) {
       engine = container;
     }
     container = container.getParent();
   }
   if (engine != null) {
     configBase = new File(configBase, engine.getName());
   }
   if (host != null) {
     configBase = new File(configBase, host.getName());
   }
   return configBase;
 }