use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project knox by apache.
the class DeploymentFactory method createDeploymentContext.
private static DeploymentContext createDeploymentContext(GatewayConfig config, String archivePath, Topology topology, Map<String, List<ProviderDeploymentContributor>> providers) {
archivePath = Urls.encode(archivePath);
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, archivePath);
WebAppDescriptor webAppDesc = Descriptors.create(WebAppDescriptor.class);
GatewayDescriptor gateway = GatewayDescriptorFactory.create();
DeploymentContext context = new DeploymentContextImpl(config, topology, gateway, webArchive, webAppDesc, providers);
return context;
}
use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project knox by apache.
the class DeploymentFactory method finalize.
private static void finalize(DeploymentContext context, Map<String, List<ProviderDeploymentContributor>> providers, Map<String, List<ServiceDeploymentContributor>> services, Map.Entry<String, ServiceDeploymentContributor> application) {
try {
// Write the gateway descriptor (gateway.xml) into the war.
StringWriter writer = new StringWriter();
GatewayDescriptorFactory.store(context.getGatewayDescriptor(), "xml", writer);
context.getWebArchive().addAsWebInfResource(new StringAsset(writer.toString()), GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
// Set the location of the gateway descriptor as a servlet init param.
if (application == null) {
String servletName = context.getTopology().getName() + SERVLET_NAME_SUFFIX;
ServletType<WebAppDescriptor> servlet = findServlet(context, servletName);
// Coverity CID 1352314
if (servlet == null) {
throw new DeploymentException("Missing servlet " + servletName);
} else {
servlet.createInitParam().paramName(GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_PARAM).paramValue("/WEB-INF/" + GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
}
} else {
String servletName = context.getTopology().getName() + FILTER_NAME_SUFFIX;
FilterType<WebAppDescriptor> filter = findFilter(context, servletName);
// Coverity CID 1352313
if (filter == null) {
throw new DeploymentException("Missing filter " + servletName);
} else {
filter.createInitParam().paramName(GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_PARAM).paramValue("/WEB-INF/" + GatewayServlet.GATEWAY_DESCRIPTOR_LOCATION_DEFAULT);
}
}
if (gatewayServices != null) {
gatewayServices.finalizeContribution(context);
}
finalizeProviders(context, providers);
finalizeServices(context, services);
finalizeApplications(context, application);
writeDeploymentDescriptor(context, application != null);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project knox by apache.
the class DeploymentFactory method initialize.
private static void initialize(DeploymentContext context, Map<String, List<ProviderDeploymentContributor>> providers, Map<String, List<ServiceDeploymentContributor>> services, Map.Entry<String, ServiceDeploymentContributor> applications) {
WebAppDescriptor wad = context.getWebAppDescriptor();
String topoName = context.getTopology().getName();
if (applications == null) {
String servletName = topoName + SERVLET_NAME_SUFFIX;
wad.createServlet().servletName(servletName).servletClass(GatewayServlet.class.getName());
wad.createServletMapping().servletName(servletName).urlPattern("/*");
} else {
String filterName = topoName + FILTER_NAME_SUFFIX;
wad.createFilter().filterName(filterName).filterClass(GatewayServlet.class.getName());
wad.createFilterMapping().filterName(filterName).urlPattern("/*");
}
if (gatewayServices != null) {
gatewayServices.initializeContribution(context);
} else {
log.gatewayServicesNotInitialized();
}
initializeProviders(context, providers);
initializeServices(context, services);
initializeApplications(context, applications);
}
use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparerTest method unsupported_auth_method.
@Test
public void unsupported_auth_method() throws Exception {
Map<String, Object> deploymentConfig = createConfigStub();
Map<String, Object> webConfig = findWebConfig(deploymentConfig);
Map<String, Object> loginConfig = new HashMap<>();
loginConfig.put("auth-method", "foobar");
webConfig.put("login-config", loginConfig);
preparer.deploymentConfigs = deploymentConfig;
preparer.process();
WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
assertThat(webXml.getOrCreateLoginConfig().getAuthMethod()).isEqualTo("foobar");
}
use of org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparerTest method yaml_parsing_again.
@SuppressWarnings("unchecked")
@Test
public void yaml_parsing_again() throws Exception {
InputStream in = getClass().getClassLoader().getResourceAsStream("security2.yml");
assertThat(in).isNotNull().as("security2.yml is null");
Yaml yaml = new Yaml();
Map<String, Object> httpConfig = (Map<String, Object>) yaml.load(in);
preparer.deploymentConfigs = (Map) ((Map) httpConfig.get("swarm")).get("deployment");
preparer.process();
WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(1);
assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/protected");
}
Aggregations