Search in sources :

Example 1 with RemoteConfigurationRegistryJAASConfig

use of org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig in project knox by apache.

the class RemoteConfigurationRegistryJAASConfigTest method testZooKeeperDigestContextEntry.

@Test
public void testZooKeeperDigestContextEntry() throws Exception {
    List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
    final String ENTRY_NAME = "my_digest_context";
    final String DIGEST_PRINCIPAL = "myIdentity";
    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);
    registryConfigs.add(createDigestConfig(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 intended context entry
        validateDigestContext(jaasConfig, 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) Test(org.junit.Test)

Example 2 with RemoteConfigurationRegistryJAASConfig

use of org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig 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 3 with RemoteConfigurationRegistryJAASConfig

use of org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig in project knox by apache.

the class RemoteConfigurationRegistryJAASConfigTest method testZooKeeperDigestContextEntryWithoutAliasService.

@Test
public void testZooKeeperDigestContextEntryWithoutAliasService() throws Exception {
    List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
    final String ENTRY_NAME = "my_digest_context";
    final String DIGEST_PRINCIPAL = "myIdentity";
    final String DIGEST_PWD_ALIAS = "myAlias";
    registryConfigs.add(createDigestConfig(ENTRY_NAME, DIGEST_PRINCIPAL, DIGEST_PWD_ALIAS));
    try {
        RemoteConfigurationRegistryJAASConfig jaasConfig = RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, null);
        fail("Expected IllegalArgumentException because the AliasService is not available.");
    } catch (IllegalArgumentException e) {
        // Expected
        assertTrue(e.getMessage().contains("AliasService"));
    } catch (Throwable e) {
        fail("Wrong exception encountered: " + e.getClass().getName() + ", " + e.getMessage());
    } finally {
        Configuration.setConfiguration(null);
    }
}
Also used : RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig) RemoteConfigurationRegistryJAASConfig(org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with RemoteConfigurationRegistryJAASConfig

use of org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig in project knox by apache.

the class RemoteConfigurationRegistryJAASConfigTest method testKerberosContextEntry.

@Test
public void testKerberosContextEntry() throws Exception {
    List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
    final String ENTRY_NAME = "my_kerberos_context";
    final String PRINCIPAL = "myIdentity";
    File dummyKeyTab = File.createTempFile("my_context", "keytab");
    registryConfigs.add(createKerberosConfig(ENTRY_NAME, PRINCIPAL, dummyKeyTab.getAbsolutePath()));
    try {
        RemoteConfigurationRegistryJAASConfig jaasConfig = RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, null);
        // Make sure there are no entries for an invalid context entry name
        assertNull(jaasConfig.getAppConfigurationEntry("invalid"));
        // Validate the intended context entry
        validateKerberosContext(jaasConfig, ENTRY_NAME, PRINCIPAL, dummyKeyTab.getAbsolutePath(), true, false);
    } finally {
        Configuration.setConfiguration(null);
    }
}
Also used : 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)

Aggregations

ArrayList (java.util.ArrayList)4 RemoteConfigurationRegistryConfig (org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig)4 RemoteConfigurationRegistryJAASConfig (org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig)4 Test (org.junit.Test)4 File (java.io.File)2 AliasService (org.apache.knox.gateway.services.security.AliasService)2