Skip to content

Commit

Permalink
Resolves issue wildfly-security#229: Credential store resource not us…
Browse files Browse the repository at this point in the history
…ing provider-loader
  • Loading branch information
pskopek committed Sep 22, 2016
1 parent 6981b0c commit 38a5bbb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Res
// ----------- credential store service ----------------
final CredentialStoreService csService;
try {
csService = CredentialStoreService.createCredentialStoreService(name, uri, type, provider, relativeTo);
csService = CredentialStoreService.createCredentialStoreService(name, uri, type, provider, relativeTo, providerLoader);
} catch (CredentialStoreException e) {
throw new OperationFailedException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.wildfly.extension.elytron;

import static org.wildfly.security.credential.store.impl.KeystorePasswordStore.KEY_STORE_PASSWORD_STORE;
import static org.wildfly.extension.elytron._private.ElytronSubsystemMessages.ROOT_LOGGER;

import java.io.File;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -52,6 +53,7 @@ class CredentialStoreService implements Service<CredentialStoreClient> {
private CredentialStore credentialStore;
private final String type;
private final String provider;
private final String providerLoaderName;
private final String relativeTo;
private final String name;
private final Map<String, String> credentialStoreAttributes;
Expand All @@ -63,15 +65,16 @@ class CredentialStoreService implements Service<CredentialStoreClient> {

private Handle callbackHandle;

private CredentialStoreService(String name, Map<String, String> credentialStoreAttributes, String type, String provider, String relativeTo) throws CredentialStoreException {
private CredentialStoreService(String name, Map<String, String> credentialStoreAttributes, String type, String provider, String relativeTo, String providerLoaderName) throws CredentialStoreException {
this.name = name;
this.type = type != null ? type : KEY_STORE_PASSWORD_STORE;
this.provider = provider;
this.relativeTo = relativeTo;
this.credentialStoreAttributes = credentialStoreAttributes;
this.providerLoaderName = providerLoaderName;
}

static CredentialStoreService createCredentialStoreService(String name, String uri, String type, String provider, String relativeTo) throws CredentialStoreException {
static CredentialStoreService createCredentialStoreService(String name, String uri, String type, String provider, String relativeTo, String providerLoaderName) throws CredentialStoreException {
try {
CredentialStoreURIParser credentialStoreURIParser = new CredentialStoreURIParser(uri);
String nameToSet = name != null ? name : credentialStoreURIParser.getName(); // once we specify name, the name from uri is ignored
Expand All @@ -81,7 +84,7 @@ static CredentialStoreService createCredentialStoreService(String name, String u
if (storageFile != null) {
credentialStoreAttributes.put(ElytronDescriptionConstants.CREDENTIAL_STORE_FILE, storageFile);
}
return new CredentialStoreService(nameToSet, credentialStoreAttributes, type, provider, relativeTo);
return new CredentialStoreService(nameToSet, credentialStoreAttributes, type, provider, relativeTo, providerLoaderName);
} catch (URISyntaxException e) {
throw new CredentialStoreException(e);
}
Expand All @@ -95,7 +98,7 @@ static CredentialStoreService createCredentialStoreService(String name, String u
public void start(StartContext startContext) throws StartException {
resolveFileLocation();
try {
credentialStore = provider != null ? CredentialStore.getInstance(type, provider) : CredentialStore.getInstance(type);
credentialStore = getCredentialStoreInstance();
credentialStore.initialize(credentialStoreAttributes);
} catch (CredentialStoreException | NoSuchAlgorithmException | NoSuchProviderException e) {
throw ElytronSubsystemMessages.ROOT_LOGGER.unableToStartService(e);
Expand Down Expand Up @@ -141,6 +144,29 @@ public void pathEvent(PathManager.Event event, PathEntry pathEntry) {
}
}

private CredentialStore getCredentialStoreInstance() throws CredentialStoreException, NoSuchAlgorithmException, NoSuchProviderException {
if (provider != null) {
// directly specified provider
return CredentialStore.getInstance(type, provider);
}

Provider[] injectedProviders = providers.getOptionalValue();
if (injectedProviders != null) {
// injected provider list, select the first provider with corresponding type
for (Provider p: injectedProviders) {
try {
return CredentialStore.getInstance(type, p);
} catch (NoSuchAlgorithmException e) {
// ignore
}
}
throw ROOT_LOGGER.providerLoaderCannotSupplyProvider(providerLoaderName, type);
} else {
// default provider
return CredentialStore.getInstance(type);
}
}

Injector<Provider[]> getProvidersInjector() {
return providers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.jboss.logging.Logger.Level.INFO;

import java.security.KeyStore;
import java.security.NoSuchProviderException;
import java.security.Provider;

import org.jboss.as.controller.OperationFailedException;
Expand Down Expand Up @@ -243,6 +244,9 @@ public interface ElytronSubsystemMessages extends BasicLogger {
@Message(id = 913, value = "Credential alias not specified in URI reference '%s'")
OperationFailedException credentialAliasNotSpecifiedInUriReference(String uriReference);

@Message(id = 914, value = "Provider loader '%s' cannot supply Credential Store provider of type '%s'")
NoSuchProviderException providerLoaderCannotSupplyProvider(String providerLoader, String type);

/*
* Identity Resource Messages - 1000
*/
Expand Down

0 comments on commit 38a5bbb

Please sign in to comment.