use of org.jboss.as.test.integration.management.util.CLIWrapper in project wildfly by wildfly.
the class CredentialStoreTestCase method testCredentialStoreCreating.
/**
* Tests credential store with automatically created PKCS12 keystore.
*/
@Test
@Ignore
public void testCredentialStoreCreating() throws Exception {
String storeName = NAME;
File tempFolder = Utils.createTemporaryFolder(storeName);
String fileName = System.currentTimeMillis() + ".p12";
File ksFile = new File(tempFolder, fileName);
assertTrue(tempFolder.isDirectory());
assertFalse(ksFile.exists());
try {
try (CLIWrapper cli = new CLIWrapper(true)) {
cli.sendLine(String.format("/path=%s:add(path=\"%s\")", storeName, asAbsolutePath(tempFolder)));
SimpleCredentialStore storeConfig = SimpleCredentialStore.builder().withName(storeName).withKeyStorePath(Path.builder().withPath(fileName).withRelativeTo(storeName).build()).withCredential(CredentialReference.builder().withClearText("pkcs12pass").build()).withKeyStoreType("PKCS12").withModifiable(true).withCreate(true).withAlias("elytron", "rocks!").build();
try {
storeConfig.create(cli);
assertContainsAliases(cli, storeName, "elytron");
assertTrue(ksFile.exists());
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=another-secret:add(secret-value=\"%1$s\")", storeName));
assertCredentialValue(storeName, "elytron", "rocks!");
assertCredentialValue(storeName, "another-secret", storeName);
} finally {
// this should remove alias "elytron" from KeyStore file and remove credential {@value NAME} from domain
// model
storeConfig.remove(cli);
}
// KeyStore file should not be removed after
assertTrue(ksFile.exists());
KeyStore ks = KeyStore.getInstance("PKCS12");
try (FileInputStream fis = new FileInputStream(ksFile)) {
ks.load(fis, "pkcs12pass".toCharArray());
assertEquals(1, ks.size());
assertTrue(ks.aliases().nextElement().contains("another-secret"));
}
}
} finally {
FileUtils.deleteQuietly(tempFolder);
}
}
use of org.jboss.as.test.integration.management.util.CLIWrapper in project wildfly by wildfly.
the class CredentialStoreTestCase method testReloadCredentialStore.
/**
* Tests reload operation on credential store instance.
*/
@Test
public void testReloadCredentialStore() throws Exception {
final String alias = "cs-reload-test";
try (CLIWrapper cli = new CLIWrapper(true)) {
try {
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:add(secret-value=\"%s\"", CS_NAME_MODIFIABLE, alias, alias));
assertCredentialNotFound(CS_NAME_CLEAR, alias);
assertCredentialNotFound(CS_NAME_CRED_REF, alias);
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s:reload()", CS_NAME_CRED_REF));
assertCredentialNotFound(CS_NAME_CLEAR, alias);
assertCredentialValue(CS_NAME_CRED_REF, alias, alias);
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s:reload()", CS_NAME_CLEAR));
assertCredentialValue(CS_NAME_CLEAR, alias, alias);
} finally {
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:remove()", CS_NAME_MODIFIABLE, alias));
}
}
}
use of org.jboss.as.test.integration.management.util.CLIWrapper in project wildfly by wildfly.
the class CredentialStoreTestCase method testAddRemoveAddAlias.
/**
* Tests add-remove-add opertations sequence on an alias in credential store.
*/
@Test
@Ignore("WFLY-8144")
public void testAddRemoveAddAlias() throws Exception {
final String alias = "addremoveadd";
try (CLIWrapper cli = new CLIWrapper(true)) {
try {
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:add(secret-value=\"%s\"", CS_NAME_MODIFIABLE, alias, alias));
assertCredentialValue(CS_NAME_MODIFIABLE, alias, alias);
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:remove()", CS_NAME_MODIFIABLE, alias));
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:add(secret-value=\"%s\"", CS_NAME_MODIFIABLE, alias, alias + alias));
assertCredentialValue(CS_NAME_MODIFIABLE, alias, alias + alias);
} finally {
cli.sendLine(String.format("/subsystem=elytron/credential-store=%s/alias=%s:remove()", CS_NAME_MODIFIABLE, alias));
}
}
}
use of org.jboss.as.test.integration.management.util.CLIWrapper in project wildfly by wildfly.
the class AbstractElytronSetupTask method setup.
/**
* Creates configuration elements (provided by implementation of {@link #getConfigurableElements()} method) and calls
* {@link ConfigurableElement#create(CLIWrapper)} for them.
*/
protected void setup(final ModelControllerClient modelControllerClient) throws Exception {
configurableElements = getConfigurableElements();
if (configurableElements == null || configurableElements.length == 0) {
LOGGER.warn("Empty Elytron configuration.");
return;
}
try (CLIWrapper cli = new CLIWrapper(true)) {
for (final ConfigurableElement configurableElement : configurableElements) {
LOGGER.infov("Adding element {0} ({1})", configurableElement.getName(), configurableElement.getClass().getSimpleName());
configurableElement.create(cli);
}
}
ServerReload.reloadIfRequired(modelControllerClient);
}
use of org.jboss.as.test.integration.management.util.CLIWrapper in project wildfly by wildfly.
the class AbstractElytronSetupTask method tearDown.
/**
* Reverts configuration changes done by {@link #setup(ModelControllerClient)} method - i.e. calls {@link ConfigurableElement#remove(CLIWrapper)} method
* on instances provided by {@link #getConfigurableElements()} (in reverse order).
*/
protected void tearDown(ModelControllerClient modelControllerClient) throws Exception {
if (configurableElements == null || configurableElements.length == 0) {
LOGGER.warn("Empty Elytron configuration.");
return;
}
try (CLIWrapper cli = new CLIWrapper(true)) {
final ListIterator<ConfigurableElement> reverseConfigIt = Arrays.asList(configurableElements).listIterator(configurableElements.length);
while (reverseConfigIt.hasPrevious()) {
final ConfigurableElement configurableElement = reverseConfigIt.previous();
LOGGER.infov("Removing element {0} ({1})", configurableElement.getName(), configurableElement.getClass().getSimpleName());
configurableElement.remove(cli);
}
}
this.configurableElements = null;
ServerReload.reloadIfRequired(modelControllerClient);
}
Aggregations