Search in sources :

Example 1 with RemoteConfigurationRegistryConfig

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

the class CuratorClientService method init.

@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
    List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
    // Load the remote registry configurations
    registryConfigs.addAll(RemoteConfigurationRegistriesAccessor.getRemoteRegistryConfigurations(config));
    // Configure registry authentication
    RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);
    if (registryConfigs.size() > 1) {
        // Warn about current limit on number of supported client configurations
        log.multipleRemoteRegistryConfigurations();
    }
    // Create the clients
    for (RemoteConfigurationRegistryConfig registryConfig : registryConfigs) {
        if (TYPE.equalsIgnoreCase(registryConfig.getRegistryType())) {
            RemoteConfigurationRegistryClient registryClient = createClient(registryConfig);
            clients.put(registryConfig.getName(), registryClient);
        }
    }
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig) ArrayList(java.util.ArrayList)

Example 2 with RemoteConfigurationRegistryConfig

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

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

the class RemoteConfigurationRegistryJAASConfigTest method createDigestConfig.

private static RemoteConfigurationRegistryConfig createDigestConfig(String entryName, String principal, String credentialAlias, String registryType) {
    RemoteConfigurationRegistryConfig rc = EasyMock.createNiceMock(RemoteConfigurationRegistryConfig.class);
    EasyMock.expect(rc.getRegistryType()).andReturn(registryType).anyTimes();
    EasyMock.expect(rc.getName()).andReturn(entryName).anyTimes();
    EasyMock.expect(rc.isSecureRegistry()).andReturn(true).anyTimes();
    EasyMock.expect(rc.getAuthType()).andReturn("digest").anyTimes();
    EasyMock.expect(rc.getPrincipal()).andReturn(principal).anyTimes();
    EasyMock.expect(rc.getCredentialAlias()).andReturn(credentialAlias).anyTimes();
    EasyMock.replay(rc);
    return rc;
}
Also used : RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig)

Example 4 with RemoteConfigurationRegistryConfig

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

the class RemoteConfigurationRegistryJAASConfigTest method createKerberosConfig.

private static RemoteConfigurationRegistryConfig createKerberosConfig(String entryName, String principal, String keyTabPath, Boolean useKeyTab, Boolean useTicketCache, String registryType) {
    RemoteConfigurationRegistryConfig rc = EasyMock.createNiceMock(RemoteConfigurationRegistryConfig.class);
    EasyMock.expect(rc.getRegistryType()).andReturn(registryType).anyTimes();
    EasyMock.expect(rc.getName()).andReturn(entryName).anyTimes();
    EasyMock.expect(rc.isSecureRegistry()).andReturn(true).anyTimes();
    EasyMock.expect(rc.getAuthType()).andReturn("kerberos").anyTimes();
    EasyMock.expect(rc.getPrincipal()).andReturn(principal).anyTimes();
    EasyMock.expect(rc.getKeytab()).andReturn(keyTabPath).anyTimes();
    EasyMock.expect(rc.isUseKeyTab()).andReturn(useKeyTab != null ? useKeyTab : true).anyTimes();
    EasyMock.expect(rc.isUseTicketCache()).andReturn(useTicketCache != null ? useTicketCache : false).anyTimes();
    EasyMock.replay(rc);
    return rc;
}
Also used : RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig)

Example 5 with RemoteConfigurationRegistryConfig

use of org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig 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)

Aggregations

RemoteConfigurationRegistryConfig (org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig)10 ArrayList (java.util.ArrayList)7 File (java.io.File)5 Test (org.junit.Test)5 RemoteConfigurationRegistryJAASConfig (org.apache.knox.gateway.service.config.remote.zk.RemoteConfigurationRegistryJAASConfig)4 AliasService (org.apache.knox.gateway.services.security.AliasService)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 RemoteConfigurationRegistryClient (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient)1