use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.
the class DefaultAliasService method getPasswordFromAliasForCluster.
/* (non-Javadoc)
* @see org.apache.knox.gateway.services.security.impl.AliasService#getAliasForCluster(java.lang.String, java.lang.String, boolean)
*/
@Override
public char[] getPasswordFromAliasForCluster(String clusterName, String alias, boolean generate) throws AliasServiceException {
char[] credential = null;
try {
credential = keystoreService.getCredentialForCluster(clusterName, alias);
if (credential == null) {
if (generate) {
generateAliasForCluster(clusterName, alias);
credential = keystoreService.getCredentialForCluster(clusterName, alias);
}
}
} catch (KeystoreServiceException e) {
LOG.failedToGetCredentialForCluster(clusterName, e);
throw new AliasServiceException(e);
}
return credential;
}
use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.
the class DefaultAliasService method generateAliasForCluster.
@Override
public void generateAliasForCluster(String clusterName, String alias) throws AliasServiceException {
try {
keystoreService.getCredentialStoreForCluster(clusterName);
} catch (KeystoreServiceException e) {
LOG.failedToGenerateAliasForCluster(clusterName, e);
throw new AliasServiceException(e);
}
String passwordString = generatePassword(16);
addAliasForCluster(clusterName, alias, passwordString);
}
use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.
the class DefaultAliasService method getAliasesForCluster.
/* (non-Javadoc)
* @see AliasService#getAliasesForCluster(java.lang.String)
*/
@Override
public List<String> getAliasesForCluster(String clusterName) {
ArrayList<String> list = new ArrayList<String>();
KeyStore keyStore;
try {
keyStore = keystoreService.getCredentialStoreForCluster(clusterName);
if (keyStore != null) {
String alias = null;
try {
Enumeration<String> e = keyStore.aliases();
while (e.hasMoreElements()) {
alias = e.nextElement();
// only include the metadata key names in the list of names
if (!alias.contains("@")) {
list.add(alias);
}
}
} catch (KeyStoreException e) {
LOG.failedToGetCredentialForCluster(clusterName, e);
}
}
} catch (KeystoreServiceException kse) {
LOG.failedToGetCredentialForCluster(clusterName, kse);
}
return list;
}
use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.
the class DefaultKeystoreService method init.
@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
ReadWriteLock lock = new ReentrantReadWriteLock(true);
readLock = lock.readLock();
writeLock = lock.writeLock();
this.keyStoreDir = config.getGatewaySecurityDir() + File.separator + "keystores" + File.separator;
File ksd = new File(this.keyStoreDir);
if (!ksd.exists()) {
if (!ksd.mkdirs()) {
throw new ServiceLifecycleException(RES.failedToCreateKeyStoreDirectory(ksd.getAbsolutePath()));
}
}
signingKeystoreName = config.getSigningKeystoreName();
// ensure that the keystore actually exists and fail to start if not
if (signingKeystoreName != null) {
File sks = new File(this.keyStoreDir, signingKeystoreName);
if (!sks.exists()) {
throw new ServiceLifecycleException("Configured signing keystore does not exist.");
}
signingKeyAlias = config.getSigningKeyAlias();
if (signingKeyAlias != null) {
// ensure that the signing key alias exists in the configured keystore
KeyStore ks;
try {
ks = getSigningKeystore();
if (ks != null) {
if (!ks.containsAlias(signingKeyAlias)) {
throw new ServiceLifecycleException("Configured signing key alias does not exist.");
}
}
} catch (KeystoreServiceException e) {
throw new ServiceLifecycleException("Unable to get the configured signing keystore.", e);
} catch (KeyStoreException e) {
throw new ServiceLifecycleException("Signing keystore has not been loaded.", e);
}
}
}
}
use of org.apache.knox.gateway.services.security.KeystoreServiceException in project knox by apache.
the class DefaultKeystoreService method isKeystoreForGatewayAvailable.
@Override
public boolean isKeystoreForGatewayAvailable() throws KeystoreServiceException {
boolean rc = false;
final File keyStoreFile = new File(keyStoreDir + GATEWAY_KEYSTORE);
readLock.lock();
try {
try {
rc = isKeystoreAvailable(keyStoreFile, "JKS");
} catch (KeyStoreException e) {
throw new KeystoreServiceException(e);
} catch (IOException e) {
throw new KeystoreServiceException(e);
}
return rc;
} finally {
readLock.unlock();
}
}
Aggregations