Search in sources :

Example 1 with ServiceLifecycleException

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();
    }
}
Also used : ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) MasterService(org.apache.knox.gateway.services.security.MasterService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Before(org.junit.Before)

Example 2 with ServiceLifecycleException

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();
    }
}
Also used : ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) File(java.io.File) Test(org.junit.Test)

Example 3 with ServiceLifecycleException

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());
}
Also used : HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) File(java.io.File)

Example 4 with ServiceLifecycleException

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);
            }
        }
    }
}
Also used : ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) KeyStoreException(java.security.KeyStoreException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException) File(java.io.File) KeyStore(java.security.KeyStore)

Example 5 with ServiceLifecycleException

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.");
    }
}
Also used : CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) X500PrincipalParser(org.apache.knox.gateway.util.X500PrincipalParser) CertificateExpiredException(java.security.cert.CertificateExpiredException) AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) X500Principal(javax.security.auth.x500.X500Principal) X509Certificate(java.security.cert.X509Certificate) Date(java.util.Date) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)40 File (java.io.File)31 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)30 HashMap (java.util.HashMap)29 FileOutputStream (java.io.FileOutputStream)14 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)13 Test (org.junit.Test)9 GatewayTestConfig (org.apache.knox.gateway.GatewayTestConfig)8 Topology (org.apache.knox.gateway.topology.Topology)8 Service (org.apache.knox.gateway.topology.Service)7 Param (org.apache.knox.gateway.topology.Param)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Document (org.w3c.dom.Document)6 URL (java.net.URL)5 Provider (org.apache.knox.gateway.topology.Provider)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Properties (java.util.Properties)4 GatewayServices (org.apache.knox.gateway.services.GatewayServices)4 AliasService (org.apache.knox.gateway.services.security.AliasService)4 IOException (java.io.IOException)3