Skip to content

Commit

Permalink
[WFLY-490] Make JMX aware that the audit log resources were moved to …
Browse files Browse the repository at this point in the history
…/core-service=management/access=audit
  • Loading branch information
kabir authored and bstansberry committed Aug 14, 2013
1 parent 9288a79 commit 26f2ac1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.core-security"/>
<module name="org.jboss.as.domain-management"/>
<module name="org.jboss.as.network"/>
<module name="org.jboss.as.remoting" />
<module name="org.wildfly.security.manager"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jboss.as.controller.audit.ManagedAuditLogger;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.domain.management.CoreManagementResourceDefinition;
import org.jboss.as.domain.management.audit.AccessAuditResourceDefinition;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
Expand Down Expand Up @@ -121,6 +122,7 @@ protected void rollbackRuntime(OperationContext context, ModelNode operation, Mo

private boolean lookForHandler(OperationContext context, String name) {
PathAddress addr = PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT);
PathAddress referenceAddress = addr.append(FILE_HANDLER, name);
final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
Expand Down
34 changes: 14 additions & 20 deletions jmx/src/test/java/org/jboss/as/jmx/JMXSubsystemTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.transform.OperationTransformer.TransformedOperation;
import org.jboss.as.domain.management.CoreManagementResourceDefinition;
import org.jboss.as.domain.management.audit.AccessAuditResourceDefinition;
import org.jboss.as.model.test.FailedOperationTransformationConfig;
import org.jboss.as.model.test.FailedOperationTransformationConfig.AttributesPathAddressConfig;
Expand Down Expand Up @@ -517,20 +518,7 @@ public void testParseAndMarshallModelWithAuditLogAndHandlerReferences() throws E
" </audit-log>" +
"</subsystem>";

AdditionalInitialization additionalInit = new BaseAdditionalInitalization() {

@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource,
ManagementResourceRegistration rootRegistration) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration);

Resource auditLog = Resource.Factory.create();
rootResource.registerChild(AccessAuditResourceDefinition.PATH_ELEMENT, auditLog);
Resource testHandler = Resource.Factory.create();
testHandler.getModel().setEmptyObject();
auditLog.registerChild(PathElement.pathElement(FILE_HANDLER, "test"), testHandler);
}
};
AdditionalInitialization additionalInit = new AuditLogInitialization();

KernelServices servicesA = createKernelServicesBuilder(additionalInit).setSubsystemXml(subsystemXml).build();
Assert.assertTrue(servicesA.isSuccessfulBoot());
Expand Down Expand Up @@ -937,28 +925,34 @@ protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegis
ManagementResourceRegistration rootRegistration) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration);

Resource auditLogResource = Resource.Factory.create();
rootResource.registerChild(AccessAuditResourceDefinition.PATH_ELEMENT, auditLogResource);
Resource coreManagement = Resource.Factory.create();
rootResource.registerChild(CoreManagementResourceDefinition.PATH_ELEMENT, coreManagement);
Resource auditLog = Resource.Factory.create();
coreManagement.registerChild(AccessAuditResourceDefinition.PATH_ELEMENT, auditLog);

Resource testFileHandler = Resource.Factory.create();
testFileHandler.getModel().setEmptyObject();
auditLogResource.registerChild(PathElement.pathElement(FILE_HANDLER, "test"), testFileHandler);
auditLog.registerChild(PathElement.pathElement(FILE_HANDLER, "test"), testFileHandler);
}
}

private static class ManagementAuditLogInitialization extends AdditionalInitialization.ManagementAdditionalInitialization {

private static final long serialVersionUID = 1L;

@Override
protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource,
ManagementResourceRegistration rootRegistration) {
super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration);

Resource auditLogResource = Resource.Factory.create();
rootResource.registerChild(AccessAuditResourceDefinition.PATH_ELEMENT, auditLogResource);
Resource coreManagement = Resource.Factory.create();
rootResource.registerChild(CoreManagementResourceDefinition.PATH_ELEMENT, coreManagement);
Resource auditLog = Resource.Factory.create();
coreManagement.registerChild(AccessAuditResourceDefinition.PATH_ELEMENT, auditLog);

