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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations