use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DefaultTopologyServiceTest method testProviderParamsOrderIsPreserved.
@Test
public void testProviderParamsOrderIsPreserved() {
Provider provider = new Provider();
String[] names = { "ldapRealm=", "ldapContextFactory", "ldapRealm.contextFactory", "ldapGroupRealm", "ldapGroupRealm.contextFactory", "ldapGroupRealm.contextFactory.systemAuthenticationMechanism" };
Param param = null;
for (String name : names) {
param = new Param();
param.setName(name);
param.setValue(name);
provider.addParam(param);
}
Map<String, String> params = provider.getParams();
Set<String> keySet = params.keySet();
Iterator<String> iter = keySet.iterator();
int i = 0;
while (iter.hasNext()) {
assertTrue(iter.next().equals(names[i++]));
}
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class ProviderParameterPropertyInterpreter method interpret.
@Override
public void interpret(String token, String value) throws InterpretException {
if (token == null || token.isEmpty()) {
throw new InterpretException(gatewayResources.providerParameterNameIsRequiredError());
}
if (value == null || value.isEmpty()) {
throw new InterpretException(gatewayResources.providerParameterValueIsRequiredError());
}
Param param = new Param();
param.setName(token);
param.setValue(value);
provider.addParam(param);
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class GatewayAdminTopologyFuncTest method createTestTopology.
private Topology createTestTopology() {
Topology topology = new Topology();
topology.setName("test-topology");
try {
topology.setUri(new URI(gatewayUrl + "/" + topology.getName()));
} catch (URISyntaxException ex) {
assertThat(topology.getUri(), not(nullValue()));
}
Provider identityProvider = new Provider();
identityProvider.setName("Default");
identityProvider.setRole("identity-assertion");
identityProvider.setEnabled(true);
Provider AuthenicationProvider = new Provider();
AuthenicationProvider.setName("ShiroProvider");
AuthenicationProvider.setRole("authentication");
AuthenicationProvider.setEnabled(true);
Param ldapMain = new Param();
ldapMain.setName("main.ldapRealm");
ldapMain.setValue("org.apache.knox.gateway.shirorealm.KnoxLdapRealm");
Param ldapGroupContextFactory = new Param();
ldapGroupContextFactory.setName("main.ldapGroupContextFactory");
ldapGroupContextFactory.setValue("org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory");
Param ldapRealmContext = new Param();
ldapRealmContext.setName("main.ldapRealm.contextFactory");
ldapRealmContext.setValue("$ldapGroupContextFactory");
Param ldapURL = new Param();
ldapURL.setName("main.ldapRealm.contextFactory.url");
ldapURL.setValue(driver.getLdapUrl());
Param ldapUserTemplate = new Param();
ldapUserTemplate.setName("main.ldapRealm.userDnTemplate");
ldapUserTemplate.setValue("uid={0},ou=people,dc=hadoop,dc=apache,dc=org");
Param authcBasic = new Param();
authcBasic.setName("urls./**");
authcBasic.setValue("authcBasic");
AuthenicationProvider.addParam(ldapGroupContextFactory);
AuthenicationProvider.addParam(ldapMain);
AuthenicationProvider.addParam(ldapRealmContext);
AuthenicationProvider.addParam(ldapURL);
AuthenicationProvider.addParam(ldapUserTemplate);
AuthenicationProvider.addParam(authcBasic);
Service testService = new Service();
testService.setRole("test-service-role");
topology.addProvider(AuthenicationProvider);
topology.addProvider(identityProvider);
topology.addService(testService);
topology.setTimestamp(System.nanoTime());
return topology;
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testDeploymentWithServiceParams.
@Test(timeout = LONG_TIMEOUT)
public void testDeploymentWithServiceParams() throws Exception {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Service service;
Param param;
Topology topology = new Topology();
topology.setName("test-cluster");
service = new Service();
service.setRole("HIVE");
service.setUrls(Arrays.asList(new String[] { "http://hive-host:50001/" }));
param = new Param();
param.setName("someparam");
param.setValue("somevalue");
service.addParam(param);
topology.addService(service);
service = new Service();
service.setRole("WEBHBASE");
service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50002/" }));
param = new Param();
param.setName("replayBufferSize");
param.setValue("33");
service.addParam(param);
topology.addService(service);
service = new Service();
service.setRole("OOZIE");
service.setUrls(Arrays.asList(new String[] { "http://hbase-host:50003/" }));
param = new Param();
param.setName("otherparam");
param.setValue("65");
service.addParam(param);
topology.addService(service);
EnterpriseArchive war = DeploymentFactory.createDeployment(config, topology);
Document doc = XmlUtils.readXml(war.get("%2F/WEB-INF/gateway.xml").getAsset().openStream());
// dump( doc );
Node resourceNode, filterNode, paramNode;
String value;
resourceNode = node(doc, "gateway/resource[role/text()='HIVE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='someparam']");
value = value(paramNode, "value/text()");
assertThat(value, is("somevalue"));
resourceNode = node(doc, "gateway/resource[role/text()='WEBHBASE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='replayBufferSize']");
value = value(paramNode, "value/text()");
assertThat(value, is("33"));
resourceNode = node(doc, "gateway/resource[role/text()='OOZIE']");
assertThat(resourceNode, is(not(nullValue())));
filterNode = node(resourceNode, "filter[role/text()='dispatch']");
assertThat(filterNode, is(not(nullValue())));
paramNode = node(filterNode, "param[name/text()='otherparam']");
value = value(paramNode, "value/text()");
assertThat(value, is("65"));
FileUtils.deleteQuietly(deployDir);
LOG_EXIT();
}
use of org.apache.knox.gateway.topology.Param in project knox by apache.
the class DeploymentFactoryFuncTest method testWebXmlGeneration.
@Test(timeout = LONG_TIMEOUT)
public void testWebXmlGeneration() throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
LOG_ENTER();
GatewayConfig config = new GatewayTestConfig();
File targetDir = new File(System.getProperty("user.dir"), "target");
File gatewayDir = new File(targetDir, "gateway-home-" + UUID.randomUUID());
gatewayDir.mkdirs();
((GatewayTestConfig) config).setGatewayHomeDir(gatewayDir.getAbsolutePath());
File deployDir = new File(config.getGatewayDeploymentDir());
deployDir.mkdirs();
DefaultGatewayServices srvcs = new DefaultGatewayServices();
Map<String, String> options = new HashMap<>();
options.put("persist-master", "false");
options.put("master", "password");
try {
DeploymentFactory.setGatewayServices(srvcs);
srvcs.init(config, options);
} catch (ServiceLifecycleException e) {
// I18N not required.
e.printStackTrace();
}
Topology topology = new Topology();
topology.setName("test-cluster");
Service service = new Service();
service.setRole("WEBHDFS");
service.addUrl("http://localhost:50070/webhdfs");
topology.addService(service);
Provider provider = new Provider();
provider.setRole("authentication");
provider.setName("ShiroProvider");
provider.setEnabled(true);
Param param = new Param();
param.setName("contextConfigLocation");
param.setValue("classpath:app-context-security.xml");
provider.addParam(param);
topology.addProvider(provider);
Provider asserter = new Provider();
asserter.setRole("identity-assertion");
asserter.setName("Default");
asserter.setEnabled(true);
topology.addProvider(asserter);
Provider authorizer = new Provider();
authorizer.setRole("authorization");
authorizer.setName("AclsAuthz");
authorizer.setEnabled(true);
topology.addProvider(authorizer);
Provider ha = new Provider();
ha.setRole("ha");
ha.setName("HaProvider");
ha.setEnabled(true);
topology.addProvider(ha);
for (int i = 0; i < 10; i++) {
createAndTestDeployment(config, topology);
}
LOG_EXIT();
}
Aggregations