Search in sources :

Example 16 with AliasService

use of org.apache.knox.gateway.services.security.AliasService in project knox by apache.

the class RemoteConfigurationRegistryJAASConfigTest method testZooKeeperMultipleContextEntries.

@Test
public void testZooKeeperMultipleContextEntries() throws Exception {
    List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
    final String KERBEROS_ENTRY_NAME = "my_kerberos_context";
    final String KERBEROS_PRINCIPAL = "myKerberosIdentity";
    final String DIGEST_ENTRY_NAME = "my_digest_context";
    final String DIGEST_PRINCIPAL = "myDigestIdentity";
    final String DIGEST_PWD_ALIAS = "myAlias";
    final String DIGEST_PWD = "mysecret";
    AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
    EasyMock.expect(aliasService.getPasswordFromAliasForGateway(DIGEST_PWD_ALIAS)).andReturn(DIGEST_PWD.toCharArray()).anyTimes();
    EasyMock.replay(aliasService);
    File dummyKeyTab = File.createTempFile("my_context", "keytab");
    registryConfigs.add(createKerberosConfig(KERBEROS_ENTRY_NAME, KERBEROS_PRINCIPAL, dummyKeyTab.getAbsolutePath()));
    registryConfigs.add(createDigestConfig(DIGEST_ENTRY_NAME, DIGEST_PRINCIPAL, DIGEST_PWD_ALIAS));
    try {
        RemoteConfigurationRegistryJAASConfig jaasConfig = RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);
        // Make sure there are no entries for an invalid context entry name
        assertNull(jaasConfig.getAppConfigurationEntry("invalid"));
        // Validate the kerberos context entry
        validateKerberosContext(jaasConfig, KERBEROS_ENTRY_NAME, KERBEROS_PRINCIPAL, dummyKeyTab.getAbsolutePath(), true, false);
        // Validate the digest context entry
        validateDigestContext(jaasConfig, DIGEST_ENTRY_NAME, RemoteConfigurationRegistryJAASConfig.digestLoginModules.get("ZOOKEEPER"), DIGEST_PRINCIPAL, DIGEST_PWD);
    } finally {
        Configuration.setConfiguration(null);
    }
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig) RemoteConfigurationRegistryJAASConfig(org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 17 with AliasService

use of org.apache.knox.gateway.services.security.AliasService in project knox by apache.

the class CredentialResource method getCredentialsList.

/**
 * @return
 */
private List<String> getCredentialsList() {
    GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
    String clusterName = (String) request.getServletContext().getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
    AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
    List<String> aliases = null;
    try {
        aliases = as.getAliasesForCluster(clusterName);
    } catch (AliasServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return aliases;
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) AliasServiceException(org.apache.knox.gateway.services.security.AliasServiceException)

Example 18 with AliasService

use of org.apache.knox.gateway.services.security.AliasService in project knox by apache.

the class GatewayLdapDynamicGroupFuncTest method setupGateway.

public static void setupGateway() throws IOException, Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    /*
    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "testdg-cluster"};
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    cli.run(argvals);

    outContent.reset();
    String[] args1 = {"list-alias", "--cluster", "testdg-cluster", "--master", "hadoop"};
    cli = new KnoxCLI();
    cli.run(args1);
    System.err.println("ALIAS LIST: " + outContent.toString());

    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
    System.err.println("ALIAS value1: " + new String(passwordChars1));
    */
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/testdg-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    // /*
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "testdg-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) 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 19 with AliasService

use of org.apache.knox.gateway.services.security.AliasService in project knox by apache.

the class GatewayLdapGroupFuncTest method setupGateway.

public static void setupGateway() throws Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "true");
    options.put("master", "hadoop");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    /*
    System.setProperty(GatewayConfig.GATEWAY_HOME_VAR, gatewayDir.getAbsolutePath());
    System.err.println("GH 10: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    System.setOut(new PrintStream(outContent));
    String[] argvals = {"create-alias", "ldcSystemPassword", "--value", "guest-password", "--master", "hadoop", "--cluster", "test-cluster"};
    KnoxCLI cli = new KnoxCLI();
    cli.setConf(new GatewayConfigImpl());
    cli.run(argvals);

    outContent.reset();
    String[] args1 = {"list-alias", "--cluster", "test-cluster", "--master", "hadoop"};
    cli = new KnoxCLI();
    cli.run(args1);
    System.err.println("ALIAS LIST: " + outContent.toString());

    AliasService as1 = cli.getGatewayServices().getService(GatewayServices.ALIAS_SERVICE);
    char[] passwordChars1 = as1.getPasswordFromAliasForCluster( "test-cluster", "ldcsystemPassword");
    System.err.println("ALIAS value1: " + new String(passwordChars1));
    */
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/test-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    // /*
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("test-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "test-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "test-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) 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 20 with AliasService

use of org.apache.knox.gateway.services.security.AliasService in project knox by apache.

the class Knox242FuncTest method setupGateway.

public static void setupGateway() throws IOException, Exception {
    File targetDir = new File(System.getProperty("user.dir"), "target");
    File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
    gatewayDir.mkdirs();
    GatewayTestConfig testConfig = new GatewayTestConfig();
    config = testConfig;
    testConfig.setGatewayHomeDir(gatewayDir.getAbsolutePath());
    File topoDir = new File(testConfig.getGatewayTopologyDir());
    topoDir.mkdirs();
    File deployDir = new File(testConfig.getGatewayDeploymentDir());
    deployDir.mkdirs();
    DefaultGatewayServices srvcs = new DefaultGatewayServices();
    Map<String, String> options = new HashMap<>();
    options.put("persist-master", "false");
    options.put("master", "password");
    try {
        srvcs.init(testConfig, options);
    } catch (ServiceLifecycleException e) {
        // I18N not required.
        e.printStackTrace();
    }
    gateway = GatewayServer.startGateway(testConfig, srvcs);
    MatcherAssert.assertThat("Failed to start gateway.", gateway, notNullValue());
    LOG.info("Gateway port = " + gateway.getAddresses()[0].getPort());
    gatewayUrl = "http://localhost:" + gateway.getAddresses()[0].getPort() + "/" + config.getGatewayPath();
    clusterUrl = gatewayUrl + "/testdg-cluster";
    serviceUrl = clusterUrl + "/test-service-path/test-service-resource";
    GatewayServices services = GatewayServer.getGatewayServices();
    AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
    aliasService.addAliasForCluster("testdg-cluster", "ldcSystemPassword", "guest-password");
    // char[] password1 = aliasService.getPasswordFromAliasForCluster( "testdg-cluster", "ldcSystemPassword");
    // System.err.println("SETUP password 10: " + ((password1 == null) ? "NULL" : new String(password1)));
    File descriptor = new File(topoDir, "testdg-cluster.xml");
    FileOutputStream stream = new FileOutputStream(descriptor);
    createTopology().toStream(stream);
    stream.close();
}
Also used : GatewayServices(org.apache.knox.gateway.services.GatewayServices) DefaultGatewayServices(org.apache.knox.gateway.services.DefaultGatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) 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)

Aggregations

AliasService (org.apache.knox.gateway.services.security.AliasService)35 Test (org.junit.Test)25 GatewayServices (org.apache.knox.gateway.services.GatewayServices)20 File (java.io.File)15 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)12 HashMap (java.util.HashMap)11 DefaultCryptoService (org.apache.knox.gateway.services.security.impl.DefaultCryptoService)10 KeystoreService (org.apache.knox.gateway.services.security.KeystoreService)8 MasterService (org.apache.knox.gateway.services.security.MasterService)8 CryptoService (org.apache.knox.gateway.services.security.CryptoService)7 UrlRewriteEnvironment (org.apache.knox.gateway.filter.rewrite.api.UrlRewriteEnvironment)6 Principal (java.security.Principal)5 DefaultKeystoreService (org.apache.knox.gateway.services.security.impl.DefaultKeystoreService)5 JWTokenAuthority (org.apache.knox.gateway.services.security.token.JWTokenAuthority)5 FileOutputStream (java.io.FileOutputStream)4 UrlRewriteContext (org.apache.knox.gateway.filter.rewrite.spi.UrlRewriteContext)4 ZooKeeperClientServiceProvider (org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider)4 DefaultGatewayServices (org.apache.knox.gateway.services.DefaultGatewayServices)4 RemoteConfigurationRegistryClientService (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService)4 Capture (org.easymock.Capture)4