use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.
the class TopologiesResource method uploadSimpleDescriptor.
@PUT
@Consumes({ APPLICATION_JSON, TEXT_PLAIN })
@Path(SINGLE_DESCRIPTOR_API_PATH)
public Response uploadSimpleDescriptor(@PathParam("name") String name, @Context HttpHeaders headers, String content) {
Response response = null;
GatewayServices gs = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
TopologyService ts = gs.getService(GatewayServices.TOPOLOGY_SERVICE);
File existing = getExistingConfigFile(ts.getDescriptors(), name);
boolean isUpdate = (existing != null);
// If it's an update, then use the matching existing filename; otherwise, use the media type to determine the file
// extension.
String filename = isUpdate ? existing.getName() : getFileNameForResource(name, headers);
if (ts.deployDescriptor(filename, content)) {
try {
if (isUpdate) {
response = Response.noContent().build();
} else {
response = created(new URI(buildHref(request))).build();
}
} catch (URISyntaxException e) {
log.invalidResourceURI(e.getInput(), e.getReason(), e);
response = status(Response.Status.BAD_REQUEST).entity("{ \"error\" : \"Failed to deploy descriptor " + name + "\" }").build();
}
}
return response;
}
use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.
the class VersionResource method getServerVersion.
/**
* @return
*/
private ServerVersion getServerVersion() {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
ServerInfoService sis = services.getService(GatewayServices.SERVER_INFO_SERVICE);
return new ServerVersion(sis.getBuildVersion(), sis.getBuildHash());
}
use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.
the class KnoxLdapContextFactory method setSystemPassword.
@Override
public void setSystemPassword(String systemPass) {
if (systemPass == null) {
return;
}
systemPass = systemPass.trim();
if (systemPass.length() == 0) {
return;
}
if (!systemPass.startsWith("S{ALIAS=")) {
super.setSystemPassword(systemPass);
return;
}
systemPass = systemPass.substring("S{ALIAS=".length(), systemPass.length() - 1);
String aliasName = systemPass;
GatewayServices services = GatewayServer.getGatewayServices();
AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
String clusterName = getClusterName();
// System.err.println("FACTORY systempass 30: " + systemPass);
// System.err.println("FACTORY clustername 40: " + clusterName);
// System.err.println("FACTORY SystemProperty GatewayHome 50: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
char[] password = null;
try {
password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
} catch (AliasServiceException e) {
LOG.unableToGetPassword(e);
}
// System.err.println("FACTORY password: " + ((password == null) ? "NULL" : new String(password)));
if (password != null) {
// System.err.println("FACTORY SUCCESS 20 system password :" + new String(password));
super.setSystemPassword(new String(password));
} else {
// System.err.println("FACTORY FORCING system password to blank");
super.setSystemPassword("");
LOG.aliasValueNotFound(clusterName, aliasName);
}
}
use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.
the class ShiroDeploymentContributorTest method testDeployment.
@Test
public void testDeployment() throws IOException {
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test-archive");
Map<String, String> providerParams = new HashMap<>();
Provider provider = new Provider();
provider.setEnabled(true);
provider.setName("shiro");
provider.setParams(providerParams);
Topology topology = new Topology();
topology.setName("Sample");
DeploymentContext context = EasyMock.createNiceMock(DeploymentContext.class);
EasyMock.expect(context.getWebArchive()).andReturn(webArchive).anyTimes();
EasyMock.expect(context.getWebAppDescriptor()).andReturn(Descriptors.create(WebAppDescriptor.class)).anyTimes();
EasyMock.expect(context.getTopology()).andReturn(topology).anyTimes();
EasyMock.replay(context);
AliasService as = EasyMock.createNiceMock(AliasService.class);
CryptoService cryptoService = new DefaultCryptoService();
((DefaultCryptoService) cryptoService).setAliasService(as);
GatewayServices gatewayServices = EasyMock.createNiceMock(GatewayServices.class);
EasyMock.expect(gatewayServices.getService(GatewayServices.CRYPTO_SERVICE)).andReturn(cryptoService).anyTimes();
ShiroDeploymentContributor contributor = new ShiroDeploymentContributor();
assertThat(contributor.getRole(), is("authentication"));
assertThat(contributor.getName(), is("ShiroProvider"));
// Just make sure it doesn't blow up.
contributor.initializeContribution(context);
contributor.contributeProvider(context, provider);
// Just make sure it doesn't blow up.
contributor.finalizeContribution(context);
assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isHttpOnly(), is(true));
assertThat(context.getWebAppDescriptor().getOrCreateSessionConfig().getOrCreateCookieConfig().isSecure(), is(true));
}
use of org.apache.knox.gateway.services.GatewayServices in project knox by apache.
the class HaServletContextListener method setupHaProvider.
private void setupHaProvider(HaDescriptor descriptor, ServletContext servletContext) {
GatewayServices services = (GatewayServices) servletContext.getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
String clusterName = (String) servletContext.getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
ServiceRegistry serviceRegistry = services.getService(GatewayServices.SERVICE_REGISTRY_SERVICE);
HaProvider provider = new DefaultHaProvider(descriptor);
List<String> serviceNames = descriptor.getEnabledServiceNames();
for (String serviceName : serviceNames) {
provider.addHaService(serviceName, serviceRegistry.lookupServiceURLs(clusterName, serviceName));
}
servletContext.setAttribute(PROVIDER_ATTRIBUTE_NAME, provider);
}
Aggregations