Search in sources :

Example 26 with ServiceLifecycleException

use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.

the class CMFMasterService method setupMasterSecret.

protected void setupMasterSecret(String securityDir, String filename, boolean persisting) throws ServiceLifecycleException {
    File masterFile = new File(securityDir, filename);
    if (masterFile.exists()) {
        try {
            initializeFromMaster(masterFile);
        } catch (Exception e) {
            throw new ServiceLifecycleException("Unable to load the persisted master secret.", e);
        }
    } else {
        if (master == null) {
            displayWarning(persisting);
            promptUser();
        }
        if (persisting) {
            persistMaster(master, masterFile);
        }
    }
}
Also used : ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) File(java.io.File) IOException(java.io.IOException) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException)

Example 27 with ServiceLifecycleException

use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.

the class DefaultServiceRegistryService method setupRegistryFile.

protected void setupRegistryFile(String securityDir, String filename) throws ServiceLifecycleException {
    File registryFile = new File(securityDir, filename);
    if (registryFile.exists()) {
        try {
            String json = FileUtils.readFileToString(registryFile);
            Registry reg = (Registry) getMapFromJsonString(json);
            if (reg != null) {
                registry = reg;
            }
        } catch (Exception e) {
            throw new ServiceLifecycleException("Unable to load the persisted registry.", e);
        }
    }
    registryFileName = registryFile.getAbsolutePath();
}
Also used : ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) ServiceRegistry(org.apache.knox.gateway.services.registry.ServiceRegistry) File(java.io.File) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 28 with ServiceLifecycleException

use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.

the class JettySSLService method init.

@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
    // set any JSSE or security related system properties
    System.setProperty(EPHEMERAL_DH_KEY_SIZE_PROPERTY, config.getEphemeralDHKeySize());
    try {
        if (!ks.isCredentialStoreForClusterAvailable(GATEWAY_CREDENTIAL_STORE_NAME)) {
            log.creatingCredentialStoreForGateway();
            ks.createCredentialStoreForCluster(GATEWAY_CREDENTIAL_STORE_NAME);
        // LET'S NOT GENERATE A DIFFERENT KEY PASSPHRASE BY DEFAULT ANYMORE
        // IF A DEPLOYMENT WANTS TO CHANGE THE KEY PASSPHRASE TO MAKE IT MORE SECURE THEN
        // THEY CAN ADD THE ALIAS EXPLICITLY WITH THE CLI
        // as.generateAliasForCluster(GATEWAY_CREDENTIAL_STORE_NAME, GATEWAY_IDENTITY_PASSPHRASE);
        } else {
            log.credentialStoreForGatewayFoundNotCreating();
        }
    } catch (KeystoreServiceException e) {
        throw new ServiceLifecycleException("Keystore was not loaded properly - the provided (or persisted) master secret may not match the password for the keystore.", e);
    }
    try {
        if (!ks.isKeystoreForGatewayAvailable()) {
            log.creatingKeyStoreForGateway();
            ks.createKeystoreForGateway();
            char[] passphrase = null;
            try {
                passphrase = as.getGatewayIdentityPassphrase();
            } catch (AliasServiceException e) {
                throw new ServiceLifecycleException("Error accessing credential store for the gateway.", e);
            }
            if (passphrase == null) {
                passphrase = ms.getMasterSecret();
            }
            ks.addSelfSignedCertForGateway("gateway-identity", passphrase);
        } else {
            log.keyStoreForGatewayFoundNotCreating();
        }
        logAndValidateCertificate();
    } catch (KeystoreServiceException e) {
        throw new ServiceLifecycleException("Keystore was not loaded properly - the provided (or persisted) master secret may not match the password for the keystore.", e);
    }
    keystoreType = config.getKeystoreType();
    sslIncludeCiphers = config.getIncludedSSLCiphers();
    sslExcludeCiphers = config.getExcludedSSLCiphers();
    sslExcludeProtocols = config.getExcludedSSLProtocols();
    clientAuthNeeded = config.isClientAuthNeeded();
    clientAuthWanted = config.isClientAuthWanted();
    truststorePath = config.getTruststorePath();
    trustAllCerts = config.getTrustAllCerts();
    trustStoreType = config.getTruststoreType();
}
Also used : AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException)

Example 29 with ServiceLifecycleException

use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.

the class DefaultTokenAuthorityService method init.

@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
    if (as == null || ks == null) {
        throw new ServiceLifecycleException("Alias or Keystore service is not set");
    }
    signingKeyAlias = config.getSigningKeyAlias();
    @SuppressWarnings("unused") RSAPrivateKey key;
    char[] passphrase = null;
    try {
        passphrase = as.getPasswordFromAliasForGateway(SIGNING_KEY_PASSPHRASE);
        if (passphrase != null) {
            key = (RSAPrivateKey) ks.getSigningKey(getSigningKeyAlias(), passphrase);
            if (key == null) {
                throw new ServiceLifecycleException("Provisioned passphrase cannot be used to acquire signing key.");
            }
        }
    } catch (AliasServiceException e) {
        throw new ServiceLifecycleException("Provisioned signing key passphrase cannot be acquired.", e);
    } catch (KeystoreServiceException e) {
        throw new ServiceLifecycleException("Provisioned signing key passphrase cannot be acquired.", e);
    }
}
Also used : AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) KeystoreServiceException(org.apache.knox.gateway.services.security.KeystoreServiceException) RSAPrivateKey(java.security.interfaces.RSAPrivateKey)

Example 30 with ServiceLifecycleException

use of org.apache.knox.gateway.services.ServiceLifecycleException in project knox by apache.

the class CryptoServiceTest method setupSuite.

@BeforeClass
public static void setupSuite() throws Exception {
    as = new AliasService() {

        @Override
        public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
        }

        @Override
        public void start() throws ServiceLifecycleException {
        }

        @Override
        public void stop() throws ServiceLifecycleException {
        }

        @Override
        public void addAliasForCluster(String clusterName, String alias, String value) {
        }

        @Override
        public char[] getPasswordFromAliasForCluster(String clusterName, String alias) {
            return "password".toCharArray();
        }

        @Override
        public char[] getPasswordFromAliasForCluster(String clusterName, String alias, boolean generate) {
            return null;
        }

        @Override
        public void generateAliasForCluster(String clusterName, String alias) {
        }

        @Override
        public char[] getPasswordFromAliasForGateway(String alias) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void generateAliasForGateway(String alias) {
        // TODO Auto-generated method stub
        }

        @Override
        public Certificate getCertificateForGateway(String alias) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void removeAliasForCluster(String clusterName, String alias) {
        }

        @Override
        public List<String> getAliasesForCluster(String clusterName) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public char[] getGatewayIdentityPassphrase() throws AliasServiceException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    cs = new DefaultCryptoService();
    ((DefaultCryptoService) cs).setAliasService(as);
}
Also used : ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) List(java.util.List) DefaultCryptoService(org.apache.knox.gateway.services.security.impl.DefaultCryptoService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Certificate(java.security.cert.Certificate) BeforeClass(org.junit.BeforeClass)

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