use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.
the class WebXmlAssetTest method testInvalidLoginAuthMethod.
@Test
public void testInvalidLoginAuthMethod() throws Exception {
WebXmlAsset asset = new WebXmlAsset();
assertThat(asset.getLoginRealm(null)).isNull();
assertThat(asset.getLoginRealm("")).isNull();
assertThat(asset.getLoginRealm(" ")).isNull();
}
use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.
the class MPJWTAuthExtensionArchivePreparer method process.
@Override
public void process() throws Exception {
WARArchive war = archive.as(WARArchive.class);
// Check for LoginConfig annotation
Collection<AnnotationInstance> lcAnnotations = index.getAnnotations(LOGIN_CONFIG);
for (AnnotationInstance lc : lcAnnotations) {
AnnotationValue authMethod = lc.value("authMethod");
AnnotationValue realmName = lc.value("realmName");
String realm = realmName != null ? realmName.asString() : "";
// Set the web.xml login-config auth-method and jboss-web.xml security domain
if (authMethod != null) {
WebXmlAsset webXml = war.findWebXmlAsset();
webXml.setLoginConfig(authMethod.asString(), realm);
}
if (realm.length() > 0) {
JBossWebAsset jBossWeb = war.findJbossWebAsset();
jBossWeb.setSecurityDomain(realm);
}
}
// Get the @ApplicationPath setting
WebXmlAsset webXml = war.findWebXmlAsset();
String appPath = "/";
Collection<AnnotationInstance> appPaths = index.getAnnotations(APP_PATH);
if (!appPaths.isEmpty()) {
appPath = appPaths.iterator().next().value().asString();
}
// Process the @RolesAllowed, @PermitAll and @DenyAll annotations
Collection<AnnotationInstance> rolesAnnotations = index.getAnnotations(ROLES_ALLOWED);
for (AnnotationInstance annotation : rolesAnnotations) {
if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
// Process the root resource
String[] roles = annotation.value().asStringArray();
ClassInfo classInfo = annotation.target().asClass();
if (!scannedClasses.contains(classInfo.name())) {
generateSecurityConstraints(webXml, classInfo, roles, appPath);
}
} else if (annotation.target().kind() == AnnotationTarget.Kind.METHOD) {
// Process the containing root resource if it has not been already
MethodInfo methodInfo = annotation.target().asMethod();
ClassInfo classInfo = methodInfo.declaringClass();
if (!scannedClasses.contains(classInfo.name())) {
String[] roles = {};
generateSecurityConstraints(webXml, classInfo, roles, appPath);
}
}
}
// Handle the verification configuration on the fraction
if (fraction.getTokenIssuer().isPresent()) {
log.debugf("Issuer: %s", fraction.getTokenIssuer().get());
war.addAsManifestResource(new StringAsset(fraction.getTokenIssuer().get()), "MP-JWT-ISSUER");
}
if (fraction.getPublicKey() != null) {
log.debugf("PublicKey: %s", fraction.getPublicKey());
war.addAsManifestResource(new StringAsset(fraction.getPublicKey()), "MP-JWT-SIGNER");
}
if (log.isTraceEnabled()) {
log.trace("war: " + war.toString(true));
}
}
use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.
the class FlywayMigrationArchivePreparer method process.
@Override
public void process() {
if (archive.getName().endsWith(".war")) {
WARArchive webArchive = archive.as(WARArchive.class);
WebXmlAsset webXml = webArchive.findWebXmlAsset();
webXml.addListener("org.wildfly.swarm.flyway.deployment.FlywayMigrationServletContextListener");
FlywayFraction flywayFraction = flywayFractionInstance.get();
if (flywayFraction.usePrimaryDataSource()) {
String dataSourceJndi = getDatasourceNameJndi();
webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JNDI_DATASOURCE, dataSourceJndi);
} else {
webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_URL, flywayFraction.jdbcUrl());
webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_USER, flywayFraction.jdbcUser());
webXml.setContextParam(FlywayMigrationServletContextListener.FLYWAY_JDBC_PASSWORD, flywayFraction.jdbcPassword());
}
}
}
use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.
the class JaegerInstaller method process.
@Override
public void process() throws Exception {
JaegerFraction fraction = jaegerFractionInstance.get();
logger.info("Determining whether to install Jaeger integration or not.");
logger.info("JaegerFraction instance: " + fraction);
if (archive.getName().endsWith(".war")) {
logger.logf(Logger.Level.INFO, "Installing the Jaeger integration for the deployment %s", archive.getName());
WARArchive webArchive = archive.as(WARArchive.class);
WebXmlAsset webXml = webArchive.findWebXmlAsset();
logger.logf(Logger.Level.INFO, "Adding the listener org.wildfly.swarm.jaeger.deployment.JaegerInitializer");
webXml.addListener("org.wildfly.swarm.jaeger.deployment.JaegerInitializer");
setContextParamIfNotNull(webXml, JAEGER_SERVICE_NAME, fraction.getServiceName());
setContextParamIfNotNull(webXml, JAEGER_SERVICE_NAME, fraction.getServiceName());
setContextParamIfNotNull(webXml, JAEGER_SAMPLER_TYPE, fraction.getSamplerType());
setContextParamIfNotNull(webXml, JAEGER_SAMPLER_PARAM, fraction.getSamplerParameter());
setContextParamIfNotNull(webXml, JAEGER_SAMPLER_MANAGER_HOST_PORT, fraction.getSamplerManagerHost());
setContextParamIfNotNull(webXml, JAEGER_REPORTER_LOG_SPANS, fraction.getReporterLogSpans());
setContextParamIfNotNull(webXml, JAEGER_AGENT_HOST, fraction.getAgentHost());
setContextParamIfNotNull(webXml, JAEGER_AGENT_PORT, fraction.getAgentPort());
setContextParamIfNotNull(webXml, JAEGER_REPORTER_FLUSH_INTERVAL, fraction.getReporterFlushInterval());
setContextParamIfNotNull(webXml, JAEGER_REPORTER_MAX_QUEUE_SIZE, fraction.getReporterMaxQueueSize());
webXml.setContextParam("skipOpenTracingResolver", "true");
}
}
use of org.wildfly.swarm.undertow.descriptors.WebXmlAsset in project wildfly-swarm by wildfly-swarm.
the class OpenTracingInstaller method process.
@Override
public void process() throws Exception {
logger.info("Determining whether to install OpenTracing integration or not.");
if (archive.getName().endsWith(".war")) {
logger.logf(Logger.Level.INFO, "Installing the OpenTracing integration for the deployment %s", archive.getName());
WARArchive webArchive = archive.as(WARArchive.class);
WebXmlAsset webXml = webArchive.findWebXmlAsset();
logger.logf(Logger.Level.INFO, "Adding the listener org.wildfly.swarm.opentracing.deployment.OpenTracingInitializer");
webXml.addListener("org.wildfly.swarm.opentracing.deployment.OpenTracingInitializer");
setContextParamIfNotNull(webXml, TracingFilter.SKIP_PATTERN, fraction.getServletSkipPattern());
}
}
Aggregations