use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project tomee by apache.
the class DataSourceDefinitionTest method createDeployment.
@Deployment(testable = false)
public static WebArchive createDeployment() {
WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class).version(WebAppVersionType._3_0).createServlet().servletName(SERVLET_NAME).servletClass(DataSourceServlet.class.getName()).up().createServletMapping().servletName(SERVLET_NAME).urlPattern("/" + TEST_NAME).up();
WebArchive archive = ShrinkWrap.create(WebArchive.class, TEST_NAME + ".war").addClass(DataSourceDefinitionTest.class).addClass(DataSourceServlet.class).addClass(DataSourceBean.class).addClass(DataSourcePojo.class).addClass(Runner.class).addAsLibraries(JarLocation.jarLocation(Test.class)).addAsWebInfResource(new ClassLoaderAsset(CONTENT_LOCATION_EJB_JAR_XML), RESOURCE_EJB_JAR_XML).setWebXML(new StringAsset(descriptor.exportAsString()));
return archive;
}
use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project tomee by apache.
the class EARTest method createDeployment.
@Deployment
public static EnterpriseArchive createDeployment() {
final JavaArchive apiJar = ShrinkWrap.create(JavaArchive.class, "connector-sample-api.jar");
apiJar.addPackage("org.superbiz.connector.api");
System.out.println("API JAR:\n" + apiJar.toString(true));
final JavaArchive implJar = ShrinkWrap.create(JavaArchive.class, "connector-sample-impl.jar");
implJar.addPackage("org.superbiz.connector.adapter");
System.out.println("IMPL JAR:\n" + implJar.toString(true));
final ResourceAdapterArchive rar = ShrinkWrap.create(ResourceAdapterArchive.class, "connector-sample-ra.rar");
rar.addAsLibraries(implJar);
final File raXml = Basedir.basedir("../connector-sample-rar/src/main/rar/META-INF/ra.xml");
rar.setResourceAdapterXML(raXml);
System.out.println("RAR:\n" + rar.toString(true));
final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "connector-sample-war.war");
webArchive.addPackage("org.superbiz.application");
final WebAppDescriptor webAppDescriptor = Descriptors.create(WebAppDescriptor.class);
webAppDescriptor.version("3.0");
final File resourcesXml = Basedir.basedir("../connector-sample-war/src/main/webapp/WEB-INF/resources.xml");
webArchive.addAsWebInfResource(resourcesXml);
webArchive.setWebXML(new StringAsset(webAppDescriptor.exportAsString()));
webArchive.addAsWebInfResource(resourcesXml);
webArchive.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
System.out.println("Webapp:\n" + webArchive.toString(true));
final EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class, "connector-sample.ear");
enterpriseArchive.addAsLibraries(apiJar);
enterpriseArchive.addAsModule(rar);
enterpriseArchive.addAsModule(webArchive);
ApplicationDescriptor applicationXml = Descriptors.create(ApplicationDescriptor.class);
applicationXml.displayName("connector-sample-ear");
applicationXml.createModule().getOrCreateWeb().webUri("connector-sample-war.war").contextRoot("/sample").up().up().createModule().connector("connector-sample-ra.rar").up().libraryDirectory("lib");
enterpriseArchive.setApplicationXML(new StringAsset(applicationXml.exportAsString()));
System.out.println(enterpriseArchive.toString(true));
return enterpriseArchive;
}
use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project knox by apache.
the class ShiroDeploymentContributor method contributeProvider.
@Override
public void contributeProvider(DeploymentContext context, Provider provider) {
// Many filter based authentication mechanisms require a ServletContextListener
// to be added and the Knox deployment machinery provides the ability to add this
// through the DeploymentContext.
// Writing provider specific config out to the war for cluster specific config can be
// accomplished through the DeploymentContext as well. The JBoss shrinkwrap API can be
// used to write the asset to the war.
// add servletContextListener
context.getWebAppDescriptor().createListener().listenerClass(LISTENER_CLASSNAME);
// add session timeout
int st = DEFAULT_SESSION_TIMEOUT;
SessionConfigType<WebAppDescriptor> sessionConfig = context.getWebAppDescriptor().createSessionConfig();
Map<String, String> params = provider.getParams();
String sts = params.get(SESSION_TIMEOUT);
if (sts != null && sts.trim().length() != 0) {
st = Integer.parseInt(sts.trim());
}
if (st <= 0) {
// user default session timeout
st = DEFAULT_SESSION_TIMEOUT;
}
sessionConfig.sessionTimeout(st);
sessionConfig.getOrCreateCookieConfig().httpOnly(true);
sessionConfig.getOrCreateCookieConfig().secure(true);
String clusterName = context.getTopology().getName();
ShiroConfig config = new ShiroConfig(provider, clusterName);
String configStr = config.toString();
if (config != null) {
context.getWebArchive().addAsWebInfResource(new StringAsset(configStr), SHRIO_CONFIG_FILE_NAME);
}
}
use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparerTest method set_2_security_constraints.
@Test
public void set_2_security_constraints() throws Exception {
Map<String, Object> deploymentConfig = createConfigStub();
Map<String, Object> webConfig = findWebConfig(deploymentConfig);
Map<String, Object> securityConstraint1 = new HashMap<>();
securityConstraint1.put("url-pattern", "/aaa");
Map<String, Object> securityConstraint2 = new HashMap<>();
securityConstraint2.put("url-pattern", "/bbb");
webConfig.put("security-constraints", Arrays.asList(securityConstraint1, securityConstraint2));
preparer.deploymentConfigs = deploymentConfig;
preparer.process();
WebAppDescriptor webXml = Descriptors.importAs(WebAppDescriptor.class).fromStream(archive.get(WebXmlAsset.NAME).getAsset().openStream());
assertThat(webXml.getAllSecurityConstraint().size()).isEqualTo(2);
assertThat(webXml.getAllSecurityConstraint().get(0).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/aaa");
assertThat(webXml.getAllSecurityConstraint().get(1).getAllWebResourceCollection().get(0).getAllUrlPattern().get(0)).isEqualTo("/bbb");
}
use of org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor in project wildfly-swarm by wildfly-swarm.
the class HttpSecurityPreparerTest method set_1_security_constraint.
@Test
public void set_1_security_constraint() throws Exception {
Map<String, Object> deploymentConfig = createConfigStub();
Map<String, Object> webConfig = findWebConfig(deploymentConfig);
Map<String, Object> securityConstraint = new HashMap<>();
securityConstraint.put("url-pattern", "/aaa");
webConfig.put("security-constraints", Collections.singletonList(securityConstraint));
preparer.deploymentConfigs = deploymentConfig;
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("/aaa");
}
Aggregations