-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFCORE-4758]: Community - Simple config export for a server as an at…
…tachment for standalone or domain mode. * Adding a new read-config-as-xml-file to replace read-config-as-xml. * Adding more tests * Fixing some tests that aren't cleaning up their changes. * RBAC covering. * Replacing \" in produced XML by '. Jira: https://issues.redhat.com/browse/WFCORE-4758 Signed-off-by: Emmanuel Hugonnet <[email protected]>
- Loading branch information
Showing
28 changed files
with
1,330 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...rc/main/java/org/jboss/as/controller/operations/common/AbstractXmlMarshallingHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.controller.operations.common; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; | ||
import static org.jboss.as.controller.logging.ControllerLogger.MGMT_OP_LOGGER; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.EnumSet; | ||
import java.util.Set; | ||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.OperationStepHandler; | ||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.as.controller.access.Action; | ||
import org.jboss.as.controller.access.AuthorizationResult; | ||
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; | ||
import org.jboss.as.controller.logging.ControllerLogger; | ||
import org.jboss.as.controller.persistence.ConfigurationPersistenceException; | ||
import org.jboss.as.controller.persistence.ConfigurationPersister; | ||
import org.jboss.as.controller.registry.Resource; | ||
import org.jboss.dmr.ModelNode; | ||
|
||
/** | ||
* | ||
* @author Emmanuel Hugonnet (c) 2021 Red Hat, Inc. | ||
*/ | ||
public abstract class AbstractXmlMarshallingHandler implements OperationStepHandler { | ||
|
||
private static final Set<Action.ActionEffect> EFFECTS | ||
= Collections.unmodifiableSet(EnumSet.of(Action.ActionEffect.ADDRESS, Action.ActionEffect.READ_CONFIG)); | ||
|
||
private final ConfigurationPersister configPersister; | ||
|
||
protected AbstractXmlMarshallingHandler(final ConfigurationPersister configPersister) { | ||
this.configPersister = configPersister; | ||
} | ||
|
||
@Override | ||
public void execute(OperationContext context, ModelNode operation) { | ||
final PathAddress pa = context.getCurrentAddress(); | ||
|
||
AuthorizationResult authResult = context.authorize(operation, EFFECTS); | ||
if (authResult.getDecision() != AuthorizationResult.Decision.PERMIT) { | ||
throw ControllerLogger.ROOT_LOGGER.unauthorized(operation.require(OP).asString(), pa, authResult.getExplanation()); | ||
} | ||
|
||
final Resource resource = context.readResourceFromRoot(getBaseAddress()); | ||
// Get the model recursively | ||
final ModelNode model = Resource.Tools.readModel(resource); | ||
try { | ||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
BufferedOutputStream output = new BufferedOutputStream(baos)) { | ||
configPersister.marshallAsXml(model, output); | ||
attachResult(context, baos); | ||
} | ||
} catch (RuntimeException e) { | ||
throw e; | ||
} catch (IOException | ConfigurationPersistenceException e) { | ||
// Log this | ||
MGMT_OP_LOGGER.failedExecutingOperation(e, operation.require(ModelDescriptionConstants.OP), pa); | ||
context.getFailureDescription().set(e.toString()); | ||
} | ||
} | ||
|
||
protected abstract void attachResult(OperationContext context, ByteArrayOutputStream baos); | ||
|
||
protected PathAddress getBaseAddress() { | ||
return PathAddress.EMPTY_ADDRESS; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...er/src/main/java/org/jboss/as/controller/operations/common/XmlFileMarshallingHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.controller.operations.common; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UUID; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
|
||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleOperationDefinition; | ||
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; | ||
import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition; | ||
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; | ||
import org.jboss.as.controller.descriptions.common.ControllerResolver; | ||
import org.jboss.as.controller.persistence.ConfigurationPersister; | ||
import org.jboss.as.version.Stability; | ||
import org.jboss.dmr.ModelType; | ||
|
||
/** | ||
* | ||
* A {@link org.jboss.as.controller.OperationStepHandler} that can output a model in XML file. | ||
* | ||
* @author Emmanuel Hugonnet (c) 2021 Red Hat, Inc. | ||
*/ | ||
public class XmlFileMarshallingHandler extends AbstractXmlMarshallingHandler { | ||
|
||
private static final String OPERATION_NAME = ModelDescriptionConstants.READ_CONFIG_AS_XML_FILE_OPERATION; | ||
|
||
public static final SimpleOperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, ControllerResolver.getResolver()) | ||
.addAccessConstraint(SensitiveTargetAccessConstraintDefinition.READ_WHOLE_CONFIG) | ||
.setReplyParameters(new SimpleAttributeDefinitionBuilder(UUID, ModelType.STRING, false).build()) | ||
.setReadOnly() | ||
.setRuntimeOnly() | ||
.setStability(Stability.COMMUNITY) | ||
.build(); | ||
|
||
public XmlFileMarshallingHandler(final ConfigurationPersister configPersister) { | ||
super(configPersister); | ||
} | ||
|
||
@Override | ||
protected void attachResult(OperationContext context, ByteArrayOutputStream baos) { | ||
String uuid = context.attachResultStream("application/xml", new ByteArrayInputStream(baos.toByteArray())); | ||
context.getResult().get(UUID).set(uuid); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../src/main/java/org/jboss/as/host/controller/operations/HostXmlFileMarshallingHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.as.host.controller.operations; | ||
|
||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.as.controller.PathElement; | ||
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; | ||
import org.jboss.as.controller.operations.common.XmlFileMarshallingHandler; | ||
import org.jboss.as.controller.persistence.ConfigurationPersister; | ||
import org.jboss.as.domain.controller.LocalHostControllerInfo; | ||
|
||
/** | ||
* | ||
* @author Emmanuel Hugonnet (c) 2021 Red Hat, Inc. | ||
*/ | ||
public class HostXmlFileMarshallingHandler extends XmlFileMarshallingHandler { | ||
|
||
private final LocalHostControllerInfo hostControllerInfo; | ||
|
||
public HostXmlFileMarshallingHandler(final ConfigurationPersister configPersister, final LocalHostControllerInfo hostControllerInfo) { | ||
super(configPersister); | ||
this.hostControllerInfo = hostControllerInfo; | ||
} | ||
|
||
@Override | ||
protected PathAddress getBaseAddress() { | ||
return PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.HOST, hostControllerInfo.getLocalHostName())); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.