use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class CMFKeystoreServiceTest method setup.
@Before
public void setup() {
try {
ks = new CMFKeystoreService(".", "ambari");
ks.setMasterService(new MasterService() {
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
// TODO Auto-generated method stub
}
public void start() throws ServiceLifecycleException {
// TODO Auto-generated method stub
}
public void stop() throws ServiceLifecycleException {
// TODO Auto-generated method stub
}
public char[] getMasterSecret() {
// TODO Auto-generated method stub
return "testmaster".toCharArray();
}
});
} catch (ServiceLifecycleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class CMFMasterServiceTest method testMasterService.
@Test
public void testMasterService() {
try {
ms.setupMasterSecret(".", true);
// System.out.println("MASTER: " + new String(ms.getMasterSecret()));
assertTrue(new String(ms.getMasterSecret()).equals("testmastersecret"));
File file = new File("ambari-master");
assertTrue(file.exists());
file.delete();
} catch (ServiceLifecycleException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail();
}
}
use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.
the class GatewayTestDriver method setupGateway.
/**
* Creates a GATEWAY_HOME, starts a gateway instance and deploys a test topology.
*/
public void setupGateway(GatewayTestConfig config, String cluster, XMLTag topology, boolean use) throws Exception {
this.useGateway = use;
this.config = config;
this.clusterName = cluster;
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
config.setGatewayHomeDir(gatewayDir.getAbsolutePath());
File topoDir = new File(config.getGatewayTopologyDir());
topoDir.mkdirs();
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
File descriptor = new File(topoDir, cluster + ".xml");
FileOutputStream stream = new FileOutputStream(descriptor);
topology.toStream(stream);
stream.close();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
gateway = GatewayServer.startGateway(config, srvcs);
MatcherAssert.assertThat("Failed to start gateway.", gateway, CoreMatchers.notNullValue());
log.info("Gateway port = " + gateway.getAddresses()[0].getPort());
}
use of org.apache.knox.gateway.services.ServiceLifecycleException 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.ServiceLifecycleException in project knox by apache.
the class JettySSLService method logAndValidateCertificate.
private void logAndValidateCertificate() throws ServiceLifecycleException {
// let's log the hostname (CN) and cert expiry from the gateway's public cert to aid in SSL debugging
Certificate cert;
try {
cert = as.getCertificateForGateway("gateway-identity");
} catch (AliasServiceException e) {
throw new ServiceLifecycleException("Cannot Retreive Gateway SSL Certificate. Server will not start.", e);
}
if (cert != null) {
if (cert instanceof X509Certificate) {
X500Principal x500Principal = ((X509Certificate) cert).getSubjectX500Principal();
X500PrincipalParser parser = new X500PrincipalParser(x500Principal);
log.certificateHostNameForGateway(parser.getCN());
Date notBefore = ((X509Certificate) cert).getNotBefore();
Date notAfter = ((X509Certificate) cert).getNotAfter();
log.certificateValidityPeriod(notBefore, notAfter);
// let's not even start if the current date is not within the validity period for the SSL cert
try {
((X509Certificate) cert).checkValidity();
} catch (CertificateExpiredException e) {
throw new ServiceLifecycleException("Gateway SSL Certificate is Expired. Server will not start.", e);
} catch (CertificateNotYetValidException e) {
throw new ServiceLifecycleException("Gateway SSL Certificate is not yet valid. Server will not start.", e);
}
} else {
throw new ServiceLifecycleException("Public certificate for the gateway cannot be found with the alias gateway-identity. Plase check the identity certificate alias.");
}
} else {
throw new ServiceLifecycleException("Public certificate for the gateway is not of the expected type of X509Certificate. Something is wrong with the gateway keystore.");
}
}
Aggregations