Skip to content

Commit

Permalink
[WFLY-490] Update the current management model to JMX integration to …
Browse files Browse the repository at this point in the history
…hide the entire management model representation if access is prevented.

(Previously errors were being reported to the client and remaining functionality of JMX clients such as jconsole was subsequently broken)
  • Loading branch information
darranl authored and bstansberry committed Aug 7, 2013
1 parent 3124219 commit ea95a10
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import static org.jboss.as.jmx.JmxMessages.MESSAGES;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -135,6 +136,9 @@ public boolean onResource(PathAddress address) {

@Override
public Set<ObjectInstance> getResult() {
if (set.size() == 1 && set.contains(ModelControllerMBeanHelper.createRootObjectName(domain))) {
return Collections.emptySet();
}
return set;
}
}).iterate();
Expand All @@ -159,6 +163,9 @@ public boolean onResource(PathAddress address) {

@Override
public Set<ObjectName> getResult() {
if (set.size() == 1 && set.contains(ModelControllerMBeanHelper.createRootObjectName(domain))) {
return Collections.emptySet();
}
return set;
}
}).iterate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@

/**
* An MBeanServer wrapper that exposes the ModelController via JMX.
* <p/>
* <b>Note:</b> This only gets invoked when connecting via JConsole
* if you connect via a remote process URL. If you connect to a 'Local Process' the platform MBean
* Server is used directly.
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
public class SecurityActions {
class SecurityActions {
static ClassLoader getClassLoader(final Class<?> clazz) {
return ! WildFlySecurityManager.isChecking() ? clazz.getClassLoader() : doPrivileged(new GetClassLoaderAction(clazz));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,35 @@

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jboss.as.controller.ModelController;
import org.jboss.as.controller.ModelController.OperationTransactionControl;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProxyController;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.UnauthorizedException;
import org.jboss.as.controller.access.constraint.management.AccessConstraintDefinition;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.registry.AliasEntry;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.controller.registry.OperationEntry.Flag;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.ServerMessages;
import org.jboss.dmr.ModelNode;

/**
* Ugly hack to be able to get the root resurce and registration.
* Ugly hack to be able to get the root resource and registration.
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
Expand Down Expand Up @@ -68,7 +82,11 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
if (threadResource == null || threadResource != ResourceAndRegistration.NULL) {
throw ServerMessages.MESSAGES.internalUseOnly();
}
try {
resource.set(new ResourceAndRegistration(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true), context.getResourceRegistration()));
} catch (UnauthorizedException e) {
resource.set(new ResourceAndRegistration(Resource.Factory.create(), new EmptyResourceRegistration()));
}
context.stepCompleted();
}

Expand Down Expand Up @@ -105,4 +123,98 @@ public ImmutableManagementResourceRegistration getRegistration() {
return registry;
}
}

private static class EmptyResourceRegistration implements ImmutableManagementResourceRegistration {

@Override
public boolean isRuntimeOnly() {
return false;
}

@Override
public boolean isRemote() {
return false;
}

@Override
public boolean isAlias() {
return false;
}

@Override
public AliasEntry getAliasEntry() {
return null;
}

@Override
public OperationStepHandler getOperationHandler(PathAddress address, String operationName) {
return null;
}

@Override
public DescriptionProvider getOperationDescription(PathAddress address, String operationName) {
return null;
}

@Override
public Set<Flag> getOperationFlags(PathAddress address, String operationName) {
return null;
}

@Override
public OperationEntry getOperationEntry(PathAddress address, String operationName) {
return null;
}

@Override
public Set<String> getAttributeNames(PathAddress address) {
return Collections.emptySet();
}

@Override
public AttributeAccess getAttributeAccess(PathAddress address, String attributeName) {
return null;
}

@Override
public Set<String> getChildNames(PathAddress address) {
return Collections.emptySet();
}

@Override
public Set<PathElement> getChildAddresses(PathAddress address) {
return Collections.emptySet();
}

@Override
public DescriptionProvider getModelDescription(PathAddress address) {
return null;
}

@Override
public Map<String, OperationEntry> getOperationDescriptions(PathAddress address, boolean inherited) {
return Collections.emptyMap();
}

@Override
public ProxyController getProxyController(PathAddress address) {
return null;
}

@Override
public Set<ProxyController> getProxyControllers(PathAddress address) {
return Collections.emptySet();
}

@Override
public ImmutableManagementResourceRegistration getSubModel(PathAddress address) {
return null;
}

@Override
public List<AccessConstraintDefinition> getAccessConstraints() {
return Collections.emptyList();
}

}
}

0 comments on commit ea95a10

Please sign in to comment.