Search in sources :

Example 6 with CLIWrapper

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);
    }
}
Also used : CLIWrapper(org.jboss.as.test.integration.management.util.CLIWrapper) SimpleCredentialStore(org.wildfly.test.security.common.elytron.SimpleCredentialStore) File(java.io.File) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with CLIWrapper

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));
        }
    }
}
Also used : CLIWrapper(org.jboss.as.test.integration.management.util.CLIWrapper) Test(org.junit.Test)

Example 8 with CLIWrapper

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));
        }
    }
}
Also used : CLIWrapper(org.jboss.as.test.integration.management.util.CLIWrapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with CLIWrapper

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);
}
Also used : ConfigurableElement(org.wildfly.test.security.common.elytron.ConfigurableElement) CLIWrapper(org.jboss.as.test.integration.management.util.CLIWrapper)

Example 10 with CLIWrapper

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);
}
Also used : ConfigurableElement(org.wildfly.test.security.common.elytron.ConfigurableElement) CLIWrapper(org.jboss.as.test.integration.management.util.CLIWrapper)

Aggregations

CLIWrapper (org.jboss.as.test.integration.management.util.CLIWrapper)10 Test (org.junit.Test)4 CLIOpResult (org.jboss.as.test.integration.management.util.CLIOpResult)3 Ignore (org.junit.Ignore)3 ConfigurableElement (org.wildfly.test.security.common.elytron.ConfigurableElement)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 StandardCharsets (java.nio.charset.StandardCharsets)1 AllPermission (java.security.AllPermission)1 KeyStore (java.security.KeyStore)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 SC_NOT_FOUND (javax.servlet.http.HttpServletResponse.SC_NOT_FOUND)1