This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

View 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);
}
}
}

View 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();
}
}

View 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));
}
}

View 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()]);
}
}

View 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);
}
}

View 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;
}
}

View 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);
}
}

View 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);
}
}

View File

@@ -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");
}
}
}

View 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);
}
}

File diff suppressed because it is too large Load Diff

View 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.

View 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

View 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

View 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にのみ追加できます。

View 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=매니저 구성요소들은 컨텍스트들에만 추가될 수 있습니다.

View File

@@ -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无效

View 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));
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View 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;
}
}
}

View 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);
}
}

View 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");
}

View 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();
}
}

View 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);
}
}

View 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>