-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding commands to manager trusted certificates
- Loading branch information
Showing
11 changed files
with
534 additions
and
2 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
...ation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCertificateImportHandler.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,75 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.core.instmgr; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTACHED_STREAMS; | ||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILESYSTEM_PATH; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
import org.jboss.as.controller.AttributeDefinition; | ||
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.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; | ||
import org.jboss.as.controller.registry.OperationEntry; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
import org.wildfly.installationmanager.MavenOptions; | ||
import org.wildfly.installationmanager.spi.InstallationManager; | ||
import org.wildfly.installationmanager.spi.InstallationManagerFactory; | ||
|
||
/** | ||
* Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as | ||
* channel changes. | ||
*/ | ||
public class InstMgrCertificateImportHandler extends InstMgrOperationStepHandler { | ||
public static final String OPERATION_NAME = "certificate-import"; | ||
|
||
protected static final AttributeDefinition CERT_FILE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.CERT_FILE, ModelType.INT) | ||
.setStorageRuntime() | ||
.setRequired(true) | ||
.addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE) | ||
.addArbitraryDescriptor(ATTACHED_STREAMS, ModelNode.TRUE) | ||
.build(); | ||
|
||
public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER) | ||
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY) | ||
.setReplyType(ModelType.OBJECT) | ||
.setRuntimeOnly() | ||
.setReplyValueType(ModelType.OBJECT) | ||
.addParameter(CERT_FILE) | ||
.build(); | ||
|
||
InstMgrCertificateImportHandler(InstMgrService imService, InstallationManagerFactory imf) { | ||
super(imService, imf); | ||
} | ||
|
||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
context.addStep(new OperationStepHandler() { | ||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
try { | ||
Path serverHome = imService.getHomeDir(); | ||
MavenOptions mavenOptions = new MavenOptions(null, false); | ||
InstallationManager installationManager = imf.create(serverHome, mavenOptions); | ||
|
||
try (InputStream is = context.getAttachmentStream(CERT_FILE.resolveModelAttribute(context, operation).asInt())) { | ||
installationManager.acceptTrustedCertificates(is); | ||
} | ||
} catch (OperationFailedException | RuntimeException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}, OperationContext.Stage.RUNTIME); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...lation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCertificateParseHandler.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,87 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.core.instmgr; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTACHED_STREAMS; | ||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILESYSTEM_PATH; | ||
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_DESCRIPTION; | ||
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_FINGERPRINT; | ||
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_KEY_ID; | ||
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_STATUS; | ||
|
||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
import org.jboss.as.controller.AttributeDefinition; | ||
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.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; | ||
import org.jboss.as.controller.registry.OperationEntry; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
import org.wildfly.installationmanager.MavenOptions; | ||
import org.wildfly.installationmanager.TrustCertificate; | ||
import org.wildfly.installationmanager.spi.InstallationManager; | ||
import org.wildfly.installationmanager.spi.InstallationManagerFactory; | ||
|
||
/** | ||
* Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as | ||
* channel changes. | ||
*/ | ||
public class InstMgrCertificateParseHandler extends InstMgrOperationStepHandler { | ||
public static final String OPERATION_NAME = "certificate-parse"; | ||
|
||
protected static final AttributeDefinition CERT_FILE = SimpleAttributeDefinitionBuilder.create(InstMgrConstants.CERT_FILE, ModelType.INT) | ||
.setStorageRuntime() | ||
.setRequired(true) | ||
.addArbitraryDescriptor(FILESYSTEM_PATH, ModelNode.TRUE) | ||
.addArbitraryDescriptor(ATTACHED_STREAMS, ModelNode.TRUE) | ||
.build(); | ||
|
||
public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER) | ||
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY) | ||
.setReplyType(ModelType.OBJECT) | ||
.setRuntimeOnly() | ||
.setReplyValueType(ModelType.OBJECT) | ||
.addParameter(CERT_FILE) | ||
.build(); | ||
|
||
InstMgrCertificateParseHandler(InstMgrService imService, InstallationManagerFactory imf) { | ||
super(imService, imf); | ||
} | ||
|
||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
context.addStep(new OperationStepHandler() { | ||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
try { | ||
Path serverHome = imService.getHomeDir(); | ||
MavenOptions mavenOptions = new MavenOptions(null, false); | ||
InstallationManager installationManager = imf.create(serverHome, mavenOptions); | ||
|
||
try (InputStream is = context.getAttachmentStream(CERT_FILE.resolveModelAttribute(context, operation).asInt())) { | ||
TrustCertificate tc = installationManager.parseCA(is); | ||
|
||
ModelNode entry = new ModelNode(); | ||
entry.get(CERT_KEY_ID).set(tc.getKeyID()); | ||
entry.get(CERT_FINGERPRINT).set(tc.getFingerprint()); | ||
entry.get(CERT_DESCRIPTION).set(tc.getDescription()); | ||
entry.get(CERT_STATUS).set(tc.getStatus()); | ||
context.getResult().set(entry); | ||
} | ||
} catch (OperationFailedException | RuntimeException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}, OperationContext.Stage.RUNTIME); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrCertificateRemoveHandler.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,70 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.wildfly.core.instmgr; | ||
|
||
import static org.wildfly.core.instmgr.InstMgrConstants.CERT_KEY_ID; | ||
|
||
import java.nio.file.Path; | ||
|
||
import org.jboss.as.controller.AttributeDefinition; | ||
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.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleOperationDefinitionBuilder; | ||
import org.jboss.as.controller.registry.OperationEntry; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
import org.wildfly.installationmanager.MavenOptions; | ||
import org.wildfly.installationmanager.spi.InstallationManager; | ||
import org.wildfly.installationmanager.spi.InstallationManagerFactory; | ||
|
||
/** | ||
* Operation handler to get the history of the installation manager changes, either artifacts or configuration metadata as | ||
* channel changes. | ||
*/ | ||
public class InstMgrCertificateRemoveHandler extends InstMgrOperationStepHandler { | ||
public static final String OPERATION_NAME = "certificate-remove"; | ||
|
||
protected static final AttributeDefinition KEY_ID = SimpleAttributeDefinitionBuilder.create(CERT_KEY_ID, ModelType.STRING) | ||
.setStorageRuntime() | ||
.setRequired(true) | ||
.build(); | ||
|
||
public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, InstMgrResolver.RESOLVER) | ||
.withFlags(OperationEntry.Flag.HOST_CONTROLLER_ONLY) | ||
.setReplyType(ModelType.OBJECT) | ||
.setRuntimeOnly() | ||
.setReplyValueType(ModelType.OBJECT) | ||
.addParameter(KEY_ID) | ||
.build(); | ||
|
||
InstMgrCertificateRemoveHandler(InstMgrService imService, InstallationManagerFactory imf) { | ||
super(imService, imf); | ||
} | ||
|
||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
final String keyId = KEY_ID.resolveModelAttribute(context, operation).asString(); | ||
context.addStep(new OperationStepHandler() { | ||
@Override | ||
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
try { | ||
Path serverHome = imService.getHomeDir(); | ||
MavenOptions mavenOptions = new MavenOptions(null, false); | ||
InstallationManager installationManager = imf.create(serverHome, mavenOptions); | ||
|
||
installationManager.revokeTrustedCertificate(keyId); | ||
} catch (OperationFailedException | RuntimeException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}, OperationContext.Stage.RUNTIME); | ||
} | ||
} |
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
Oops, something went wrong.