use of org.wildfly.test.security.common.elytron.SimpleCredentialStore 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);
}
}
Aggregations