in modules/securevault/src/main/java/org/apache/synapse/securevault/secret/SecretManager.java [72:203]
public void init(Properties properties) {
if (initialized) {
if (log.isDebugEnabled()) {
log.debug("Secret Manager already has been started.");
}
return;
}
if (properties == null) {
if (log.isDebugEnabled()) {
log.debug("KeyStore configuration properties cannot be found");
}
return;
}
String configurationFile = MiscellaneousUtil.getProperty(
properties, PROP_SECRET_MANAGER_CONF, PROP_DEFAULT_CONF_LOCATION);
Properties configurationProperties = MiscellaneousUtil.loadProperties(configurationFile);
if (configurationProperties == null || configurationProperties.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Configuration properties can not be loaded form : " +
configurationFile + " Will use synapse properties");
}
configurationProperties = properties;
}
String repositoriesString = MiscellaneousUtil.getProperty(
configurationProperties, PROP_SECRET_REPOSITORIES, null);
if (repositoriesString == null || "".equals(repositoriesString)) {
if (log.isDebugEnabled()) {
log.debug("No secret repositories have been configured");
}
return;
}
String[] repositories = repositoriesString.split(",");
if (repositories == null || repositories.length == 0) {
if (log.isDebugEnabled()) {
log.debug("No secret repositories have been configured");
}
return;
}
//Create a KeyStore Information for private key entry KeyStore
IdentityKeyStoreInformation identityInformation =
KeyStoreInformationFactory.createIdentityKeyStoreInformation(properties);
// Create a KeyStore Information for trusted certificate KeyStore
TrustKeyStoreInformation trustInformation =
KeyStoreInformationFactory.createTrustKeyStoreInformation(properties);
String identityKeyPass = identityInformation
.getKeyPasswordProvider().getResolvedSecret();
String identityStorePass = identityInformation
.getKeyStorePasswordProvider().getResolvedSecret();
String trustStorePass = trustInformation
.getKeyStorePasswordProvider().getResolvedSecret();
if (!validatePasswords(identityStorePass, identityKeyPass, trustStorePass)) {
if (log.isDebugEnabled()) {
log.info("Either Identity or Trust keystore password is mandatory" +
" in order to initialized secret manager.");
}
return;
}
IdentityKeyStoreWrapper identityKeyStoreWrapper = new IdentityKeyStoreWrapper();
identityKeyStoreWrapper.init(identityInformation, identityKeyPass);
TrustKeyStoreWrapper trustKeyStoreWrapper = new TrustKeyStoreWrapper();
trustKeyStoreWrapper.init(trustInformation);
SecretRepository currentParent = null;
for (String secretRepo : repositories) {
StringBuffer sb = new StringBuffer();
sb.append(PROP_SECRET_REPOSITORIES);
sb.append(DOT);
sb.append(secretRepo);
String id = sb.toString();
sb.append(DOT);
sb.append(PROP_PROVIDER);
String provider = MiscellaneousUtil.getProperty(
configurationProperties, sb.toString(), null);
if (provider == null || "".equals(provider)) {
handleException("Repository provider cannot be null ");
}
if (log.isDebugEnabled()) {
log.debug("Initiating a File Based Secret Repository");
}
try {
Class aClass = getClass().getClassLoader().loadClass(provider.trim());
Object instance = aClass.newInstance();
if (instance instanceof SecretRepositoryProvider) {
SecretRepository secretRepository = ((SecretRepositoryProvider) instance).
getSecretRepository(identityKeyStoreWrapper, trustKeyStoreWrapper);
secretRepository.init(configurationProperties, id);
if (parentRepository == null) {
parentRepository = secretRepository;
}
secretRepository.setParent(currentParent);
currentParent = secretRepository;
if (log.isDebugEnabled()) {
log.debug("Successfully Initiate a Secret Repository provided by : "
+ provider);
}
} else {
handleException("Invalid class as SecretRepositoryProvider : Class Name : "
+ provider);
}
} catch (ClassNotFoundException e) {
handleException("A Secret Provider cannot be found for class name : " + provider);
} catch (IllegalAccessException e) {
handleException("Error creating a instance from class : " + provider);
} catch (InstantiationException e) {
handleException("Error creating a instance from class : " + provider);
}
}
initialized = true;
}