init
This commit is contained in:
47
java/org/apache/catalina/mbeans/BaseCatalinaMBean.java
Normal file
47
java/org/apache/catalina/mbeans/BaseCatalinaMBean.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
import javax.management.modelmbean.InvalidTargetObjectTypeException;
|
||||
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
|
||||
public abstract class BaseCatalinaMBean<T> extends BaseModelMBean {
|
||||
|
||||
protected T doGetManagedResource() throws MBeanException {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
T resource = (T) getManagedResource();
|
||||
return resource;
|
||||
} catch (InstanceNotFoundException | RuntimeOperationsException |
|
||||
InvalidTargetObjectTypeException e) {
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static Object newInstance(String type) throws MBeanException {
|
||||
try {
|
||||
return Class.forName(type).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
java/org/apache/catalina/mbeans/ClassNameMBean.java
Normal file
42
java/org/apache/catalina/mbeans/ClassNameMBean.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
/**
|
||||
* <p>A convenience base class for <strong>ModelMBean</strong> implementations
|
||||
* where the underlying base class (and therefore the set of supported
|
||||
* properties) is different for varying implementations of a standard
|
||||
* interface. For Catalina, that includes at least the following:
|
||||
* Connector, Logger, Realm, and Valve. This class creates an artificial
|
||||
* MBean attribute named <code>className</code>, which reports the fully
|
||||
* qualified class name of the managed object as its value.</p>
|
||||
*
|
||||
* @param <T> The type that this bean represents.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class ClassNameMBean<T> extends BaseCatalinaMBean<T> {
|
||||
|
||||
/**
|
||||
* Return the fully qualified Java class name of the managed object
|
||||
* for this MBean.
|
||||
*/
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return this.resource.getClass().getName();
|
||||
}
|
||||
}
|
||||
97
java/org/apache/catalina/mbeans/ConnectorMBean.java
Normal file
97
java/org/apache/catalina/mbeans/ConnectorMBean.java
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.ReflectionException;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.tomcat.util.IntrospectionUtils;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.coyote.tomcat5.CoyoteConnector</code> component.</p>
|
||||
*
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class ConnectorMBean extends ClassNameMBean<Connector> {
|
||||
|
||||
/**
|
||||
* Obtain and return the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param name Name of the requested attribute
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
Connector connector = doGetManagedResource();
|
||||
return IntrospectionUtils.getProperty(connector, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param attribute The identification of the attribute to be set
|
||||
* and the new value
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (attribute == null) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException(
|
||||
"Attribute is null"), "Attribute is null");
|
||||
}
|
||||
String name = attribute.getName();
|
||||
Object value = attribute.getValue();
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
Connector connector = doGetManagedResource();
|
||||
IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
219
java/org/apache/catalina/mbeans/ContainerMBean.java
Normal file
219
java/org/apache/catalina/mbeans/ContainerMBean.java
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Container;
|
||||
import org.apache.catalina.ContainerListener;
|
||||
import org.apache.catalina.JmxEnabled;
|
||||
import org.apache.catalina.LifecycleException;
|
||||
import org.apache.catalina.LifecycleListener;
|
||||
import org.apache.catalina.Valve;
|
||||
import org.apache.catalina.core.ContainerBase;
|
||||
import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.catalina.core.StandardHost;
|
||||
import org.apache.catalina.startup.ContextConfig;
|
||||
import org.apache.catalina.startup.HostConfig;
|
||||
|
||||
public class ContainerMBean extends BaseCatalinaMBean<ContainerBase> {
|
||||
|
||||
/**
|
||||
* Add a new child Container to those associated with this Container,
|
||||
* if supported. Won't start the child yet. Has to be started with a call to
|
||||
* Start method after necessary configurations are done.
|
||||
*
|
||||
* @param type ClassName of the child to be added
|
||||
* @param name Name of the child to be added
|
||||
*
|
||||
* @exception MBeanException if the child cannot be added
|
||||
*/
|
||||
public void addChild(String type, String name) throws MBeanException{
|
||||
|
||||
Container contained = (Container) newInstance(type);
|
||||
contained.setName(name);
|
||||
|
||||
if(contained instanceof StandardHost){
|
||||
HostConfig config = new HostConfig();
|
||||
contained.addLifecycleListener(config);
|
||||
} else if(contained instanceof StandardContext){
|
||||
ContextConfig config = new ContextConfig();
|
||||
contained.addLifecycleListener(config);
|
||||
}
|
||||
|
||||
boolean oldValue= true;
|
||||
|
||||
ContainerBase container = doGetManagedResource();
|
||||
try {
|
||||
oldValue = container.getStartChildren();
|
||||
container.setStartChildren(false);
|
||||
container.addChild(contained);
|
||||
contained.init();
|
||||
} catch (LifecycleException e){
|
||||
throw new MBeanException(e);
|
||||
} finally {
|
||||
if(container != null) {
|
||||
container.setStartChildren(oldValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing child Container from association with this parent
|
||||
* Container.
|
||||
*
|
||||
* @param name Name of the existing child Container to be removed
|
||||
* @throws MBeanException if the child cannot be removed
|
||||
*/
|
||||
public void removeChild(String name) throws MBeanException{
|
||||
if (name != null) {
|
||||
Container container = doGetManagedResource();
|
||||
Container contained = container.findChild(name);
|
||||
container.removeChild(contained);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a valve to this Container instance.
|
||||
*
|
||||
* @param valveType ClassName of the valve to be added
|
||||
* @return the MBean name of the new valve
|
||||
* @throws MBeanException if adding the valve failed
|
||||
*/
|
||||
public String addValve(String valveType) throws MBeanException{
|
||||
Valve valve = (Valve) newInstance(valveType);
|
||||
|
||||
Container container = doGetManagedResource();
|
||||
container.getPipeline().addValve(valve);
|
||||
|
||||
if (valve instanceof JmxEnabled) {
|
||||
return ((JmxEnabled)valve).getObjectName().toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Valve.
|
||||
*
|
||||
* @param valveName MBean Name of the Valve to remove
|
||||
*
|
||||
* @exception MBeanException if a component cannot be removed
|
||||
*/
|
||||
public void removeValve(String valveName) throws MBeanException{
|
||||
Container container = doGetManagedResource();
|
||||
|
||||
ObjectName oname;
|
||||
try {
|
||||
oname = new ObjectName(valveName);
|
||||
} catch (MalformedObjectNameException e) {
|
||||
throw new MBeanException(e);
|
||||
} catch (NullPointerException e) {
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
|
||||
if (container != null) {
|
||||
Valve[] valves = container.getPipeline().getValves();
|
||||
for (int i = 0; i < valves.length; i++) {
|
||||
if (valves[i] instanceof JmxEnabled) {
|
||||
ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
|
||||
if (voname.equals(oname)) {
|
||||
container.getPipeline().removeValve(valves[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a LifecycleEvent listener to this component.
|
||||
*
|
||||
* @param type ClassName of the listener to add
|
||||
* @throws MBeanException if adding the listener failed
|
||||
*/
|
||||
public void addLifecycleListener(String type) throws MBeanException{
|
||||
LifecycleListener listener = (LifecycleListener) newInstance(type);
|
||||
Container container = doGetManagedResource();
|
||||
container.addLifecycleListener(listener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a LifecycleEvent listeners from this component.
|
||||
*
|
||||
* @param type The ClassName of the listeners to be removed.
|
||||
* Note that all the listeners having given ClassName will be removed.
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public void removeLifecycleListeners(String type) throws MBeanException{
|
||||
Container container = doGetManagedResource();
|
||||
|
||||
LifecycleListener[] listeners = container.findLifecycleListeners();
|
||||
for (LifecycleListener listener : listeners){
|
||||
if (listener.getClass().getName().equals(type)) {
|
||||
container.removeLifecycleListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List the class name of each of the lifecycle listeners added to this
|
||||
* container.
|
||||
* @return the lifecycle listeners class names
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findLifecycleListenerNames() throws MBeanException {
|
||||
Container container = doGetManagedResource();
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
LifecycleListener[] listeners = container.findLifecycleListeners();
|
||||
for(LifecycleListener listener: listeners){
|
||||
result.add(listener.getClass().getName());
|
||||
}
|
||||
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List the class name of each of the container listeners added to this
|
||||
* container.
|
||||
* @return the container listeners class names
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findContainerListenerNames() throws MBeanException {
|
||||
Container container = doGetManagedResource();
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
ContainerListener[] listeners = container.findContainerListeners();
|
||||
for(ContainerListener listener: listeners){
|
||||
result.add(listener.getClass().getName());
|
||||
}
|
||||
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
}
|
||||
63
java/org/apache/catalina/mbeans/ContextEnvironmentMBean.java
Normal file
63
java/org/apache/catalina/mbeans/ContextEnvironmentMBean.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.ReflectionException;
|
||||
|
||||
import org.apache.tomcat.util.descriptor.web.ContextEnvironment;
|
||||
import org.apache.tomcat.util.descriptor.web.NamingResources;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.tomcat.util.descriptor.web.ContextEnvironment</code> component.</p>
|
||||
*
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class ContextEnvironmentMBean extends BaseCatalinaMBean<ContextEnvironment> {
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param attribute The identification of the attribute to be set
|
||||
* and the new value
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
super.setAttribute(attribute);
|
||||
|
||||
ContextEnvironment ce = doGetManagedResource();
|
||||
|
||||
// cannot use side-effects. It's removed and added back each time
|
||||
// there is a modification in a resource.
|
||||
NamingResources nr = ce.getNamingResources();
|
||||
nr.removeEnvironment(ce.getName());
|
||||
nr.addEnvironment(ce);
|
||||
}
|
||||
}
|
||||
189
java/org/apache/catalina/mbeans/ContextMBean.java
Normal file
189
java/org/apache/catalina/mbeans/ContextMBean.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.MBeanException;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.tomcat.util.descriptor.web.ApplicationParameter;
|
||||
import org.apache.tomcat.util.descriptor.web.ErrorPage;
|
||||
import org.apache.tomcat.util.descriptor.web.FilterDef;
|
||||
import org.apache.tomcat.util.descriptor.web.FilterMap;
|
||||
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
|
||||
|
||||
public class ContextMBean extends BaseCatalinaMBean<Context> {
|
||||
|
||||
/**
|
||||
* Return the set of application parameters for this application.
|
||||
* @return a string array with a representation of each parameter
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findApplicationParameters() throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
ApplicationParameter[] params = context.findApplicationParameters();
|
||||
String[] stringParams = new String[params.length];
|
||||
for (int counter = 0; counter < params.length; counter++) {
|
||||
stringParams[counter] = params[counter].toString();
|
||||
}
|
||||
|
||||
return stringParams;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the security constraints for this web application.
|
||||
* If there are none, a zero-length array is returned.
|
||||
* @return a string array with a representation of each
|
||||
* security constraint
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findConstraints() throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
SecurityConstraint[] constraints = context.findConstraints();
|
||||
String[] stringConstraints = new String[constraints.length];
|
||||
for (int counter = 0; counter < constraints.length; counter++) {
|
||||
stringConstraints[counter] = constraints[counter].toString();
|
||||
}
|
||||
|
||||
return stringConstraints;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the error page entry for the specified HTTP error code,
|
||||
* if any; otherwise return <code>null</code>.
|
||||
*
|
||||
* @param errorCode Error code to look up
|
||||
* @return a string representation of the error page
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String findErrorPage(int errorCode) throws MBeanException {
|
||||
Context context = doGetManagedResource();
|
||||
return context.findErrorPage(errorCode).toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the error page entry for the specified Java exception type,
|
||||
* if any; otherwise return <code>null</code>.
|
||||
*
|
||||
* @param exceptionType Exception type to look up
|
||||
* @return a string representation of the error page
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
* @deprecated Unused. Will be removed in Tomcat 10.
|
||||
* Use {@link #findErrorPage(Throwable)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public String findErrorPage(String exceptionType) throws MBeanException {
|
||||
Context context = doGetManagedResource();
|
||||
return context.findErrorPage(exceptionType).toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the error page entry for the specified Java exception type,
|
||||
* if any; otherwise return <code>null</code>.
|
||||
*
|
||||
* @param exceptionType Exception type to look up
|
||||
* @return a string representation of the error page
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String findErrorPage(Throwable exceptionType) throws MBeanException {
|
||||
Context context = doGetManagedResource();
|
||||
return context.findErrorPage(exceptionType).toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the set of defined error pages for all specified error codes
|
||||
* and exception types.
|
||||
* @return a string array with a representation of each error page
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findErrorPages() throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
ErrorPage[] pages = context.findErrorPages();
|
||||
String[] stringPages = new String[pages.length];
|
||||
for (int counter = 0; counter < pages.length; counter++) {
|
||||
stringPages[counter] = pages[counter].toString();
|
||||
}
|
||||
|
||||
return stringPages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the filter definition for the specified filter name, if any;
|
||||
* otherwise return <code>null</code>.
|
||||
*
|
||||
* @param name Filter name to look up
|
||||
* @return a string representation of the filter definition
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String findFilterDef(String name) throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
FilterDef filterDef = context.findFilterDef(name);
|
||||
return filterDef.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the set of defined filters for this Context.
|
||||
* @return a string array with a representation of all
|
||||
* the filter definitions
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findFilterDefs() throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
FilterDef[] filterDefs = context.findFilterDefs();
|
||||
String[] stringFilters = new String[filterDefs.length];
|
||||
for (int counter = 0; counter < filterDefs.length; counter++) {
|
||||
stringFilters[counter] = filterDefs[counter].toString();
|
||||
}
|
||||
|
||||
return stringFilters;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the set of filter mappings for this Context.
|
||||
* @return a string array with a representation of all the filter mappings
|
||||
* @throws MBeanException propagated from the managed resource access
|
||||
*/
|
||||
public String[] findFilterMaps() throws MBeanException {
|
||||
|
||||
Context context = doGetManagedResource();
|
||||
|
||||
FilterMap[] maps = context.findFilterMaps();
|
||||
String[] stringMaps = new String[maps.length];
|
||||
for (int counter = 0; counter < maps.length; counter++) {
|
||||
stringMaps[counter] = maps[counter].toString();
|
||||
}
|
||||
|
||||
return stringMaps;
|
||||
}
|
||||
}
|
||||
133
java/org/apache/catalina/mbeans/ContextResourceLinkMBean.java
Normal file
133
java/org/apache/catalina/mbeans/ContextResourceLinkMBean.java
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.ReflectionException;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResourceLink;
|
||||
import org.apache.tomcat.util.descriptor.web.NamingResources;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.tomcat.util.descriptor.web.ContextResourceLink</code> component.</p>
|
||||
*
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class ContextResourceLinkMBean extends BaseCatalinaMBean<ContextResourceLink> {
|
||||
|
||||
/**
|
||||
* Obtain and return the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param name Name of the requested attribute
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
ContextResourceLink cl = doGetManagedResource();
|
||||
|
||||
String value = null;
|
||||
if ("global".equals(name)) {
|
||||
return cl.getGlobal();
|
||||
} else if ("description".equals(name)) {
|
||||
return cl.getDescription();
|
||||
} else if ("name".equals(name)) {
|
||||
return cl.getName();
|
||||
} else if ("type".equals(name)) {
|
||||
return cl.getType();
|
||||
} else {
|
||||
value = (String) cl.getProperty(name);
|
||||
if (value == null) {
|
||||
throw new AttributeNotFoundException("Cannot find attribute [" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param attribute The identification of the attribute to be set
|
||||
* and the new value
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (attribute == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute is null"),
|
||||
"Attribute is null");
|
||||
}
|
||||
|
||||
String name = attribute.getName();
|
||||
Object value = attribute.getValue();
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
ContextResourceLink crl = doGetManagedResource();
|
||||
|
||||
if ("global".equals(name)) {
|
||||
crl.setGlobal((String) value);
|
||||
} else if ("description".equals(name)) {
|
||||
crl.setDescription((String) value);
|
||||
} else if ("name".equals(name)) {
|
||||
crl.setName((String) value);
|
||||
} else if ("type".equals(name)) {
|
||||
crl.setType((String) value);
|
||||
} else {
|
||||
crl.setProperty(name, "" + value);
|
||||
}
|
||||
|
||||
// cannot use side-effects. It's removed and added back each time
|
||||
// there is a modification in a resource.
|
||||
NamingResources nr = crl.getNamingResources();
|
||||
nr.removeResourceLink(crl.getName());
|
||||
nr.addResourceLink(crl);
|
||||
}
|
||||
}
|
||||
137
java/org/apache/catalina/mbeans/ContextResourceMBean.java
Normal file
137
java/org/apache/catalina/mbeans/ContextResourceMBean.java
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.ReflectionException;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResource;
|
||||
import org.apache.tomcat.util.descriptor.web.NamingResources;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.tomcat.util.descriptor.web.ContextResource</code> component.</p>
|
||||
*
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class ContextResourceMBean extends BaseCatalinaMBean<ContextResource> {
|
||||
|
||||
/**
|
||||
* Obtain and return the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param name Name of the requested attribute
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
ContextResource cr = doGetManagedResource();
|
||||
|
||||
String value = null;
|
||||
if ("auth".equals(name)) {
|
||||
return cr.getAuth();
|
||||
} else if ("description".equals(name)) {
|
||||
return cr.getDescription();
|
||||
} else if ("name".equals(name)) {
|
||||
return cr.getName();
|
||||
} else if ("scope".equals(name)) {
|
||||
return cr.getScope();
|
||||
} else if ("type".equals(name)) {
|
||||
return cr.getType();
|
||||
} else {
|
||||
value = (String) cr.getProperty(name);
|
||||
if (value == null) {
|
||||
throw new AttributeNotFoundException
|
||||
("Cannot find attribute [" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the value of a specific attribute of this MBean.
|
||||
*
|
||||
* @param attribute The identification of the attribute to be set
|
||||
* and the new value
|
||||
*
|
||||
* @exception AttributeNotFoundException if this attribute is not
|
||||
* supported by this MBean
|
||||
* @exception MBeanException if the initializer of an object
|
||||
* throws an exception
|
||||
* @exception ReflectionException if a Java reflection exception
|
||||
* occurs when invoking the getter
|
||||
*/
|
||||
@Override
|
||||
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException,
|
||||
ReflectionException {
|
||||
|
||||
// Validate the input parameters
|
||||
if (attribute == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute is null"),
|
||||
"Attribute is null");
|
||||
}
|
||||
String name = attribute.getName();
|
||||
Object value = attribute.getValue();
|
||||
if (name == null) {
|
||||
throw new RuntimeOperationsException(
|
||||
new IllegalArgumentException("Attribute name is null"),
|
||||
"Attribute name is null");
|
||||
}
|
||||
|
||||
ContextResource cr = doGetManagedResource();
|
||||
|
||||
if ("auth".equals(name)) {
|
||||
cr.setAuth((String)value);
|
||||
} else if ("description".equals(name)) {
|
||||
cr.setDescription((String)value);
|
||||
} else if ("name".equals(name)) {
|
||||
cr.setName((String)value);
|
||||
} else if ("scope".equals(name)) {
|
||||
cr.setScope((String)value);
|
||||
} else if ("type".equals(name)) {
|
||||
cr.setType((String)value);
|
||||
} else {
|
||||
cr.setProperty(name, "" + value);
|
||||
}
|
||||
|
||||
// cannot use side-effects. It's removed and added back each time
|
||||
// there is a modification in a resource.
|
||||
NamingResources nr = cr.getNamingResources();
|
||||
nr.removeResource(cr.getName());
|
||||
nr.addResource(cr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.OperationNotSupportedException;
|
||||
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Lifecycle;
|
||||
import org.apache.catalina.LifecycleEvent;
|
||||
import org.apache.catalina.LifecycleListener;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.catalina.UserDatabase;
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of <code>LifecycleListener</code> that instantiates the
|
||||
* set of MBeans associated with global JNDI resources that are subject to
|
||||
* management.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class GlobalResourcesLifecycleListener implements LifecycleListener {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GlobalResourcesLifecycleListener.class);
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The owning Catalina component that we are attached to.
|
||||
*/
|
||||
protected Lifecycle component = null;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected static final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
// ---------------------------------------------- LifecycleListener Methods
|
||||
|
||||
/**
|
||||
* Primary entry point for startup and shutdown events.
|
||||
*
|
||||
* @param event The event that has occurred
|
||||
*/
|
||||
@Override
|
||||
public void lifecycleEvent(LifecycleEvent event) {
|
||||
|
||||
if (Lifecycle.START_EVENT.equals(event.getType())) {
|
||||
component = event.getLifecycle();
|
||||
createMBeans();
|
||||
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
|
||||
destroyMBeans();
|
||||
component = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------ Protected Methods
|
||||
|
||||
/**
|
||||
* Create the MBeans for the interesting global JNDI resources.
|
||||
*/
|
||||
protected void createMBeans() {
|
||||
// Look up our global naming context
|
||||
Context context = null;
|
||||
try {
|
||||
context = (Context) (new InitialContext()).lookup("java:/");
|
||||
} catch (NamingException e) {
|
||||
log.error("No global naming context defined for server");
|
||||
return;
|
||||
}
|
||||
|
||||
// Recurse through the defined global JNDI resources context
|
||||
try {
|
||||
createMBeans("", context);
|
||||
} catch (NamingException e) {
|
||||
log.error("Exception processing Global JNDI Resources", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the MBeans for the interesting global JNDI resources in
|
||||
* the specified naming context.
|
||||
*
|
||||
* @param prefix Prefix for complete object name paths
|
||||
* @param context Context to be scanned
|
||||
*
|
||||
* @exception NamingException if a JNDI exception occurs
|
||||
*/
|
||||
protected void createMBeans(String prefix, Context context) throws NamingException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating MBeans for Global JNDI Resources in Context '" +
|
||||
prefix + "'");
|
||||
}
|
||||
|
||||
try {
|
||||
NamingEnumeration<Binding> bindings = context.listBindings("");
|
||||
while (bindings.hasMore()) {
|
||||
Binding binding = bindings.next();
|
||||
String name = prefix + binding.getName();
|
||||
Object value = context.lookup(binding.getName());
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Checking resource " + name);
|
||||
}
|
||||
if (value instanceof Context) {
|
||||
createMBeans(name + "/", (Context) value);
|
||||
} else if (value instanceof UserDatabase) {
|
||||
try {
|
||||
createMBeans(name, (UserDatabase) value);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception creating UserDatabase MBeans for " + name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch( RuntimeException ex) {
|
||||
log.error("RuntimeException " + ex);
|
||||
} catch( OperationNotSupportedException ex) {
|
||||
log.error("Operation not supported " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the MBeans for the specified UserDatabase and its contents.
|
||||
*
|
||||
* @param name Complete resource name of this UserDatabase
|
||||
* @param database The UserDatabase to be processed
|
||||
*
|
||||
* @exception Exception if an exception occurs while creating MBeans
|
||||
*/
|
||||
protected void createMBeans(String name, UserDatabase database) throws Exception {
|
||||
|
||||
// Create the MBean for the UserDatabase itself
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Creating UserDatabase MBeans for resource " + name);
|
||||
log.debug("Database=" + database);
|
||||
}
|
||||
try {
|
||||
MBeanUtils.createMBean(database);
|
||||
} catch(Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot create UserDatabase MBean for resource " + name, e);
|
||||
}
|
||||
|
||||
// Create the MBeans for each defined Role
|
||||
Iterator<Role> roles = database.getRoles();
|
||||
while (roles.hasNext()) {
|
||||
Role role = roles.next();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Creating Role MBean for role " + role);
|
||||
}
|
||||
try {
|
||||
MBeanUtils.createMBean(role);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Cannot create Role MBean for role " + role, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the MBeans for each defined Group
|
||||
Iterator<Group> groups = database.getGroups();
|
||||
while (groups.hasNext()) {
|
||||
Group group = groups.next();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Creating Group MBean for group " + group);
|
||||
}
|
||||
try {
|
||||
MBeanUtils.createMBean(group);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot create Group MBean for group " + group, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the MBeans for each defined User
|
||||
Iterator<User> users = database.getUsers();
|
||||
while (users.hasNext()) {
|
||||
User user = users.next();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(" Creating User MBean for user " + user);
|
||||
}
|
||||
try {
|
||||
MBeanUtils.createMBean(user);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot create User MBean for user " + user, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Destroy the MBeans for the interesting global JNDI resources.
|
||||
*/
|
||||
protected void destroyMBeans() {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Destroying MBeans for Global JNDI Resources");
|
||||
}
|
||||
}
|
||||
}
|
||||
138
java/org/apache/catalina/mbeans/GroupMBean.java
Normal file
138
java/org/apache/catalina/mbeans/GroupMBean.java
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.catalina.Group</code> component.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class GroupMBean extends BaseModelMBean {
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing this MBean.
|
||||
*/
|
||||
protected final ManagedBean managed = registry.findManagedBean("Group");
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all authorized roles for this group.
|
||||
*/
|
||||
public String[] getRoles() {
|
||||
|
||||
Group group = (Group) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<Role> roles = group.getRoles();
|
||||
while (roles.hasNext()) {
|
||||
Role role = null;
|
||||
try {
|
||||
role = roles.next();
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), role);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for role " + role);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all users that are members of this group.
|
||||
*/
|
||||
public String[] getUsers() {
|
||||
|
||||
Group group = (Group) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<User> users = group.getUsers();
|
||||
while (users.hasNext()) {
|
||||
User user = null;
|
||||
try {
|
||||
user = users.next();
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for user " + user);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link Role} to those this group belongs to.
|
||||
*
|
||||
* @param rolename Role name of the new role
|
||||
*/
|
||||
public void addRole(String rolename) {
|
||||
|
||||
Group group = (Group) this.resource;
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
Role role = group.getUserDatabase().findRole(rolename);
|
||||
if (role == null) {
|
||||
throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
|
||||
}
|
||||
group.addRole(role);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a {@link Role} from those this group belongs to.
|
||||
*
|
||||
* @param rolename Role name of the old role
|
||||
*/
|
||||
public void removeRole(String rolename) {
|
||||
|
||||
Group group = (Group) this.resource;
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
Role role = group.getUserDatabase().findRole(rolename);
|
||||
if (role == null) {
|
||||
throw new IllegalArgumentException("Invalid role name [" + rolename + "]");
|
||||
}
|
||||
group.removeRole(role);
|
||||
}
|
||||
}
|
||||
547
java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java
Normal file
547
java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java
Normal file
@@ -0,0 +1,547 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.rmi.AccessException;
|
||||
import java.rmi.AlreadyBoundException;
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.server.RMIClientSocketFactory;
|
||||
import java.rmi.server.RMIServerSocketFactory;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.management.remote.JMXConnectorServer;
|
||||
import javax.management.remote.JMXServiceURL;
|
||||
import javax.management.remote.rmi.RMIConnectorServer;
|
||||
import javax.management.remote.rmi.RMIJRMPServerImpl;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
import javax.rmi.ssl.SslRMIClientSocketFactory;
|
||||
import javax.rmi.ssl.SslRMIServerSocketFactory;
|
||||
|
||||
import org.apache.catalina.Lifecycle;
|
||||
import org.apache.catalina.LifecycleEvent;
|
||||
import org.apache.catalina.LifecycleListener;
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.apache.tomcat.util.res.StringManager;
|
||||
|
||||
/**
|
||||
* This listener fixes the port used by JMX/RMI Server making things much
|
||||
* simpler if you need to connect jconsole or similar to a remote Tomcat
|
||||
* instance that is running behind a firewall. Only the ports are configured via
|
||||
* the listener. The remainder of the configuration is via the standard system
|
||||
* properties for configuring JMX.
|
||||
*
|
||||
* @deprecated The features provided by this listener are now available in the
|
||||
* remote JMX capability included with the JRE.
|
||||
* This listener will be removed in Tomcat 10 and may be removed
|
||||
* from Tomcat 8.5.x some time after 2020-12-31.
|
||||
*/
|
||||
@Deprecated
|
||||
public class JmxRemoteLifecycleListener implements LifecycleListener {
|
||||
|
||||
private static final Log log = LogFactory.getLog(JmxRemoteLifecycleListener.class);
|
||||
|
||||
protected static final StringManager sm =
|
||||
StringManager.getManager(JmxRemoteLifecycleListener.class);
|
||||
|
||||
protected String rmiBindAddress = null;
|
||||
protected int rmiRegistryPortPlatform = -1;
|
||||
protected int rmiServerPortPlatform = -1;
|
||||
protected boolean rmiRegistrySSL = true;
|
||||
protected boolean rmiServerSSL = true;
|
||||
protected String ciphers[] = null;
|
||||
protected String protocols[] = null;
|
||||
protected boolean clientAuth = true;
|
||||
protected boolean authenticate = true;
|
||||
protected String passwordFile = null;
|
||||
protected String loginModuleName = null;
|
||||
protected String accessFile = null;
|
||||
protected boolean useLocalPorts = false;
|
||||
|
||||
protected JMXConnectorServer csPlatform = null;
|
||||
|
||||
/**
|
||||
* Get the inet address on which the Platform RMI server is exported.
|
||||
* @return The textual representation of inet address
|
||||
*/
|
||||
public String getRmiBindAddress() {
|
||||
return rmiBindAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the inet address on which the Platform RMI server is exported.
|
||||
* @param theRmiBindAddress The textual representation of inet address
|
||||
*/
|
||||
public void setRmiBindAddress(String theRmiBindAddress) {
|
||||
rmiBindAddress = theRmiBindAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port on which the Platform RMI server is exported. This is the
|
||||
* port that is normally chosen by the RMI stack.
|
||||
* @return The port number
|
||||
*/
|
||||
public int getRmiServerPortPlatform() {
|
||||
return rmiServerPortPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the port on which the Platform RMI server is exported. This is the
|
||||
* port that is normally chosen by the RMI stack.
|
||||
* @param theRmiServerPortPlatform The port number
|
||||
*/
|
||||
public void setRmiServerPortPlatform(int theRmiServerPortPlatform) {
|
||||
rmiServerPortPlatform = theRmiServerPortPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the port on which the Platform RMI registry is exported.
|
||||
* @return The port number
|
||||
*/
|
||||
public int getRmiRegistryPortPlatform() {
|
||||
return rmiRegistryPortPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the port on which the Platform RMI registry is exported.
|
||||
* @param theRmiRegistryPortPlatform The port number
|
||||
*/
|
||||
public void setRmiRegistryPortPlatform(int theRmiRegistryPortPlatform) {
|
||||
rmiRegistryPortPlatform = theRmiRegistryPortPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag that indicates that local ports should be used for all
|
||||
* connections. If using SSH tunnels, or similar, this should be set to
|
||||
* true to ensure the RMI client uses the tunnel.
|
||||
* @return <code>true</code> if local ports should be used
|
||||
*/
|
||||
public boolean getUseLocalPorts() {
|
||||
return useLocalPorts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flag that indicates that local ports should be used for all
|
||||
* connections. If using SSH tunnels, or similar, this should be set to
|
||||
* true to ensure the RMI client uses the tunnel.
|
||||
* @param useLocalPorts Set to <code>true</code> if local ports should be
|
||||
* used
|
||||
*/
|
||||
public void setUseLocalPorts(boolean useLocalPorts) {
|
||||
this.useLocalPorts = useLocalPorts;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
// Get all the other parameters required from the standard system
|
||||
// properties. Only need to get the parameters that affect the creation
|
||||
// of the server port.
|
||||
String rmiRegistrySSLValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.registry.ssl", "false");
|
||||
rmiRegistrySSL = Boolean.parseBoolean(rmiRegistrySSLValue);
|
||||
|
||||
String rmiServerSSLValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.ssl", "true");
|
||||
rmiServerSSL = Boolean.parseBoolean(rmiServerSSLValue);
|
||||
|
||||
String protocolsValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.ssl.enabled.protocols");
|
||||
if (protocolsValue != null) {
|
||||
protocols = protocolsValue.split(",");
|
||||
}
|
||||
|
||||
String ciphersValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.ssl.enabled.cipher.suites");
|
||||
if (ciphersValue != null) {
|
||||
ciphers = ciphersValue.split(",");
|
||||
}
|
||||
|
||||
String clientAuthValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.ssl.need.client.auth", "true");
|
||||
clientAuth = Boolean.parseBoolean(clientAuthValue);
|
||||
|
||||
String authenticateValue = System.getProperty(
|
||||
"com.sun.management.jmxremote.authenticate", "true");
|
||||
authenticate = Boolean.parseBoolean(authenticateValue);
|
||||
|
||||
passwordFile = System.getProperty(
|
||||
"com.sun.management.jmxremote.password.file",
|
||||
"jmxremote.password");
|
||||
|
||||
accessFile = System.getProperty(
|
||||
"com.sun.management.jmxremote.access.file",
|
||||
"jmxremote.access");
|
||||
|
||||
loginModuleName = System.getProperty(
|
||||
"com.sun.management.jmxremote.login.config");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void lifecycleEvent(LifecycleEvent event) {
|
||||
if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
|
||||
log.warn(sm.getString("jmxRemoteLifecycleListener.deprecated"));
|
||||
} else if (Lifecycle.START_EVENT.equals(event.getType())) {
|
||||
// When the server starts, configure JMX/RMI
|
||||
|
||||
// Configure using standard JMX system properties
|
||||
init();
|
||||
|
||||
// Prevent an attacker guessing the RMI object ID
|
||||
System.setProperty("java.rmi.server.randomIDs", "true");
|
||||
|
||||
// Create the environment
|
||||
HashMap<String,Object> env = new HashMap<>();
|
||||
|
||||
RMIClientSocketFactory registryCsf = null;
|
||||
RMIServerSocketFactory registrySsf = null;
|
||||
|
||||
RMIClientSocketFactory serverCsf = null;
|
||||
RMIServerSocketFactory serverSsf = null;
|
||||
|
||||
// Configure registry socket factories
|
||||
if (rmiRegistrySSL) {
|
||||
registryCsf = new SslRMIClientSocketFactory();
|
||||
if (rmiBindAddress == null) {
|
||||
registrySsf = new SslRMIServerSocketFactory(
|
||||
ciphers, protocols, clientAuth);
|
||||
} else {
|
||||
registrySsf = new SslRmiServerBindSocketFactory(
|
||||
ciphers, protocols, clientAuth, rmiBindAddress);
|
||||
}
|
||||
} else {
|
||||
if (rmiBindAddress != null) {
|
||||
registrySsf = new RmiServerBindSocketFactory(rmiBindAddress);
|
||||
}
|
||||
}
|
||||
|
||||
// Configure server socket factories
|
||||
if (rmiServerSSL) {
|
||||
serverCsf = new SslRMIClientSocketFactory();
|
||||
if (rmiBindAddress == null) {
|
||||
serverSsf = new SslRMIServerSocketFactory(
|
||||
ciphers, protocols, clientAuth);
|
||||
} else {
|
||||
serverSsf = new SslRmiServerBindSocketFactory(
|
||||
ciphers, protocols, clientAuth, rmiBindAddress);
|
||||
}
|
||||
} else {
|
||||
if (rmiBindAddress != null) {
|
||||
serverSsf = new RmiServerBindSocketFactory(rmiBindAddress);
|
||||
}
|
||||
}
|
||||
|
||||
// By default, the registry will pick an address to listen on.
|
||||
// Setting this property overrides that and ensures it listens on
|
||||
// the configured address.
|
||||
if (rmiBindAddress != null) {
|
||||
System.setProperty("java.rmi.server.hostname", rmiBindAddress);
|
||||
}
|
||||
|
||||
// Force the use of local ports if required
|
||||
if (useLocalPorts) {
|
||||
registryCsf = new RmiClientLocalhostSocketFactory(registryCsf);
|
||||
serverCsf = new RmiClientLocalhostSocketFactory(serverCsf);
|
||||
}
|
||||
|
||||
env.put("jmx.remote.rmi.server.credential.types", new String[] {
|
||||
String[].class.getName(),
|
||||
String.class.getName() });
|
||||
|
||||
// Populate the env properties used to create the server
|
||||
if (serverCsf != null) {
|
||||
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, serverCsf);
|
||||
env.put("com.sun.jndi.rmi.factory.socket", registryCsf);
|
||||
}
|
||||
if (serverSsf != null) {
|
||||
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverSsf);
|
||||
}
|
||||
|
||||
// Configure authentication
|
||||
if (authenticate) {
|
||||
env.put("jmx.remote.x.password.file", passwordFile);
|
||||
env.put("jmx.remote.x.access.file", accessFile);
|
||||
env.put("jmx.remote.x.login.config", loginModuleName);
|
||||
}
|
||||
|
||||
// Create the Platform server
|
||||
csPlatform = createServer("Platform", rmiBindAddress, rmiRegistryPortPlatform,
|
||||
rmiServerPortPlatform, env, registryCsf, registrySsf, serverCsf, serverSsf);
|
||||
|
||||
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
|
||||
destroyServer("Platform", csPlatform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private JMXConnectorServer createServer(String serverName,
|
||||
String bindAddress, int theRmiRegistryPort, int theRmiServerPort,
|
||||
HashMap<String,Object> theEnv,
|
||||
RMIClientSocketFactory registryCsf, RMIServerSocketFactory registrySsf,
|
||||
RMIClientSocketFactory serverCsf, RMIServerSocketFactory serverSsf) {
|
||||
|
||||
if (bindAddress == null) {
|
||||
bindAddress = "localhost";
|
||||
}
|
||||
|
||||
String url = "service:jmx:rmi://" + bindAddress;
|
||||
JMXServiceURL serviceUrl;
|
||||
try {
|
||||
serviceUrl = new JMXServiceURL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
log.error(sm.getString("jmxRemoteLifecycleListener.invalidURL", serverName, url), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
RMIConnectorServer cs = null;
|
||||
try {
|
||||
RMIJRMPServerImpl server = new RMIJRMPServerImpl(
|
||||
rmiServerPortPlatform, serverCsf, serverSsf, theEnv);
|
||||
cs = new RMIConnectorServer(serviceUrl, theEnv, server,
|
||||
ManagementFactory.getPlatformMBeanServer());
|
||||
cs.start();
|
||||
Remote jmxServer = server.toStub();
|
||||
// Create the RMI registry
|
||||
try {
|
||||
/*
|
||||
* JmxRegistry is registered as a side-effect of creation.
|
||||
* This object is here so we can tell the IDE it is OK for it
|
||||
* not to be used.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
JmxRegistry unused = new JmxRegistry(theRmiRegistryPort, registryCsf, registrySsf, "jmxrmi", jmxServer);
|
||||
} catch (RemoteException e) {
|
||||
log.error(sm.getString(
|
||||
"jmxRemoteLifecycleListener.createRegistryFailed",
|
||||
serverName, Integer.toString(theRmiRegistryPort)), e);
|
||||
return null;
|
||||
}
|
||||
log.info(sm.getString("jmxRemoteLifecycleListener.start",
|
||||
Integer.toString(theRmiRegistryPort),
|
||||
Integer.toString(theRmiServerPort), serverName));
|
||||
} catch (IOException e) {
|
||||
log.error(sm.getString(
|
||||
"jmxRemoteLifecycleListener.createServerFailed",
|
||||
serverName), e);
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
|
||||
private void destroyServer(String serverName,
|
||||
JMXConnectorServer theConnectorServer) {
|
||||
if (theConnectorServer != null) {
|
||||
try {
|
||||
theConnectorServer.stop();
|
||||
} catch (IOException e) {
|
||||
log.error(sm.getString(
|
||||
"jmxRemoteLifecycleListener.destroyServerFailed",
|
||||
serverName),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RmiClientLocalhostSocketFactory
|
||||
implements RMIClientSocketFactory, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String FORCED_HOST = "localhost";
|
||||
|
||||
private final RMIClientSocketFactory factory;
|
||||
|
||||
public RmiClientLocalhostSocketFactory(RMIClientSocketFactory theFactory) {
|
||||
factory = theFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException {
|
||||
if (factory == null) {
|
||||
return new Socket(FORCED_HOST, port);
|
||||
} else {
|
||||
return factory.createSocket(FORCED_HOST, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RmiServerBindSocketFactory implements RMIServerSocketFactory {
|
||||
|
||||
private final InetAddress bindAddress;
|
||||
|
||||
public RmiServerBindSocketFactory(String address) {
|
||||
InetAddress bindAddress = null;
|
||||
try {
|
||||
bindAddress = InetAddress.getByName(address);
|
||||
} catch (UnknownHostException e) {
|
||||
log.error(sm.getString(
|
||||
"jmxRemoteLifecycleListener.invalidRmiBindAddress", address), e);
|
||||
// bind address will be null which means any/all local addresses
|
||||
// which should be safe
|
||||
}
|
||||
this.bindAddress = bindAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
return new ServerSocket(port, 0, bindAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SslRmiServerBindSocketFactory extends SslRMIServerSocketFactory {
|
||||
|
||||
private static final SSLServerSocketFactory sslServerSocketFactory;
|
||||
private static final String[] defaultProtocols;
|
||||
|
||||
static {
|
||||
SSLContext sslContext;
|
||||
try {
|
||||
sslContext = SSLContext.getDefault();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// Can't continue. Force a failure.
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
sslServerSocketFactory = sslContext.getServerSocketFactory();
|
||||
String[] protocols = sslContext.getDefaultSSLParameters().getProtocols();
|
||||
List<String> filteredProtocols = new ArrayList<>(protocols.length);
|
||||
for (String protocol : protocols) {
|
||||
if (protocol.toUpperCase(Locale.ENGLISH).contains("SSL")) {
|
||||
continue;
|
||||
}
|
||||
filteredProtocols.add(protocol);
|
||||
}
|
||||
defaultProtocols = filteredProtocols.toArray(new String[filteredProtocols.size()]);
|
||||
}
|
||||
|
||||
private final InetAddress bindAddress;
|
||||
|
||||
public SslRmiServerBindSocketFactory(String[] enabledCipherSuites,
|
||||
String[] enabledProtocols, boolean needClientAuth, String address) {
|
||||
super(enabledCipherSuites, enabledProtocols, needClientAuth);
|
||||
InetAddress bindAddress = null;
|
||||
try {
|
||||
bindAddress = InetAddress.getByName(address);
|
||||
} catch (UnknownHostException e) {
|
||||
log.error(sm.getString(
|
||||
"jmxRemoteLifecycleListener.invalidRmiBindAddress", address), e);
|
||||
// bind address will be null which means any/all local addresses
|
||||
// which should be safe
|
||||
}
|
||||
this.bindAddress = bindAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
SSLServerSocket sslServerSocket =
|
||||
(SSLServerSocket) sslServerSocketFactory.createServerSocket(port, 0, bindAddress);
|
||||
if (getEnabledCipherSuites() != null) {
|
||||
sslServerSocket.setEnabledCipherSuites(getEnabledCipherSuites());
|
||||
}
|
||||
if (getEnabledProtocols() == null) {
|
||||
sslServerSocket.setEnabledProtocols(defaultProtocols);
|
||||
} else {
|
||||
sslServerSocket.setEnabledProtocols(getEnabledProtocols());
|
||||
}
|
||||
sslServerSocket.setNeedClientAuth(getNeedClientAuth());
|
||||
return sslServerSocket;
|
||||
}
|
||||
|
||||
// Super class defines hashCode() and equals(). Probably not used in
|
||||
// Tomcat but for safety, override them here.
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((bindAddress == null) ? 0 : bindAddress.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
SslRmiServerBindSocketFactory other = (SslRmiServerBindSocketFactory) obj;
|
||||
if (bindAddress == null) {
|
||||
if (other.bindAddress != null)
|
||||
return false;
|
||||
} else if (!bindAddress.equals(other.bindAddress))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Better to use the internal API than re-invent the wheel.
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
private static class JmxRegistry extends sun.rmi.registry.RegistryImpl {
|
||||
private static final long serialVersionUID = -3772054804656428217L;
|
||||
private final String jmxName;
|
||||
private final Remote jmxServer;
|
||||
public JmxRegistry(int port, RMIClientSocketFactory csf,
|
||||
RMIServerSocketFactory ssf, String jmxName, Remote jmxServer) throws RemoteException {
|
||||
super(port, csf, ssf);
|
||||
this.jmxName = jmxName;
|
||||
this.jmxServer = jmxServer;
|
||||
}
|
||||
@Override
|
||||
public Remote lookup(String name)
|
||||
throws RemoteException, NotBoundException {
|
||||
return (jmxName.equals(name)) ? jmxServer : null;
|
||||
}
|
||||
@Override
|
||||
public void bind(String name, Remote obj)
|
||||
throws RemoteException, AlreadyBoundException, AccessException {
|
||||
}
|
||||
@Override
|
||||
public void unbind(String name)
|
||||
throws RemoteException, NotBoundException, AccessException {
|
||||
}
|
||||
@Override
|
||||
public void rebind(String name, Remote obj)
|
||||
throws RemoteException, AccessException {
|
||||
}
|
||||
@Override
|
||||
public String[] list() throws RemoteException {
|
||||
return new String[] { jmxName };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
java/org/apache/catalina/mbeans/LocalStrings.properties
Normal file
24
java/org/apache/catalina/mbeans/LocalStrings.properties
Normal file
@@ -0,0 +1,24 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.createRegistryFailed=Unable to create the RMI registry for the [{0}] server using port [{1}]
|
||||
jmxRemoteLifecycleListener.createServerFailed=The JMX connector server could not be created or failed to start for the [{0}] server
|
||||
jmxRemoteLifecycleListener.deprecated=The JmxRemoteLifecycleListener is deprecated as as the features it provides are now available in the remote JMX capability included with the JRE. This listener will be removed in Tomcat 10 and may be removed from Tomcat 8 some time after 2020-12-31.
|
||||
jmxRemoteLifecycleListener.destroyServerFailed=The JMX connector server could not be stopped for the [{0}] server
|
||||
jmxRemoteLifecycleListener.invalidRmiBindAddress=Invalid RMI bind address [{0}]
|
||||
jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested for the [{0}] server, [{1}], was invalid
|
||||
jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port [{0}] and the server on port [{1}] for the [{2}] server
|
||||
|
||||
mBeanFactory.managerContext=Manager components may only be added to Contexts.
|
||||
16
java/org/apache/catalina/mbeans/LocalStrings_es.properties
Normal file
16
java/org/apache/catalina/mbeans/LocalStrings_es.properties
Normal file
@@ -0,0 +1,16 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.invalidURL=LA URL del servicio JMX solicitada por el servidor [{0}], [{1}], fue no válida
|
||||
23
java/org/apache/catalina/mbeans/LocalStrings_fr.properties
Normal file
23
java/org/apache/catalina/mbeans/LocalStrings_fr.properties
Normal file
@@ -0,0 +1,23 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.createRegistryFailed=Création du répertoire RMI impossible pour le serveur [{0}] utilisant le port [{1}]
|
||||
jmxRemoteLifecycleListener.createServerFailed=Le connecteur serveur JMX pour le serveur [{0}] n''a pas pu être créé ou n''a pas pu démarrer
|
||||
jmxRemoteLifecycleListener.destroyServerFailed=Le connecteur serveur JMX pour le serveur [{0}] n''a pas pu être stoppé
|
||||
jmxRemoteLifecycleListener.invalidRmiBindAddress=Adresse d''association du RMI invalide [{0}]
|
||||
jmxRemoteLifecycleListener.invalidURL=L''URL demandée pour le serveur [{0}], [{1}], est incorrect
|
||||
jmxRemoteLifecycleListener.start=L''écouteur distant JMX a configuré le répertoire sur le port [{0}] et le serveur sur le port [{1}] pour le serveur [{2}]
|
||||
|
||||
mBeanFactory.managerContext=Un gestionnaire de sessions ne peut être ajouté qu'à un contexte
|
||||
23
java/org/apache/catalina/mbeans/LocalStrings_ja.properties
Normal file
23
java/org/apache/catalina/mbeans/LocalStrings_ja.properties
Normal file
@@ -0,0 +1,23 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.createRegistryFailed=ポート[{1}]を使用して[{0}]サーバーのRMIレジストリを作成できません
|
||||
jmxRemoteLifecycleListener.createServerFailed=[{0}]サーバーのJMXコネクタサーバーを作成できなかったか、または開始できませんでした
|
||||
jmxRemoteLifecycleListener.destroyServerFailed=[{0}]サーバーのJMXコネクタサーバーを停止できませんでした。
|
||||
jmxRemoteLifecycleListener.invalidRmiBindAddress=無効なRMIバインドアドレス[{0}]
|
||||
jmxRemoteLifecycleListener.invalidURL=[{0}] サーバーに不正な JMX サービスリクエスト [{1}] が要求されました。
|
||||
jmxRemoteLifecycleListener.start=サーバー [{2}] の JMX リモートリスナーをレジストリーポート番号 [{0}] サーバーポート番号 [{1}] で構成しました。
|
||||
|
||||
mBeanFactory.managerContext=ManagerコンポーネントはContextにのみ追加できます。
|
||||
23
java/org/apache/catalina/mbeans/LocalStrings_ko.properties
Normal file
23
java/org/apache/catalina/mbeans/LocalStrings_ko.properties
Normal file
@@ -0,0 +1,23 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.createRegistryFailed=[{0}] 서버를 위한 RMI 레지스트리를, 포트 번호 [{1}]을(를) 사용하여 생성할 수 없습니다.
|
||||
jmxRemoteLifecycleListener.createServerFailed=JMX connector 서버가 생성될 수 없었거나, [{0}] 서버를 위해 시작되지 못했습니다.
|
||||
jmxRemoteLifecycleListener.destroyServerFailed=[{0}] 서버를 위해, JMX connector 서버가 중지될 수 없었습니다.
|
||||
jmxRemoteLifecycleListener.invalidRmiBindAddress=유효하지 않은 RMI 바인딩 주소 [{0}]
|
||||
jmxRemoteLifecycleListener.invalidURL=[{0}] 서버에 요청하는 JMX 서비스 URL [{1}]은(는) 유효하지 않습니다.
|
||||
jmxRemoteLifecycleListener.start=[{2}] 서버를 위하여, JMX 원격 리스너가 포트 [{0}]에 레지스트리를 설정했으며, 포트 [{1}]에 서버를 설정했습니다.
|
||||
|
||||
mBeanFactory.managerContext=매니저 구성요소들은 컨텍스트들에만 추가될 수 있습니다.
|
||||
@@ -0,0 +1,18 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
jmxRemoteLifecycleListener.createRegistryFailed=无法使用端口[{1}]为[{0}]服务器创建RMI注册表
|
||||
jmxRemoteLifecycleListener.createServerFailed=无法为[{0}]服务器创建JMX连接器服务器或启动失败
|
||||
jmxRemoteLifecycleListener.invalidURL=为[{0}]服务器[{1}]请求的JMX服务URL无效
|
||||
191
java/org/apache/catalina/mbeans/MBeanDumper.java
Normal file
191
java/org/apache/catalina/mbeans/MBeanDumper.java
Normal file
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.JMRuntimeException;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanInfo;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.apache.tomcat.util.ExceptionUtils;
|
||||
|
||||
/**
|
||||
* General helper to dump MBean contents to the log.
|
||||
*
|
||||
*/
|
||||
public class MBeanDumper {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MBeanDumper.class);
|
||||
|
||||
private static final String CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* The following code to dump MBeans has been copied from JMXProxyServlet.
|
||||
* @param mbeanServer the MBean server
|
||||
* @param names a set of object names for which to dump the info
|
||||
* @return a string representation of the MBeans
|
||||
*/
|
||||
public static String dumpBeans(MBeanServer mbeanServer, Set<ObjectName> names)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (ObjectName oname : names) {
|
||||
buf.append("Name: ");
|
||||
buf.append(oname.toString());
|
||||
buf.append(CRLF);
|
||||
|
||||
try {
|
||||
MBeanInfo minfo=mbeanServer.getMBeanInfo(oname);
|
||||
// can't be null - I think
|
||||
String code=minfo.getClassName();
|
||||
if ("org.apache.commons.modeler.BaseModelMBean".equals(code)) {
|
||||
code=(String)mbeanServer.getAttribute(oname, "modelerType");
|
||||
}
|
||||
buf.append("modelerType: ");
|
||||
buf.append(code);
|
||||
buf.append(CRLF);
|
||||
|
||||
MBeanAttributeInfo attrs[]=minfo.getAttributes();
|
||||
Object value=null;
|
||||
|
||||
for (int i=0; i< attrs.length; i++) {
|
||||
if (! attrs[i].isReadable()) continue;
|
||||
String attName=attrs[i].getName();
|
||||
if ("modelerType".equals(attName)) continue;
|
||||
if (attName.indexOf('=') >=0 ||
|
||||
attName.indexOf(':') >=0 ||
|
||||
attName.indexOf(' ') >=0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
value=mbeanServer.getAttribute(oname, attName);
|
||||
} catch (JMRuntimeException rme) {
|
||||
Throwable cause = rme.getCause();
|
||||
if (cause instanceof UnsupportedOperationException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Error getting attribute " + oname
|
||||
+ " " + attName, rme);
|
||||
}
|
||||
} else if (cause instanceof NullPointerException) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Error getting attribute " + oname
|
||||
+ " " + attName, rme);
|
||||
}
|
||||
} else {
|
||||
log.error("Error getting attribute " + oname +
|
||||
" " + attName, rme);
|
||||
}
|
||||
continue;
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.handleThrowable(t);
|
||||
log.error("Error getting attribute " + oname +
|
||||
" " + attName, t);
|
||||
continue;
|
||||
}
|
||||
if (value==null) continue;
|
||||
String valueString;
|
||||
try {
|
||||
Class<?> c = value.getClass();
|
||||
if (c.isArray()) {
|
||||
int len = Array.getLength(value);
|
||||
StringBuilder sb = new StringBuilder("Array[" +
|
||||
c.getComponentType().getName() + "] of length " + len);
|
||||
if (len > 0) {
|
||||
sb.append(CRLF);
|
||||
}
|
||||
for (int j = 0; j < len; j++) {
|
||||
sb.append("\t");
|
||||
Object item = Array.get(value, j);
|
||||
if (item == null) {
|
||||
sb.append("NULL VALUE");
|
||||
} else {
|
||||
try {
|
||||
sb.append(escape(item.toString()));
|
||||
}
|
||||
catch (Throwable t) {
|
||||
ExceptionUtils.handleThrowable(t);
|
||||
sb.append("NON-STRINGABLE VALUE");
|
||||
}
|
||||
}
|
||||
if (j < len - 1) {
|
||||
sb.append(CRLF);
|
||||
}
|
||||
}
|
||||
valueString = sb.toString();
|
||||
}
|
||||
else {
|
||||
valueString = escape(value.toString());
|
||||
}
|
||||
buf.append(attName);
|
||||
buf.append(": ");
|
||||
buf.append(valueString);
|
||||
buf.append(CRLF);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
ExceptionUtils.handleThrowable(t);
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.handleThrowable(t);
|
||||
}
|
||||
buf.append(CRLF);
|
||||
}
|
||||
return buf.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String escape(String value) {
|
||||
// The only invalid char is \n
|
||||
// We also need to keep the string short and split it with \nSPACE
|
||||
// XXX TODO
|
||||
int idx=value.indexOf( "\n" );
|
||||
if( idx < 0 ) return value;
|
||||
|
||||
int prev=0;
|
||||
StringBuilder sb=new StringBuilder();
|
||||
while( idx >= 0 ) {
|
||||
appendHead(sb, value, prev, idx);
|
||||
|
||||
sb.append( "\\n\n ");
|
||||
prev=idx+1;
|
||||
if( idx==value.length() -1 ) break;
|
||||
idx=value.indexOf('\n', idx+1);
|
||||
}
|
||||
if( prev < value.length() )
|
||||
appendHead( sb, value, prev, value.length());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void appendHead( StringBuilder sb, String value, int start, int end) {
|
||||
if (end < 1) return;
|
||||
|
||||
int pos=start;
|
||||
while( end-pos > 78 ) {
|
||||
sb.append( value.substring(pos, pos+78));
|
||||
sb.append( "\n ");
|
||||
pos=pos+78;
|
||||
}
|
||||
sb.append( value.substring(pos,end));
|
||||
}
|
||||
|
||||
}
|
||||
925
java/org/apache/catalina/mbeans/MBeanFactory.java
Normal file
925
java/org/apache/catalina/mbeans/MBeanFactory.java
Normal file
@@ -0,0 +1,925 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Container;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.Engine;
|
||||
import org.apache.catalina.Host;
|
||||
import org.apache.catalina.JmxEnabled;
|
||||
import org.apache.catalina.Server;
|
||||
import org.apache.catalina.Service;
|
||||
import org.apache.catalina.Valve;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.core.StandardContext;
|
||||
import org.apache.catalina.core.StandardEngine;
|
||||
import org.apache.catalina.core.StandardHost;
|
||||
import org.apache.catalina.core.StandardService;
|
||||
import org.apache.catalina.loader.WebappLoader;
|
||||
import org.apache.catalina.realm.DataSourceRealm;
|
||||
import org.apache.catalina.realm.JDBCRealm;
|
||||
import org.apache.catalina.realm.JNDIRealm;
|
||||
import org.apache.catalina.realm.MemoryRealm;
|
||||
import org.apache.catalina.realm.UserDatabaseRealm;
|
||||
import org.apache.catalina.session.StandardManager;
|
||||
import org.apache.catalina.startup.ContextConfig;
|
||||
import org.apache.catalina.startup.HostConfig;
|
||||
import org.apache.juli.logging.Log;
|
||||
import org.apache.juli.logging.LogFactory;
|
||||
import org.apache.tomcat.util.res.StringManager;
|
||||
|
||||
|
||||
/**
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class MBeanFactory {
|
||||
|
||||
private static final Log log = LogFactory.getLog(MBeanFactory.class);
|
||||
|
||||
protected static final StringManager sm = StringManager.getManager(MBeanFactory.class);
|
||||
|
||||
/**
|
||||
* The <code>MBeanServer</code> for this application.
|
||||
*/
|
||||
private static final MBeanServer mserver = MBeanUtils.createServer();
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Attributes
|
||||
|
||||
/**
|
||||
* The container (Server/Service) for which this factory was created.
|
||||
*/
|
||||
private Object container;
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Operations
|
||||
|
||||
/**
|
||||
* Set the container that this factory was created for.
|
||||
* @param container The associated container
|
||||
*/
|
||||
public void setContainer(Object container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Little convenience method to remove redundant code
|
||||
* when retrieving the path string
|
||||
*
|
||||
* @param t path string
|
||||
* @return empty string if t==null || t.equals("/")
|
||||
*/
|
||||
private final String getPathStr(String t) {
|
||||
if (t == null || t.equals("/")) {
|
||||
return "";
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parent Container to add its child component
|
||||
* from parent's ObjectName
|
||||
*/
|
||||
private Container getParentContainerFromParent(ObjectName pname)
|
||||
throws Exception {
|
||||
|
||||
String type = pname.getKeyProperty("type");
|
||||
String j2eeType = pname.getKeyProperty("j2eeType");
|
||||
Service service = getService(pname);
|
||||
StandardEngine engine = (StandardEngine) service.getContainer();
|
||||
if ((j2eeType!=null) && (j2eeType.equals("WebModule"))) {
|
||||
String name = pname.getKeyProperty("name");
|
||||
name = name.substring(2);
|
||||
int i = name.indexOf('/');
|
||||
String hostName = name.substring(0,i);
|
||||
String path = name.substring(i);
|
||||
Container host = engine.findChild(hostName);
|
||||
String pathStr = getPathStr(path);
|
||||
Container context = host.findChild(pathStr);
|
||||
return context;
|
||||
} else if (type != null) {
|
||||
if (type.equals("Engine")) {
|
||||
return engine;
|
||||
} else if (type.equals("Host")) {
|
||||
String hostName = pname.getKeyProperty("host");
|
||||
Container host = engine.findChild(hostName);
|
||||
return host;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Parent ContainerBase to add its child component
|
||||
* from child component's ObjectName as a String
|
||||
*/
|
||||
private Container getParentContainerFromChild(ObjectName oname)
|
||||
throws Exception {
|
||||
|
||||
String hostName = oname.getKeyProperty("host");
|
||||
String path = oname.getKeyProperty("path");
|
||||
Service service = getService(oname);
|
||||
Container engine = service.getContainer();
|
||||
if (hostName == null) {
|
||||
// child's container is Engine
|
||||
return engine;
|
||||
} else if (path == null) {
|
||||
// child's container is Host
|
||||
Container host = engine.findChild(hostName);
|
||||
return host;
|
||||
} else {
|
||||
// child's container is Context
|
||||
Container host = engine.findChild(hostName);
|
||||
path = getPathStr(path);
|
||||
Container context = host.findChild(path);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Service getService(ObjectName oname) throws Exception {
|
||||
|
||||
if (container instanceof Service) {
|
||||
// Don't bother checking the domain - this is the only option
|
||||
return (Service) container;
|
||||
}
|
||||
|
||||
StandardService service = null;
|
||||
String domain = oname.getDomain();
|
||||
if (container instanceof Server) {
|
||||
Service[] services = ((Server)container).findServices();
|
||||
for (int i = 0; i < services.length; i++) {
|
||||
service = (StandardService) services[i];
|
||||
if (domain.equals(service.getObjectName().getDomain())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (service == null ||
|
||||
!service.getObjectName().getDomain().equals(domain)) {
|
||||
throw new Exception("Service with the domain is not found");
|
||||
}
|
||||
return service;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new AjpConnector
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param address The IP address on which to bind
|
||||
* @param port TCP port number to listen on
|
||||
* @return the object name of the created connector
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createAjpConnector(String parent, String address, int port)
|
||||
throws Exception {
|
||||
|
||||
return createConnector(parent, address, port, true, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new DataSource Realm.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param dataSourceName the datasource name
|
||||
* @param roleNameCol the column name for the role names
|
||||
* @param userCredCol the column name for the user credentials
|
||||
* @param userNameCol the column name for the user names
|
||||
* @param userRoleTable the table name for the roles table
|
||||
* @param userTable the table name for the users
|
||||
* @return the object name of the created realm
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createDataSourceRealm(String parent, String dataSourceName,
|
||||
String roleNameCol, String userCredCol, String userNameCol,
|
||||
String userRoleTable, String userTable) throws Exception {
|
||||
|
||||
// Create a new DataSourceRealm instance
|
||||
DataSourceRealm realm = new DataSourceRealm();
|
||||
realm.setDataSourceName(dataSourceName);
|
||||
realm.setRoleNameCol(roleNameCol);
|
||||
realm.setUserCredCol(userCredCol);
|
||||
realm.setUserNameCol(userNameCol);
|
||||
realm.setUserRoleTable(userRoleTable);
|
||||
realm.setUserTable(userTable);
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
// Add the new instance to its parent component
|
||||
container.setRealm(realm);
|
||||
// Return the corresponding MBean name
|
||||
ObjectName oname = realm.getObjectName();
|
||||
if (oname != null) {
|
||||
return oname.toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new HttpConnector
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param address The IP address on which to bind
|
||||
* @param port TCP port number to listen on
|
||||
* @return the object name of the created connector
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createHttpConnector(String parent, String address, int port)
|
||||
throws Exception {
|
||||
return createConnector(parent, address, port, false, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Connector
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param address The IP address on which to bind
|
||||
* @param port TCP port number to listen on
|
||||
* @param isAjp Create a AJP/1.3 Connector
|
||||
* @param isSSL Create a secure Connector
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL)
|
||||
throws Exception {
|
||||
// Set the protocol
|
||||
String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
|
||||
Connector retobj = new Connector(protocol);
|
||||
if ((address!=null) && (address.length()>0)) {
|
||||
retobj.setProperty("address", address);
|
||||
}
|
||||
// Set port number
|
||||
retobj.setPort(port);
|
||||
// Set SSL
|
||||
retobj.setSecure(isSSL);
|
||||
retobj.setScheme(isSSL ? "https" : "http");
|
||||
// Add the new instance to its parent component
|
||||
// FIX ME - addConnector will fail
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Service service = getService(pname);
|
||||
service.addConnector(retobj);
|
||||
|
||||
// Return the corresponding MBean name
|
||||
ObjectName coname = retobj.getObjectName();
|
||||
|
||||
return coname.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new HttpsConnector
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param address The IP address on which to bind
|
||||
* @param port TCP port number to listen on
|
||||
* @return the object name of the created connector
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createHttpsConnector(String parent, String address, int port)
|
||||
throws Exception {
|
||||
return createConnector(parent, address, port, false, true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new JDBC Realm.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param driverName JDBC driver name
|
||||
* @param connectionName the user name for the connection
|
||||
* @param connectionPassword the password for the connection
|
||||
* @param connectionURL the connection URL to the database
|
||||
* @return the object name of the created realm
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createJDBCRealm(String parent, String driverName,
|
||||
String connectionName, String connectionPassword, String connectionURL)
|
||||
throws Exception {
|
||||
|
||||
// Create a new JDBCRealm instance
|
||||
JDBCRealm realm = new JDBCRealm();
|
||||
realm.setDriverName(driverName);
|
||||
realm.setConnectionName(connectionName);
|
||||
realm.setConnectionPassword(connectionPassword);
|
||||
realm.setConnectionURL(connectionURL);
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
// Add the new instance to its parent component
|
||||
container.setRealm(realm);
|
||||
// Return the corresponding MBean name
|
||||
ObjectName oname = realm.getObjectName();
|
||||
|
||||
if (oname != null) {
|
||||
return (oname.toString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new JNDI Realm.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @return the object name of the created realm
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createJNDIRealm(String parent) throws Exception {
|
||||
|
||||
// Create a new JNDIRealm instance
|
||||
JNDIRealm realm = new JNDIRealm();
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
// Add the new instance to its parent component
|
||||
container.setRealm(realm);
|
||||
// Return the corresponding MBean name
|
||||
ObjectName oname = realm.getObjectName();
|
||||
|
||||
if (oname != null) {
|
||||
return (oname.toString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Memory Realm.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @return the object name of the created realm
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createMemoryRealm(String parent) throws Exception {
|
||||
|
||||
// Create a new MemoryRealm instance
|
||||
MemoryRealm realm = new MemoryRealm();
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
// Add the new instance to its parent component
|
||||
container.setRealm(realm);
|
||||
// Return the corresponding MBean name
|
||||
ObjectName oname = realm.getObjectName();
|
||||
if (oname != null) {
|
||||
return (oname.toString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new StandardContext.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param path The context path for this Context
|
||||
* @param docBase Document base directory (or WAR) for this Context
|
||||
* @return the object name of the created context
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createStandardContext(String parent,
|
||||
String path,
|
||||
String docBase)
|
||||
throws Exception {
|
||||
|
||||
return createStandardContext(parent, path, docBase, false, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new StandardContext.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param path The context path for this Context
|
||||
* @param docBase Document base directory (or WAR) for this Context
|
||||
* @param xmlValidation if XML descriptors should be validated
|
||||
* @param xmlNamespaceAware if the XML processor should namespace aware
|
||||
* @return the object name of the created context
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createStandardContext(String parent,
|
||||
String path,
|
||||
String docBase,
|
||||
boolean xmlValidation,
|
||||
boolean xmlNamespaceAware)
|
||||
throws Exception {
|
||||
|
||||
// Create a new StandardContext instance
|
||||
StandardContext context = new StandardContext();
|
||||
path = getPathStr(path);
|
||||
context.setPath(path);
|
||||
context.setDocBase(docBase);
|
||||
context.setXmlValidation(xmlValidation);
|
||||
context.setXmlNamespaceAware(xmlNamespaceAware);
|
||||
|
||||
ContextConfig contextConfig = new ContextConfig();
|
||||
context.addLifecycleListener(contextConfig);
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
ObjectName deployer = new ObjectName(pname.getDomain()+
|
||||
":type=Deployer,host="+
|
||||
pname.getKeyProperty("host"));
|
||||
if(mserver.isRegistered(deployer)) {
|
||||
String contextName = context.getName();
|
||||
mserver.invoke(deployer, "addServiced",
|
||||
new Object [] {contextName},
|
||||
new String [] {"java.lang.String"});
|
||||
String configPath = (String)mserver.getAttribute(deployer,
|
||||
"configBaseName");
|
||||
String baseName = context.getBaseName();
|
||||
File configFile = new File(new File(configPath), baseName+".xml");
|
||||
if (configFile.isFile()) {
|
||||
context.setConfigFile(configFile.toURI().toURL());
|
||||
}
|
||||
mserver.invoke(deployer, "manageApp",
|
||||
new Object[] {context},
|
||||
new String[] {"org.apache.catalina.Context"});
|
||||
mserver.invoke(deployer, "removeServiced",
|
||||
new Object [] {contextName},
|
||||
new String [] {"java.lang.String"});
|
||||
} else {
|
||||
log.warn("Deployer not found for "+pname.getKeyProperty("host"));
|
||||
Service service = getService(pname);
|
||||
Engine engine = service.getContainer();
|
||||
Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
|
||||
host.addChild(context);
|
||||
}
|
||||
|
||||
// Return the corresponding MBean name
|
||||
return context.getObjectName().toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new StandardHost.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param name Unique name of this Host
|
||||
* @param appBase Application base directory name
|
||||
* @param autoDeploy Should we auto deploy?
|
||||
* @param deployOnStartup Deploy on server startup?
|
||||
* @param deployXML Should we deploy Context XML config files property?
|
||||
* @param unpackWARs Should we unpack WARs when auto deploying?
|
||||
* @return the object name of the created host
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createStandardHost(String parent, String name,
|
||||
String appBase,
|
||||
boolean autoDeploy,
|
||||
boolean deployOnStartup,
|
||||
boolean deployXML,
|
||||
boolean unpackWARs)
|
||||
throws Exception {
|
||||
|
||||
// Create a new StandardHost instance
|
||||
StandardHost host = new StandardHost();
|
||||
host.setName(name);
|
||||
host.setAppBase(appBase);
|
||||
host.setAutoDeploy(autoDeploy);
|
||||
host.setDeployOnStartup(deployOnStartup);
|
||||
host.setDeployXML(deployXML);
|
||||
host.setUnpackWARs(unpackWARs);
|
||||
|
||||
// add HostConfig for active reloading
|
||||
HostConfig hostConfig = new HostConfig();
|
||||
host.addLifecycleListener(hostConfig);
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Service service = getService(pname);
|
||||
Engine engine = service.getContainer();
|
||||
engine.addChild(host);
|
||||
|
||||
// Return the corresponding MBean name
|
||||
return host.getObjectName().toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new StandardService and StandardEngine.
|
||||
*
|
||||
* @param domain Domain name for the container instance
|
||||
* @param defaultHost Name of the default host to be used in the Engine
|
||||
* @param baseDir Base directory value for Engine
|
||||
* @return the object name of the created service
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createStandardServiceEngine(String domain,
|
||||
String defaultHost, String baseDir) throws Exception{
|
||||
|
||||
if (!(container instanceof Server)) {
|
||||
throw new Exception("Container not Server");
|
||||
}
|
||||
|
||||
StandardEngine engine = new StandardEngine();
|
||||
engine.setDomain(domain);
|
||||
engine.setName(domain);
|
||||
engine.setDefaultHost(defaultHost);
|
||||
|
||||
Service service = new StandardService();
|
||||
service.setContainer(engine);
|
||||
service.setName(domain);
|
||||
|
||||
((Server) container).addService(service);
|
||||
|
||||
return engine.getObjectName().toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new StandardManager.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @return the object name of the created manager
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createStandardManager(String parent)
|
||||
throws Exception {
|
||||
|
||||
// Create a new StandardManager instance
|
||||
StandardManager manager = new StandardManager();
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
if (container instanceof Context) {
|
||||
((Context) container).setManager(manager);
|
||||
} else {
|
||||
throw new Exception(sm.getString("mBeanFactory.managerContext"));
|
||||
}
|
||||
ObjectName oname = manager.getObjectName();
|
||||
if (oname != null) {
|
||||
return oname.toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new UserDatabaseRealm.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @param resourceName Global JNDI resource name of the associated
|
||||
* UserDatabase
|
||||
* @return the object name of the created realm
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createUserDatabaseRealm(String parent, String resourceName)
|
||||
throws Exception {
|
||||
|
||||
// Create a new UserDatabaseRealm instance
|
||||
UserDatabaseRealm realm = new UserDatabaseRealm();
|
||||
realm.setResourceName(resourceName);
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
// Add the new instance to its parent component
|
||||
container.setRealm(realm);
|
||||
// Return the corresponding MBean name
|
||||
ObjectName oname = realm.getObjectName();
|
||||
// FIXME getObjectName() returns null
|
||||
//ObjectName oname =
|
||||
// MBeanUtils.createObjectName(pname.getDomain(), realm);
|
||||
if (oname != null) {
|
||||
return (oname.toString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Valve and associate it with a {@link Container}.
|
||||
*
|
||||
* @param className The fully qualified class name of the {@link Valve} to
|
||||
* create
|
||||
* @param parent The MBean name of the associated parent
|
||||
* {@link Container}.
|
||||
*
|
||||
* @return The MBean name of the {@link Valve} that was created or
|
||||
* <code>null</code> if the {@link Valve} does not implement
|
||||
* {@link JmxEnabled}.
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createValve(String className, String parent)
|
||||
throws Exception {
|
||||
|
||||
// Look for the parent
|
||||
ObjectName parentName = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(parentName);
|
||||
|
||||
if (container == null) {
|
||||
// TODO
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
Valve valve = (Valve) Class.forName(className).getConstructor().newInstance();
|
||||
|
||||
container.getPipeline().addValve(valve);
|
||||
|
||||
if (valve instanceof JmxEnabled) {
|
||||
return ((JmxEnabled) valve).getObjectName().toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Web Application Loader.
|
||||
*
|
||||
* @param parent MBean Name of the associated parent component
|
||||
* @return the object name of the created loader
|
||||
*
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public String createWebappLoader(String parent)
|
||||
throws Exception {
|
||||
|
||||
// Create a new WebappLoader instance
|
||||
WebappLoader loader = new WebappLoader();
|
||||
|
||||
// Add the new instance to its parent component
|
||||
ObjectName pname = new ObjectName(parent);
|
||||
Container container = getParentContainerFromParent(pname);
|
||||
if (container instanceof Context) {
|
||||
((Context) container).setLoader(loader);
|
||||
}
|
||||
// FIXME add Loader.getObjectName
|
||||
//ObjectName oname = loader.getObjectName();
|
||||
ObjectName oname =
|
||||
MBeanUtils.createObjectName(pname.getDomain(), loader);
|
||||
return oname.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Connector.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeConnector(String name) throws Exception {
|
||||
|
||||
// Acquire a reference to the component to be removed
|
||||
ObjectName oname = new ObjectName(name);
|
||||
Service service = getService(oname);
|
||||
String port = oname.getKeyProperty("port");
|
||||
String address = oname.getKeyProperty("address");
|
||||
if (address != null) {
|
||||
address = ObjectName.unquote(address);
|
||||
}
|
||||
|
||||
Connector conns[] = service.findConnectors();
|
||||
|
||||
for (int i = 0; i < conns.length; i++) {
|
||||
String connAddress = null;
|
||||
Object objConnAddress = conns[i].getProperty("address");
|
||||
if (objConnAddress != null) {
|
||||
connAddress = ((InetAddress) objConnAddress).getHostAddress();
|
||||
}
|
||||
String connPort = ""+conns[i].getPort();
|
||||
|
||||
if (address == null) {
|
||||
// Don't combine this with outer if or we could get an NPE in
|
||||
// 'else if' below
|
||||
if (connAddress == null && port.equals(connPort)) {
|
||||
service.removeConnector(conns[i]);
|
||||
conns[i].destroy();
|
||||
break;
|
||||
}
|
||||
} else if (address.equals(connAddress) && port.equals(connPort)) {
|
||||
service.removeConnector(conns[i]);
|
||||
conns[i].destroy();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Context.
|
||||
*
|
||||
* @param contextName MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeContext(String contextName) throws Exception {
|
||||
|
||||
// Acquire a reference to the component to be removed
|
||||
ObjectName oname = new ObjectName(contextName);
|
||||
String domain = oname.getDomain();
|
||||
StandardService service = (StandardService) getService(oname);
|
||||
|
||||
Engine engine = service.getContainer();
|
||||
String name = oname.getKeyProperty("name");
|
||||
name = name.substring(2);
|
||||
int i = name.indexOf('/');
|
||||
String hostName = name.substring(0,i);
|
||||
String path = name.substring(i);
|
||||
ObjectName deployer = new ObjectName(domain+":type=Deployer,host="+
|
||||
hostName);
|
||||
String pathStr = getPathStr(path);
|
||||
if(mserver.isRegistered(deployer)) {
|
||||
mserver.invoke(deployer,"addServiced",
|
||||
new Object[]{pathStr},
|
||||
new String[] {"java.lang.String"});
|
||||
mserver.invoke(deployer,"unmanageApp",
|
||||
new Object[] {pathStr},
|
||||
new String[] {"java.lang.String"});
|
||||
mserver.invoke(deployer,"removeServiced",
|
||||
new Object[] {pathStr},
|
||||
new String[] {"java.lang.String"});
|
||||
} else {
|
||||
log.warn("Deployer not found for "+hostName);
|
||||
Host host = (Host) engine.findChild(hostName);
|
||||
Context context = (Context) host.findChild(pathStr);
|
||||
// Remove this component from its parent component
|
||||
host.removeChild(context);
|
||||
if(context instanceof StandardContext)
|
||||
try {
|
||||
((StandardContext)context).destroy();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error during context [" + context.getName() + "] destroy ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Host.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeHost(String name) throws Exception {
|
||||
|
||||
// Acquire a reference to the component to be removed
|
||||
ObjectName oname = new ObjectName(name);
|
||||
String hostName = oname.getKeyProperty("host");
|
||||
Service service = getService(oname);
|
||||
Engine engine = service.getContainer();
|
||||
Host host = (Host) engine.findChild(hostName);
|
||||
|
||||
// Remove this component from its parent component
|
||||
if(host!=null) {
|
||||
engine.removeChild(host);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Loader.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeLoader(String name) throws Exception {
|
||||
|
||||
ObjectName oname = new ObjectName(name);
|
||||
// Acquire a reference to the component to be removed
|
||||
Container container = getParentContainerFromChild(oname);
|
||||
if (container instanceof Context) {
|
||||
((Context) container).setLoader(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Manager.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeManager(String name) throws Exception {
|
||||
|
||||
ObjectName oname = new ObjectName(name);
|
||||
// Acquire a reference to the component to be removed
|
||||
Container container = getParentContainerFromChild(oname);
|
||||
if (container instanceof Context) {
|
||||
((Context) container).setManager(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Realm.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeRealm(String name) throws Exception {
|
||||
|
||||
ObjectName oname = new ObjectName(name);
|
||||
// Acquire a reference to the component to be removed
|
||||
Container container = getParentContainerFromChild(oname);
|
||||
container.setRealm(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Service.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeService(String name) throws Exception {
|
||||
|
||||
if (!(container instanceof Server)) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
// Acquire a reference to the component to be removed
|
||||
ObjectName oname = new ObjectName(name);
|
||||
Service service = getService(oname);
|
||||
((Server) container).removeService(service);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing Valve.
|
||||
*
|
||||
* @param name MBean Name of the component to remove
|
||||
*
|
||||
* @exception Exception if a component cannot be removed
|
||||
*/
|
||||
public void removeValve(String name) throws Exception {
|
||||
|
||||
// Acquire a reference to the component to be removed
|
||||
ObjectName oname = new ObjectName(name);
|
||||
Container container = getParentContainerFromChild(oname);
|
||||
Valve[] valves = container.getPipeline().getValves();
|
||||
for (int i = 0; i < valves.length; i++) {
|
||||
ObjectName voname = ((JmxEnabled) valves[i]).getObjectName();
|
||||
if (voname.equals(oname)) {
|
||||
container.getPipeline().removeValve(valves[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
785
java/org/apache/catalina/mbeans/MBeanUtils.java
Normal file
785
java/org/apache/catalina/mbeans/MBeanUtils.java
Normal file
@@ -0,0 +1,785 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.DynamicMBean;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Container;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Loader;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.Server;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.catalina.UserDatabase;
|
||||
import org.apache.catalina.util.ContextName;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextEnvironment;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResource;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResourceLink;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
|
||||
/**
|
||||
* Public utility methods in support of the server side MBeans implementation.
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class MBeanUtils {
|
||||
|
||||
// ------------------------------------------------------- Static Variables
|
||||
|
||||
/**
|
||||
* The set of exceptions to the normal rules used by
|
||||
* <code>createManagedBean()</code>. The first element of each pair
|
||||
* is a class name, and the second element is the managed bean name.
|
||||
*/
|
||||
private static final String exceptions[][] = {
|
||||
{ "org.apache.catalina.users.MemoryGroup",
|
||||
"Group" },
|
||||
{ "org.apache.catalina.users.MemoryRole",
|
||||
"Role" },
|
||||
{ "org.apache.catalina.users.MemoryUser",
|
||||
"User" },
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
private static Registry registry = createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>MBeanServer</code> for this application.
|
||||
*/
|
||||
private static MBeanServer mserver = createServer();
|
||||
|
||||
|
||||
// --------------------------------------------------------- Static Methods
|
||||
|
||||
/**
|
||||
* Create and return the name of the <code>ManagedBean</code> that
|
||||
* corresponds to this Catalina component.
|
||||
*
|
||||
* @param component The component for which to create a name
|
||||
*/
|
||||
static String createManagedName(Object component) {
|
||||
|
||||
// Deal with exceptions to the standard rule
|
||||
String className = component.getClass().getName();
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
if (className.equals(exceptions[i][0])) {
|
||||
return exceptions[i][1];
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the standard transformation
|
||||
int period = className.lastIndexOf('.');
|
||||
if (period >= 0)
|
||||
className = className.substring(period + 1);
|
||||
return className;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>ContextEnvironment</code> object.
|
||||
*
|
||||
* @param environment The ContextEnvironment to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public static DynamicMBean createMBean(ContextEnvironment environment)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(environment);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(environment);
|
||||
ObjectName oname = createObjectName(domain, environment);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>ContextResource</code> object.
|
||||
*
|
||||
* @param resource The ContextResource to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public static DynamicMBean createMBean(ContextResource resource)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(resource);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(resource);
|
||||
ObjectName oname = createObjectName(domain, resource);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>ContextResourceLink</code> object.
|
||||
*
|
||||
* @param resourceLink The ContextResourceLink to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
public static DynamicMBean createMBean(ContextResourceLink resourceLink)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(resourceLink);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(resourceLink);
|
||||
ObjectName oname = createObjectName(domain, resourceLink);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>Group</code> object.
|
||||
*
|
||||
* @param group The Group to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
static DynamicMBean createMBean(Group group)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(group);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(group);
|
||||
ObjectName oname = createObjectName(domain, group);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>Role</code> object.
|
||||
*
|
||||
* @param role The Role to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
static DynamicMBean createMBean(Role role)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(role);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(role);
|
||||
ObjectName oname = createObjectName(domain, role);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>User</code> object.
|
||||
*
|
||||
* @param user The User to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
static DynamicMBean createMBean(User user)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(user);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(user);
|
||||
ObjectName oname = createObjectName(domain, user);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create, register, and return an MBean for this
|
||||
* <code>UserDatabase</code> object.
|
||||
*
|
||||
* @param userDatabase The UserDatabase to be managed
|
||||
* @return a new MBean
|
||||
* @exception Exception if an MBean cannot be created or registered
|
||||
*/
|
||||
static DynamicMBean createMBean(UserDatabase userDatabase)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(userDatabase);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
Exception e = new Exception("ManagedBean is not found with "+mname);
|
||||
throw new MBeanException(e);
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
DynamicMBean mbean = managed.createMBean(userDatabase);
|
||||
ObjectName oname = createObjectName(domain, userDatabase);
|
||||
if( mserver.isRegistered( oname )) {
|
||||
mserver.unregisterMBean(oname);
|
||||
}
|
||||
mserver.registerMBean(mbean, oname);
|
||||
return mbean;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>Service</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param environment The ContextEnvironment to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
public static ObjectName createObjectName(String domain,
|
||||
ContextEnvironment environment)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
Object container =
|
||||
environment.getNamingResources().getContainer();
|
||||
if (container instanceof Server) {
|
||||
name = new ObjectName(domain + ":type=Environment" +
|
||||
",resourcetype=Global,name=" + environment.getName());
|
||||
} else if (container instanceof Context) {
|
||||
Context context = ((Context)container);
|
||||
ContextName cn = new ContextName(context.getName(), false);
|
||||
Container host = context.getParent();
|
||||
name = new ObjectName(domain + ":type=Environment" +
|
||||
",resourcetype=Context,host=" + host.getName() +
|
||||
",context=" + cn.getDisplayName() +
|
||||
",name=" + environment.getName());
|
||||
}
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>ContextResource</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param resource The ContextResource to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
public static ObjectName createObjectName(String domain,
|
||||
ContextResource resource)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
String quotedResourceName = ObjectName.quote(resource.getName());
|
||||
Object container =
|
||||
resource.getNamingResources().getContainer();
|
||||
if (container instanceof Server) {
|
||||
name = new ObjectName(domain + ":type=Resource" +
|
||||
",resourcetype=Global,class=" + resource.getType() +
|
||||
",name=" + quotedResourceName);
|
||||
} else if (container instanceof Context) {
|
||||
Context context = ((Context)container);
|
||||
ContextName cn = new ContextName(context.getName(), false);
|
||||
Container host = context.getParent();
|
||||
name = new ObjectName(domain + ":type=Resource" +
|
||||
",resourcetype=Context,host=" + host.getName() +
|
||||
",context=" + cn.getDisplayName() +
|
||||
",class=" + resource.getType() +
|
||||
",name=" + quotedResourceName);
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>ContextResourceLink</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param resourceLink The ContextResourceLink to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
public static ObjectName createObjectName(String domain,
|
||||
ContextResourceLink resourceLink)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
String quotedResourceLinkName
|
||||
= ObjectName.quote(resourceLink.getName());
|
||||
Object container =
|
||||
resourceLink.getNamingResources().getContainer();
|
||||
if (container instanceof Server) {
|
||||
name = new ObjectName(domain + ":type=ResourceLink" +
|
||||
",resourcetype=Global" +
|
||||
",name=" + quotedResourceLinkName);
|
||||
} else if (container instanceof Context) {
|
||||
Context context = ((Context)container);
|
||||
ContextName cn = new ContextName(context.getName(), false);
|
||||
Container host = context.getParent();
|
||||
name = new ObjectName(domain + ":type=ResourceLink" +
|
||||
",resourcetype=Context,host=" + host.getName() +
|
||||
",context=" + cn.getDisplayName() +
|
||||
",name=" + quotedResourceLinkName);
|
||||
}
|
||||
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>Group</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param group The Group to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
static ObjectName createObjectName(String domain,
|
||||
Group group)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
name = new ObjectName(domain + ":type=Group,groupname=" +
|
||||
ObjectName.quote(group.getGroupname()) +
|
||||
",database=" + group.getUserDatabase().getId());
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>Loader</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param loader The Loader to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
static ObjectName createObjectName(String domain, Loader loader)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
Context context = loader.getContext();
|
||||
|
||||
ContextName cn = new ContextName(context.getName(), false);
|
||||
Container host = context.getParent();
|
||||
name = new ObjectName(domain + ":type=Loader,host=" + host.getName() +
|
||||
",context=" + cn.getDisplayName());
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>Role</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param role The Role to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
static ObjectName createObjectName(String domain, Role role)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = new ObjectName(domain + ":type=Role,rolename=" +
|
||||
ObjectName.quote(role.getRolename()) +
|
||||
",database=" + role.getUserDatabase().getId());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>User</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param user The User to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
static ObjectName createObjectName(String domain, User user)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = new ObjectName(domain + ":type=User,username=" +
|
||||
ObjectName.quote(user.getUsername()) +
|
||||
",database=" + user.getUserDatabase().getId());
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an <code>ObjectName</code> for this
|
||||
* <code>UserDatabase</code> object.
|
||||
*
|
||||
* @param domain Domain in which this name is to be created
|
||||
* @param userDatabase The UserDatabase to be named
|
||||
* @return a new object name
|
||||
* @exception MalformedObjectNameException if a name cannot be created
|
||||
*/
|
||||
static ObjectName createObjectName(String domain,
|
||||
UserDatabase userDatabase)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
ObjectName name = null;
|
||||
name = new ObjectName(domain + ":type=UserDatabase,database=" +
|
||||
userDatabase.getId());
|
||||
return name;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and configure (if necessary) and return the registry of
|
||||
* managed object descriptions.
|
||||
* @return the singleton registry
|
||||
*/
|
||||
public static synchronized Registry createRegistry() {
|
||||
if (registry == null) {
|
||||
registry = Registry.getRegistry(null, null);
|
||||
ClassLoader cl = MBeanUtils.class.getClassLoader();
|
||||
|
||||
registry.loadDescriptors("org.apache.catalina.mbeans", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.authenticator", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.core", cl);
|
||||
registry.loadDescriptors("org.apache.catalina", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.deploy", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.loader", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.realm", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.session", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.startup", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.users", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.ha", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.connector", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.valves", cl);
|
||||
registry.loadDescriptors("org.apache.catalina.storeconfig", cl);
|
||||
registry.loadDescriptors("org.apache.tomcat.util.descriptor.web", cl);
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and configure (if necessary) and return the
|
||||
* <code>MBeanServer</code> with which we will be
|
||||
* registering our <code>DynamicMBean</code> implementations.
|
||||
* @return the singleton MBean server
|
||||
*/
|
||||
public static synchronized MBeanServer createServer() {
|
||||
if (mserver == null) {
|
||||
mserver = Registry.getRegistry(null, null).getMBeanServer();
|
||||
}
|
||||
return mserver;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>ContextEnvironment</code> object.
|
||||
*
|
||||
* @param environment The ContextEnvironment to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
public static void destroyMBean(ContextEnvironment environment)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(environment);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, environment);
|
||||
if( mserver.isRegistered(oname) )
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>ContextResource</code> object.
|
||||
*
|
||||
* @param resource The ContextResource to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
public static void destroyMBean(ContextResource resource)
|
||||
throws Exception {
|
||||
|
||||
// If this is a user database resource need to destroy groups, roles,
|
||||
// users and UserDatabase mbean
|
||||
if ("org.apache.catalina.UserDatabase".equals(resource.getType())) {
|
||||
destroyMBeanUserDatabase(resource.getName());
|
||||
}
|
||||
|
||||
String mname = createManagedName(resource);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, resource);
|
||||
if( mserver.isRegistered(oname ))
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>ContextResourceLink</code> object.
|
||||
*
|
||||
* @param resourceLink The ContextResourceLink to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
public static void destroyMBean(ContextResourceLink resourceLink)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(resourceLink);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, resourceLink);
|
||||
if( mserver.isRegistered(oname) )
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>Group</code> object.
|
||||
*
|
||||
* @param group The Group to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
static void destroyMBean(Group group)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(group);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, group);
|
||||
if( mserver.isRegistered(oname) )
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>Role</code> object.
|
||||
*
|
||||
* @param role The Role to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
static void destroyMBean(Role role)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(role);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, role);
|
||||
if( mserver.isRegistered(oname) )
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for this
|
||||
* <code>User</code> object.
|
||||
*
|
||||
* @param user The User to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
static void destroyMBean(User user)
|
||||
throws Exception {
|
||||
|
||||
String mname = createManagedName(user);
|
||||
ManagedBean managed = registry.findManagedBean(mname);
|
||||
if (managed == null) {
|
||||
return;
|
||||
}
|
||||
String domain = managed.getDomain();
|
||||
if (domain == null)
|
||||
domain = mserver.getDefaultDomain();
|
||||
ObjectName oname = createObjectName(domain, user);
|
||||
if( mserver.isRegistered(oname) )
|
||||
mserver.unregisterMBean(oname);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deregister the MBean for the
|
||||
* <code>UserDatabase</code> object with this name.
|
||||
*
|
||||
* @param userDatabase The UserDatabase to be managed
|
||||
*
|
||||
* @exception Exception if an MBean cannot be deregistered
|
||||
*/
|
||||
static void destroyMBeanUserDatabase(String userDatabase)
|
||||
throws Exception {
|
||||
|
||||
ObjectName query = null;
|
||||
Set<ObjectName> results = null;
|
||||
|
||||
// Groups
|
||||
query = new ObjectName(
|
||||
"Users:type=Group,database=" + userDatabase + ",*");
|
||||
results = mserver.queryNames(query, null);
|
||||
for(ObjectName result : results) {
|
||||
mserver.unregisterMBean(result);
|
||||
}
|
||||
|
||||
// Roles
|
||||
query = new ObjectName(
|
||||
"Users:type=Role,database=" + userDatabase + ",*");
|
||||
results = mserver.queryNames(query, null);
|
||||
for(ObjectName result : results) {
|
||||
mserver.unregisterMBean(result);
|
||||
}
|
||||
|
||||
// Users
|
||||
query = new ObjectName(
|
||||
"Users:type=User,database=" + userDatabase + ",*");
|
||||
results = mserver.queryNames(query, null);
|
||||
for(ObjectName result : results) {
|
||||
mserver.unregisterMBean(result);
|
||||
}
|
||||
|
||||
// The database itself
|
||||
ObjectName db = new ObjectName(
|
||||
"Users:type=UserDatabase,database=" + userDatabase);
|
||||
if( mserver.isRegistered(db) ) {
|
||||
mserver.unregisterMBean(db);
|
||||
}
|
||||
}
|
||||
}
|
||||
332
java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java
Normal file
332
java/org/apache/catalina/mbeans/MemoryUserDatabaseMBean.java
Normal file
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.catalina.UserDatabase;
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.catalina.users.MemoryUserDatabase</code> component.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class MemoryUserDatabaseMBean extends BaseModelMBean {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing this MBean.
|
||||
*/
|
||||
protected final ManagedBean managed = registry.findManagedBean("MemoryUserDatabase");
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing Group MBeans.
|
||||
*/
|
||||
protected final ManagedBean managedGroup = registry.findManagedBean("Group");
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing Group MBeans.
|
||||
*/
|
||||
protected final ManagedBean managedRole = registry.findManagedBean("Role");
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing User MBeans.
|
||||
*/
|
||||
protected final ManagedBean managedUser = registry.findManagedBean("User");
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Attributes
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all groups defined in this database.
|
||||
*/
|
||||
public String[] getGroups() {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<Group> groups = database.getGroups();
|
||||
while (groups.hasNext()) {
|
||||
Group group = groups.next();
|
||||
results.add(findGroup(group.getGroupname()));
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all roles defined in this database.
|
||||
*/
|
||||
public String[] getRoles() {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<Role> roles = database.getRoles();
|
||||
while (roles.hasNext()) {
|
||||
Role role = roles.next();
|
||||
results.add(findRole(role.getRolename()));
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all users defined in this database.
|
||||
*/
|
||||
public String[] getUsers() {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<User> users = database.getUsers();
|
||||
while (users.hasNext()) {
|
||||
User user = users.next();
|
||||
results.add(findUser(user.getUsername()));
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Operations
|
||||
|
||||
/**
|
||||
* Create a new Group and return the corresponding MBean Name.
|
||||
*
|
||||
* @param groupname Group name of the new group
|
||||
* @param description Description of the new group
|
||||
* @return the new group object name
|
||||
*/
|
||||
public String createGroup(String groupname, String description) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Group group = database.createGroup(groupname, description);
|
||||
try {
|
||||
MBeanUtils.createMBean(group);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception creating group [" + groupname + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
return findGroup(groupname);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new Role and return the corresponding MBean Name.
|
||||
*
|
||||
* @param rolename Group name of the new group
|
||||
* @param description Description of the new group
|
||||
* @return the new role object name
|
||||
*/
|
||||
public String createRole(String rolename, String description) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Role role = database.createRole(rolename, description);
|
||||
try {
|
||||
MBeanUtils.createMBean(role);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception creating role [" + rolename + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
return findRole(rolename);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new User and return the corresponding MBean Name.
|
||||
*
|
||||
* @param username User name of the new user
|
||||
* @param password Password for the new user
|
||||
* @param fullName Full name for the new user
|
||||
* @return the new user object name
|
||||
*/
|
||||
public String createUser(String username, String password, String fullName) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
User user = database.createUser(username, password, fullName);
|
||||
try {
|
||||
MBeanUtils.createMBean(user);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception creating user [" + username + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
return findUser(username);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the MBean Name for the specified group name (if any);
|
||||
* otherwise return <code>null</code>.
|
||||
*
|
||||
* @param groupname Group name to look up
|
||||
* @return the group object name
|
||||
*/
|
||||
public String findGroup(String groupname) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Group group = database.findGroup(groupname);
|
||||
if (group == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ObjectName oname = MBeanUtils.createObjectName(managedGroup.getDomain(), group);
|
||||
return oname.toString();
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for group [" + groupname + "]");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the MBean Name for the specified role name (if any);
|
||||
* otherwise return <code>null</code>.
|
||||
*
|
||||
* @param rolename Role name to look up
|
||||
* @return the role object name
|
||||
*/
|
||||
public String findRole(String rolename) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Role role = database.findRole(rolename);
|
||||
if (role == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ObjectName oname = MBeanUtils.createObjectName(managedRole.getDomain(), role);
|
||||
return oname.toString();
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for role [" + rolename + "]");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the MBean Name for the specified user name (if any);
|
||||
* otherwise return <code>null</code>.
|
||||
*
|
||||
* @param username User name to look up
|
||||
* @return the user object name
|
||||
*/
|
||||
public String findUser(String username) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
User user = database.findUser(username);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ObjectName oname = MBeanUtils.createObjectName(managedUser.getDomain(), user);
|
||||
return oname.toString();
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for user [" + username + "]");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing group and destroy the corresponding MBean.
|
||||
*
|
||||
* @param groupname Group name to remove
|
||||
*/
|
||||
public void removeGroup(String groupname) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Group group = database.findGroup(groupname);
|
||||
if (group == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
MBeanUtils.destroyMBean(group);
|
||||
database.removeGroup(group);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception destroying group [" + groupname + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing role and destroy the corresponding MBean.
|
||||
*
|
||||
* @param rolename Role name to remove
|
||||
*/
|
||||
public void removeRole(String rolename) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
Role role = database.findRole(rolename);
|
||||
if (role == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
MBeanUtils.destroyMBean(role);
|
||||
database.removeRole(role);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception destroying role [" + rolename + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove an existing user and destroy the corresponding MBean.
|
||||
*
|
||||
* @param username User name to remove
|
||||
*/
|
||||
public void removeUser(String username) {
|
||||
UserDatabase database = (UserDatabase) this.resource;
|
||||
User user = database.findUser(username);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
MBeanUtils.destroyMBean(user);
|
||||
database.removeUser(user);
|
||||
} catch (Exception e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Exception destroying user [" + username + "] MBean");
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
}
|
||||
283
java/org/apache/catalina/mbeans/NamingResourcesMBean.java
Normal file
283
java/org/apache/catalina/mbeans/NamingResourcesMBean.java
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.deploy.NamingResourcesImpl;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextEnvironment;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResource;
|
||||
import org.apache.tomcat.util.descriptor.web.ContextResourceLink;
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.catalina.deploy.NamingResourcesImpl</code> component.</p>
|
||||
*
|
||||
* @author Amy Roh
|
||||
*/
|
||||
public class NamingResourcesMBean extends BaseModelMBean {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing this MBean.
|
||||
*/
|
||||
protected final ManagedBean managed = registry.findManagedBean("NamingResources");
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Attributes
|
||||
|
||||
/**
|
||||
* Return the MBean Names of the set of defined environment entries for
|
||||
* this web application
|
||||
* @return an array of object names as strings
|
||||
*/
|
||||
public String[] getEnvironments() {
|
||||
ContextEnvironment[] envs = ((NamingResourcesImpl)this.resource).findEnvironments();
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (int i = 0; i < envs.length; i++) {
|
||||
try {
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException (
|
||||
"Cannot create object name for environment " + envs[i]);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the MBean Names of all the defined resource references for this
|
||||
* application.
|
||||
* @return an array of object names as strings
|
||||
*/
|
||||
public String[] getResources() {
|
||||
ContextResource[] resources = ((NamingResourcesImpl)this.resource).findResources();
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
try {
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resources[i]);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for resource " + resources[i]);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the MBean Names of all the defined resource link references for
|
||||
* this application.
|
||||
* @return an array of object names as strings
|
||||
*/
|
||||
public String[] getResourceLinks() {
|
||||
ContextResourceLink[] resourceLinks =
|
||||
((NamingResourcesImpl)this.resource).findResourceLinks();
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
for (int i = 0; i < resourceLinks.length; i++) {
|
||||
try {
|
||||
ObjectName oname =
|
||||
MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException(
|
||||
"Cannot create object name for resource " + resourceLinks[i]);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Operations
|
||||
|
||||
/**
|
||||
* Add an environment entry for this web application.
|
||||
*
|
||||
* @param envName New environment entry name
|
||||
* @param type The type of the new environment entry
|
||||
* @param value The value of the new environment entry
|
||||
* @return the object name of the new environment entry
|
||||
* @throws MalformedObjectNameException if the object name was invalid
|
||||
*/
|
||||
public String addEnvironment(String envName, String type, String value)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return null;
|
||||
}
|
||||
ContextEnvironment env = nresources.findEnvironment(envName);
|
||||
if (env != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid environment name - already exists '" + envName + "'");
|
||||
}
|
||||
env = new ContextEnvironment();
|
||||
env.setName(envName);
|
||||
env.setType(type);
|
||||
env.setValue(value);
|
||||
nresources.addEnvironment(env);
|
||||
|
||||
// Return the corresponding MBean name
|
||||
ManagedBean managed = registry.findManagedBean("ContextEnvironment");
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), env);
|
||||
return oname.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a resource reference for this web application.
|
||||
*
|
||||
* @param resourceName New resource reference name
|
||||
* @param type New resource reference type
|
||||
* @return the object name of the new resource
|
||||
* @throws MalformedObjectNameException if the object name was invalid
|
||||
*/
|
||||
public String addResource(String resourceName, String type)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return null;
|
||||
}
|
||||
ContextResource resource = nresources.findResource(resourceName);
|
||||
if (resource != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid resource name - already exists'" + resourceName + "'");
|
||||
}
|
||||
resource = new ContextResource();
|
||||
resource.setName(resourceName);
|
||||
resource.setType(type);
|
||||
nresources.addResource(resource);
|
||||
|
||||
// Return the corresponding MBean name
|
||||
ManagedBean managed = registry.findManagedBean("ContextResource");
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resource);
|
||||
return oname.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a resource link reference for this web application.
|
||||
*
|
||||
* @param resourceLinkName New resource link reference name
|
||||
* @param type New resource link reference type
|
||||
* @return the object name of the new resource link
|
||||
* @throws MalformedObjectNameException if the object name was invalid
|
||||
*/
|
||||
public String addResourceLink(String resourceLinkName, String type)
|
||||
throws MalformedObjectNameException {
|
||||
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return null;
|
||||
}
|
||||
ContextResourceLink resourceLink =
|
||||
nresources.findResourceLink(resourceLinkName);
|
||||
if (resourceLink != null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid resource link name - already exists'" + resourceLinkName + "'");
|
||||
}
|
||||
resourceLink = new ContextResourceLink();
|
||||
resourceLink.setName(resourceLinkName);
|
||||
resourceLink.setType(type);
|
||||
nresources.addResourceLink(resourceLink);
|
||||
|
||||
// Return the corresponding MBean name
|
||||
ManagedBean managed = registry.findManagedBean("ContextResourceLink");
|
||||
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
|
||||
return oname.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove any environment entry with the specified name.
|
||||
*
|
||||
* @param envName Name of the environment entry to remove
|
||||
*/
|
||||
public void removeEnvironment(String envName) {
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return;
|
||||
}
|
||||
ContextEnvironment env = nresources.findEnvironment(envName);
|
||||
if (env == null) {
|
||||
throw new IllegalArgumentException("Invalid environment name '" + envName + "'");
|
||||
}
|
||||
nresources.removeEnvironment(envName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove any resource reference with the specified name.
|
||||
*
|
||||
* @param resourceName Name of the resource reference to remove
|
||||
*/
|
||||
public void removeResource(String resourceName) {
|
||||
resourceName = ObjectName.unquote(resourceName);
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return;
|
||||
}
|
||||
ContextResource resource = nresources.findResource(resourceName);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("Invalid resource name '" + resourceName + "'");
|
||||
}
|
||||
nresources.removeResource(resourceName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove any resource link reference with the specified name.
|
||||
*
|
||||
* @param resourceLinkName Name of the resource link reference to remove
|
||||
*/
|
||||
public void removeResourceLink(String resourceLinkName) {
|
||||
resourceLinkName = ObjectName.unquote(resourceLinkName);
|
||||
NamingResourcesImpl nresources = (NamingResourcesImpl) this.resource;
|
||||
if (nresources == null) {
|
||||
return;
|
||||
}
|
||||
ContextResourceLink resourceLink = nresources.findResourceLink(resourceLinkName);
|
||||
if (resourceLink == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid resource Link name '" + resourceLinkName + "'");
|
||||
}
|
||||
nresources.removeResourceLink(resourceLinkName);
|
||||
}
|
||||
}
|
||||
43
java/org/apache/catalina/mbeans/RoleMBean.java
Normal file
43
java/org/apache/catalina/mbeans/RoleMBean.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.catalina.Role</code> component.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class RoleMBean extends BaseModelMBean {
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing this MBean.
|
||||
*/
|
||||
protected final ManagedBean managed = registry.findManagedBean("Role");
|
||||
}
|
||||
117
java/org/apache/catalina/mbeans/ServiceMBean.java
Normal file
117
java/org/apache/catalina/mbeans/ServiceMBean.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import javax.management.MBeanException;
|
||||
|
||||
import org.apache.catalina.Executor;
|
||||
import org.apache.catalina.Service;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
|
||||
public class ServiceMBean extends BaseCatalinaMBean<Service> {
|
||||
|
||||
/**
|
||||
* Add a new Connector to the set of defined Connectors, and associate it
|
||||
* with this Service's Container.
|
||||
*
|
||||
* @param address The IP address on which to bind
|
||||
* @param port TCP port number to listen on
|
||||
* @param isAjp Create a AJP/1.3 Connector
|
||||
* @param isSSL Create a secure Connector
|
||||
*
|
||||
* @throws MBeanException error creating the connector
|
||||
*/
|
||||
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
|
||||
|
||||
Service service = doGetManagedResource();
|
||||
String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
|
||||
Connector connector = new Connector(protocol);
|
||||
if ((address!=null) && (address.length()>0)) {
|
||||
connector.setProperty("address", address);
|
||||
}
|
||||
connector.setPort(port);
|
||||
connector.setSecure(isSSL);
|
||||
connector.setScheme(isSSL ? "https" : "http");
|
||||
|
||||
service.addConnector(connector);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a named executor to the service
|
||||
* @param type Classname of the Executor to be added
|
||||
* @throws MBeanException error creating the executor
|
||||
*/
|
||||
public void addExecutor(String type) throws MBeanException {
|
||||
Service service = doGetManagedResource();
|
||||
Executor executor = (Executor) newInstance(type);
|
||||
service.addExecutor(executor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find and return the set of Connectors associated with this Service.
|
||||
* @return an array of string representations of the connectors
|
||||
* @throws MBeanException error accessing the associated service
|
||||
*/
|
||||
public String[] findConnectors() throws MBeanException {
|
||||
|
||||
Service service = doGetManagedResource();
|
||||
|
||||
Connector[] connectors = service.findConnectors();
|
||||
String[] str = new String[connectors.length];
|
||||
|
||||
for(int i = 0; i < connectors.length; i++) {
|
||||
str[i] = connectors[i].toString();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all executors.
|
||||
* @return an array of string representations of the executors
|
||||
* @throws MBeanException error accessing the associated service
|
||||
*/
|
||||
public String[] findExecutors() throws MBeanException {
|
||||
|
||||
Service service = doGetManagedResource();
|
||||
|
||||
Executor[] executors = service.findExecutors();
|
||||
String[] str = new String[executors.length];
|
||||
|
||||
for(int i = 0; i < executors.length; i++){
|
||||
str[i] = executors[i].toString();
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves executor by name
|
||||
* @param name Name of the executor to be retrieved
|
||||
* @return a string representation of the executor
|
||||
* @throws MBeanException error accessing the associated service
|
||||
*/
|
||||
public String getExecutor(String name) throws MBeanException{
|
||||
Service service = doGetManagedResource();
|
||||
Executor executor = service.getExecutor(name);
|
||||
return executor.toString();
|
||||
}
|
||||
}
|
||||
186
java/org/apache/catalina/mbeans/UserMBean.java
Normal file
186
java/org/apache/catalina/mbeans/UserMBean.java
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.catalina.mbeans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.catalina.Group;
|
||||
import org.apache.catalina.Role;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.tomcat.util.modeler.BaseModelMBean;
|
||||
import org.apache.tomcat.util.modeler.ManagedBean;
|
||||
import org.apache.tomcat.util.modeler.Registry;
|
||||
|
||||
/**
|
||||
* <p>A <strong>ModelMBean</strong> implementation for the
|
||||
* <code>org.apache.catalina.User</code> component.</p>
|
||||
*
|
||||
* @author Craig R. McClanahan
|
||||
*/
|
||||
public class UserMBean extends BaseModelMBean {
|
||||
|
||||
|
||||
// ----------------------------------------------------- Instance Variables
|
||||
|
||||
/**
|
||||
* The configuration information registry for our managed beans.
|
||||
*/
|
||||
protected final Registry registry = MBeanUtils.createRegistry();
|
||||
|
||||
|
||||
/**
|
||||
* The <code>ManagedBean</code> information describing this MBean.
|
||||
*/
|
||||
protected final ManagedBean managed = registry.findManagedBean("User");
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Attributes
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all groups this user is a member of.
|
||||
*/
|
||||
public String[] getGroups() {
|
||||
|
||||
User user = (User) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<Group> groups = user.getGroups();
|
||||
while (groups.hasNext()) {
|
||||
Group group = null;
|
||||
try {
|
||||
group = groups.next();
|
||||
ObjectName oname =
|
||||
MBeanUtils.createObjectName(managed.getDomain(), group);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException
|
||||
("Cannot create object name for group " + group);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the MBean Names of all roles assigned to this user.
|
||||
*/
|
||||
public String[] getRoles() {
|
||||
|
||||
User user = (User) this.resource;
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
Iterator<Role> roles = user.getRoles();
|
||||
while (roles.hasNext()) {
|
||||
Role role = null;
|
||||
try {
|
||||
role = roles.next();
|
||||
ObjectName oname =
|
||||
MBeanUtils.createObjectName(managed.getDomain(), role);
|
||||
results.add(oname.toString());
|
||||
} catch (MalformedObjectNameException e) {
|
||||
IllegalArgumentException iae = new IllegalArgumentException
|
||||
("Cannot create object name for role " + role);
|
||||
iae.initCause(e);
|
||||
throw iae;
|
||||
}
|
||||
}
|
||||
return results.toArray(new String[results.size()]);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------- Operations
|
||||
|
||||
/**
|
||||
* Add a new {@link Group} to those this user belongs to.
|
||||
*
|
||||
* @param groupname Group name of the new group
|
||||
*/
|
||||
public void addGroup(String groupname) {
|
||||
|
||||
User user = (User) this.resource;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
Group group = user.getUserDatabase().findGroup(groupname);
|
||||
if (group == null) {
|
||||
throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
|
||||
}
|
||||
user.addGroup(group);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new {@link Role} to those this user belongs to.
|
||||
*
|
||||
* @param rolename Role name of the new role
|
||||
*/
|
||||
public void addRole(String rolename) {
|
||||
|
||||
User user = (User) this.resource;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
Role role = user.getUserDatabase().findRole(rolename);
|
||||
if (role == null) {
|
||||
throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
|
||||
}
|
||||
user.addRole(role);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a {@link Group} from those this user belongs to.
|
||||
*
|
||||
* @param groupname Group name of the old group
|
||||
*/
|
||||
public void removeGroup(String groupname) {
|
||||
|
||||
User user = (User) this.resource;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
Group group = user.getUserDatabase().findGroup(groupname);
|
||||
if (group == null) {
|
||||
throw new IllegalArgumentException("Invalid group name '" + groupname + "'");
|
||||
}
|
||||
user.removeGroup(group);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove a {@link Role} from those this user belongs to.
|
||||
*
|
||||
* @param rolename Role name of the old role
|
||||
*/
|
||||
public void removeRole(String rolename) {
|
||||
|
||||
User user = (User) this.resource;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
Role role = user.getUserDatabase().findRole(rolename);
|
||||
if (role == null) {
|
||||
throw new IllegalArgumentException("Invalid role name '" + rolename + "'");
|
||||
}
|
||||
user.removeRole(role);
|
||||
}
|
||||
}
|
||||
323
java/org/apache/catalina/mbeans/mbeans-descriptors.xml
Normal file
323
java/org/apache/catalina/mbeans/mbeans-descriptors.xml
Normal file
@@ -0,0 +1,323 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<mbeans-descriptors>
|
||||
|
||||
<mbean name="MBeanFactory"
|
||||
type="org.apache.catalina.mbeans.MBeanFactory"
|
||||
description="Factory for MBeans and corresponding components"
|
||||
domain="Catalina">
|
||||
|
||||
<!-- IMPLEMENTATION NOTE - all of the createXxxxx methods create a new -->
|
||||
<!-- component and attach it to Catalina's component tree. The return -->
|
||||
<!-- value is the object name of the corresponding MBean for the new -->
|
||||
<!-- component. -->
|
||||
|
||||
<operation name="createAjpConnector"
|
||||
description="Create a new AjpConnector"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="address"
|
||||
description="The IP address on which to bind"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="port"
|
||||
description="TCP port number to listen on"
|
||||
type="int"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createDataSourceRealm"
|
||||
description="Create a new DataSource Realm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="dataSourceName"
|
||||
description="The JNDI named JDBC DataSource"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="roleNameCol"
|
||||
description="The column in the user role table that names a role"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="userCredCol"
|
||||
description="The column in the user table that holds the user's
|
||||
credentials"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="userNameCol"
|
||||
description="The column in the user table that holds the user's
|
||||
username"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="userRoleTable"
|
||||
description="The table that holds the relation between user's and
|
||||
roles"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="userTable"
|
||||
description="The table that holds user data"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createHttpConnector"
|
||||
description="Create a new HttpConnector"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="address"
|
||||
description="The IP address on which to bind"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="port"
|
||||
description="TCP port number to listen on"
|
||||
type="int"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createHttpsConnector"
|
||||
description="Create a new HttpsConnector"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="address"
|
||||
description="The IP address on which to bind"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="port"
|
||||
description="TCP port number to listen on"
|
||||
type="int"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createJDBCRealm"
|
||||
description="Create a new JDBC Realm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createJNDIRealm"
|
||||
description="Create a new JNDI Realm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createMemoryRealm"
|
||||
description="Create a new Memory Realm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createUserDatabaseRealm"
|
||||
description="Create a new UserDatabaseRealm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="resourceName"
|
||||
description="Global JNDI resource name of the associated"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createStandardContext"
|
||||
description="Create a new StandardContext"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="path"
|
||||
description="The context path for this Context"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="docBase"
|
||||
description="Document base directory (or WAR) for this Context"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createStandardServiceEngine"
|
||||
description="Create a new StandardService and StandardEngine"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="domain"
|
||||
description="Domain used for MBeans associated with the new Service"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="defaultHost"
|
||||
description="Default host name for the new Engine"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="baseDir"
|
||||
description="Base directory value for the new Engine"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createStandardHost"
|
||||
description="Create a new StandardHost"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="name"
|
||||
description="Unique name of this Host"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="appBase"
|
||||
description="set host deployment directory"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="autoDeploy"
|
||||
description="The auto deploy flag for this Host"
|
||||
type="boolean"/>
|
||||
<parameter name="deployOnStartup"
|
||||
description="The deploy on startup flag for this Host"
|
||||
type="boolean"/>
|
||||
<parameter name="deployXML"
|
||||
description="deploy Context XML config files property"
|
||||
type="boolean"/>
|
||||
<parameter name="unpackWARs"
|
||||
description="Unpack WARs property"
|
||||
type="boolean"/>
|
||||
</operation>
|
||||
|
||||
|
||||
<operation name="createStandardManager"
|
||||
description="Create a new StandardManager"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createUserDatabaseRealm"
|
||||
description="Create a new UserDatabase Realm"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="resourceName"
|
||||
description="Global JNDI resource name of our UserDatabase instance"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createValve"
|
||||
description="Create a new Valve for the given Container"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="className"
|
||||
description="Fully qualified class name of the Valve to create"
|
||||
type="java.lang.String"/>
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="createWebappLoader"
|
||||
description="Create a new Web Application Loader"
|
||||
impact="ACTION"
|
||||
returnType="java.lang.String">
|
||||
<parameter name="parent"
|
||||
description="MBean Name of the associated parent component"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<!-- IMPLEMENTATION NOTE - all of the removeXxxxx methods cause the -->
|
||||
<!-- corresponding Catalina component (and any related child -->
|
||||
<!-- components to be stopped (if necessary) and removed, and the -->
|
||||
<!-- corresponding MBeans to be destroyed. -->
|
||||
|
||||
<operation name="removeConnector"
|
||||
description="Remove an existing Connector"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeContext"
|
||||
description="Remove an existing Context"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeHost"
|
||||
description="Remove an existing Host"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeLoader"
|
||||
description="Remove an existing Loader"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeManager"
|
||||
description="Remove an existing Manager"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeRealm"
|
||||
description="Remove an existing Realm"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeService"
|
||||
description="Remove an existing Service"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
<operation name="removeValve"
|
||||
description="Remove an existing Valve"
|
||||
impact="ACTION"
|
||||
returnType="void">
|
||||
<parameter name="name"
|
||||
description="MBean Name of the component to be removed"
|
||||
type="java.lang.String"/>
|
||||
</operation>
|
||||
|
||||
</mbean>
|
||||
|
||||
</mbeans-descriptors>
|
||||
Reference in New Issue
Block a user