Resource testFileHandler = Resource.Factory.create();
testFileHandler.getModel().setEmptyObject();
auditLogResource.registerChild(PathElement.pathElement(FILE_HANDLER, "test"), testFileHandler);
auditLog.registerChild(PathElement.pathElement(FILE_HANDLER, "test"), testFileHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.RunningModeControl;
import org.jboss.as.controller.access.DelegatingConfigurableAuthorizer;
import org.jboss.as.controller.audit.ManagedAuditLogger;
import org.jboss.as.controller.audit.ManagedAuditLoggerImpl;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
Expand All @@ -60,8 +61,9 @@
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.services.path.PathManagerService;
import org.jboss.as.controller.services.path.PathResourceDefinition;
import org.jboss.as.domain.management.audit.AuditLogLoggerResourceDefinition;
import org.jboss.as.domain.management.CoreManagementResourceDefinition;
import org.jboss.as.domain.management.audit.AccessAuditResourceDefinition;
import org.jboss.as.domain.management.audit.AuditLogLoggerResourceDefinition;
import org.jboss.as.domain.management.audit.EnvironmentNameReader;
import org.jboss.as.jmx.ExposeModelResourceResolved;
import org.jboss.as.jmx.JMXExtension;
Expand Down Expand Up @@ -103,9 +105,10 @@ public class JmxAuditLogHandlerTestCase extends AbstractControllerTestBase {
private final List<ModelNode> bootOperations = new ArrayList<ModelNode>();

public JmxAuditLogHandlerTestCase() {
bootOperations.add(Util.createAddOperation(PathAddress.pathAddress(AccessAuditResourceDefinition.PATH_ELEMENT)));
bootOperations.add(Util.createAddOperation(PathAddress.pathAddress(CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuditResourceDefinition.PATH_ELEMENT)));
ModelNode add = Util.createAddOperation(
PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT,
PathElement.pathElement(ModelDescriptionConstants.JSON_FORMATTER, "test-formatter")));
bootOperations.add(add);
Expand All @@ -114,6 +117,7 @@ public JmxAuditLogHandlerTestCase() {

add = Util.createAddOperation(
PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT,
AuditLogLoggerResourceDefinition.PATH_ELEMENT));
add.get(ModelDescriptionConstants.LOG_READ_ONLY).set(true);
Expand Down Expand Up @@ -618,6 +622,7 @@ private ModelNode createAddFileHandlerOperation(String handlerName, String forma

private PathAddress createFileHandlerAddress(String handlerName){
return PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT,
PathElement.pathElement(ModelDescriptionConstants.FILE_HANDLER, handlerName));
}
Expand All @@ -632,6 +637,7 @@ private ModelNode createRemoveCoreHandlerReferenceOperation(String name){

private PathAddress createCoreHandlerReferenceAddress(String name){
return PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT,
AuditLogLoggerResourceDefinition.PATH_ELEMENT,
PathElement.pathElement(ModelDescriptionConstants.HANDLER, name));
Expand All @@ -653,7 +659,10 @@ private PathAddress createJmxHandlerReferenceAddress(String name){
}

private ModelNode createCoreAuditLogWriteAttributeOperation(String attr, boolean value) {
return Util.getWriteAttributeOperation(PathAddress.pathAddress(AccessAuditResourceDefinition.PATH_ELEMENT, AuditLogLoggerResourceDefinition.PATH_ELEMENT), attr, new ModelNode(value));
return Util.getWriteAttributeOperation(PathAddress.pathAddress(
CoreManagementResourceDefinition.PATH_ELEMENT,
AccessAuditResourceDefinition.PATH_ELEMENT,
AuditLogLoggerResourceDefinition.PATH_ELEMENT), attr, new ModelNode(value));
}

private ModelNode createJMXAuditLogWriteAttributeOperation(String attr, boolean value) {
Expand Down Expand Up @@ -745,7 +754,7 @@ protected void initModel(Resource rootResource, ManagementResourceRegistration r
}

registration.registerSubModel(PathResourceDefinition.createSpecified(pathManagerService));
registration.registerSubModel(new AccessAuditResourceDefinition(auditLogger, pathManagerService, new EnvironmentNameReader() {
registration.registerSubModel(CoreManagementResourceDefinition.forStandaloneServer(new DelegatingConfigurableAuthorizer(), getAuditLogger(), pathManagerService, new EnvironmentNameReader() {
public boolean isServer() {
return true;
}
Expand All @@ -763,6 +772,7 @@ public String getProductName() {
}
}));


pathManagerService.addPathManagerResources(rootResource);


Expand All @@ -772,6 +782,8 @@ public String getProductName() {
JMXExtension extension = new JMXExtension();
extension.initialize(extensionRegistry.getExtensionContext("xxxx", false));

rootResource.registerChild(CoreManagementResourceDefinition.PATH_ELEMENT, Resource.Factory.create());

//registration.registerSubModel(JMXSubsystemRootResource.create(auditLogger));
}

Expand Down

0 comments on commit 26f2ac1

Please sign in to comment.