use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class OidcActivationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null) {
return;
}
JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
if (webMetaData == null) {
webMetaData = new JBossWebMetaData();
warMetaData.setMergedJBossWebMetaData(webMetaData);
}
OidcConfigService configService = OidcConfigService.getInstance();
if (configService.isSecureDeployment(deploymentUnit) && configService.isDeploymentConfigured(deploymentUnit)) {
addOidcAuthDataAndConfig(phaseContext, configService, webMetaData);
}
LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
if (loginConfig != null && OIDC_AUTH_METHOD.equals(loginConfig.getAuthMethod())) {
ListenerMetaData listenerMetaData = new ListenerMetaData();
listenerMetaData.setListenerClass(OidcConfigurationServletListener.class.getName());
webMetaData.getListeners().add(listenerMetaData);
ROOT_LOGGER.tracef("Activating OIDC for deployment %s.", deploymentUnit.getName());
OidcDeploymentMarker.mark(deploymentUnit);
VirtualHttpServerMechanismFactoryMarkerUtility.virtualMechanismFactoryRequired(deploymentUnit);
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class JaxrsIntegrationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!JaxrsDeploymentMarker.isJaxrsDeployment(deploymentUnit)) {
return;
}
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
return;
}
final DeploymentUnit parent = deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
final JBossWebMetaData webdata = warMetaData.getMergedJBossWebMetaData();
setConfigParameters(phaseContext, webdata);
final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA);
if (resteasy == null)
return;
deploymentUnit.getDeploymentSubsystemModel(JaxrsExtension.SUBSYSTEM_NAME);
final List<ParamValueMetaData> params = webdata.getContextParams();
boolean entityExpandEnabled = false;
if (params != null) {
Iterator<ParamValueMetaData> it = params.iterator();
while (it.hasNext()) {
final ParamValueMetaData param = it.next();
if (param.getParamName().equals(ResteasyContextParameters.RESTEASY_EXPAND_ENTITY_REFERENCES)) {
entityExpandEnabled = true;
}
}
}
// don't expand entity references by default
if (!entityExpandEnabled) {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_EXPAND_ENTITY_REFERENCES, "false");
}
final Map<ModuleIdentifier, ResteasyDeploymentData> attachmentMap = parent.getAttachment(JaxrsAttachments.ADDITIONAL_RESTEASY_DEPLOYMENT_DATA);
final List<ResteasyDeploymentData> additionalData = new ArrayList<ResteasyDeploymentData>();
final ModuleSpecification moduleSpec = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
if (moduleSpec != null && attachmentMap != null) {
final Set<ModuleIdentifier> identifiers = new HashSet<ModuleIdentifier>();
for (ModuleDependency dep : moduleSpec.getAllDependencies()) {
// make sure we don't double up
if (!identifiers.contains(dep.getIdentifier())) {
identifiers.add(dep.getIdentifier());
if (attachmentMap.containsKey(dep.getIdentifier())) {
additionalData.add(attachmentMap.get(dep.getIdentifier()));
}
}
}
resteasy.merge(additionalData);
}
if (!resteasy.getScannedResourceClasses().isEmpty()) {
StringBuilder buf = null;
for (String resource : resteasy.getScannedResourceClasses()) {
if (buf == null) {
buf = new StringBuilder();
buf.append(resource);
} else {
buf.append(",").append(resource);
}
}
String resources = buf.toString();
JAXRS_LOGGER.debugf("Adding Jakarta RESTful Web Services resource classes: %s", resources);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_RESOURCES, resources);
}
if (!resteasy.getScannedProviderClasses().isEmpty()) {
StringBuilder buf = null;
for (String provider : resteasy.getScannedProviderClasses()) {
if (buf == null) {
buf = new StringBuilder();
buf.append(provider);
} else {
buf.append(",").append(provider);
}
}
String providers = buf.toString();
JAXRS_LOGGER.debugf("Adding Jakarta RESTful Web Services provider classes: %s", providers);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_PROVIDERS, providers);
}
if (!resteasy.getScannedJndiComponentResources().isEmpty()) {
StringBuilder buf = null;
for (String resource : resteasy.getScannedJndiComponentResources()) {
if (buf == null) {
buf = new StringBuilder();
buf.append(resource);
} else {
buf.append(",").append(resource);
}
}
String providers = buf.toString();
JAXRS_LOGGER.debugf("Adding Jakarta RESTful Web Services jndi component resource classes: %s", providers);
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_SCANNED_JNDI_RESOURCES, providers);
}
if (!resteasy.isUnwrappedExceptionsParameterSet()) {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_UNWRAPPED_EXCEPTIONS, "javax.ejb.EJBException");
}
if (findContextParam(webdata, ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB) == null) {
final String prop = WildFlySecurityManager.getPropertyPrivileged(ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, null);
if (prop != null) {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, prop);
} else {
setContextParameter(webdata, ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB, Boolean.toString(hasJacksonAnnotations(deploymentUnit)));
}
}
boolean managementAdded = false;
if (!resteasy.getScannedApplicationClasses().isEmpty() || resteasy.hasBootClasses() || resteasy.isDispatcherCreated()) {
addManagement(deploymentUnit, resteasy);
managementAdded = true;
}
if (resteasy.hasBootClasses() || resteasy.isDispatcherCreated())
return;
// ignore any non-annotated Application class that doesn't have a servlet mapping
Set<Class<? extends Application>> applicationClassSet = new HashSet<>();
for (Class<? extends Application> clazz : resteasy.getScannedApplicationClasses()) {
if (clazz.isAnnotationPresent(ApplicationPath.class) || servletMappingsExist(webdata, clazz.getName())) {
applicationClassSet.add(clazz);
}
}
// add default servlet
if (applicationClassSet.isEmpty()) {
JBossServletMetaData servlet = new JBossServletMetaData();
servlet.setName(JAX_RS_SERVLET_NAME);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
addServlet(webdata, servlet);
setServletMappingPrefix(webdata, JAX_RS_SERVLET_NAME, servlet);
} else {
for (Class<? extends Application> applicationClass : applicationClassSet) {
String servletName = null;
servletName = applicationClass.getName();
JBossServletMetaData servlet = new JBossServletMetaData();
// must load on startup for services like JSAPI to work
servlet.setLoadOnStartup("" + 0);
servlet.setName(servletName);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
setServletInitParam(servlet, SERVLET_INIT_PARAM, applicationClass.getName());
addServlet(webdata, servlet);
if (!servletMappingsExist(webdata, servletName)) {
try {
// no mappings, add our own
List<String> patterns = new ArrayList<String>();
// for some reason the spec requires this to be decoded
String pathValue = URLDecoder.decode(applicationClass.getAnnotation(ApplicationPath.class).value().trim(), "UTF-8");
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
String prefix = pathValue;
if (pathValue.endsWith("/")) {
pathValue += "*";
} else {
pathValue += "/*";
}
patterns.add(pathValue);
setServletInitParam(servlet, "resteasy.servlet.mapping.prefix", prefix);
ServletMappingMetaData mapping = new ServletMappingMetaData();
mapping.setServletName(servletName);
mapping.setUrlPatterns(patterns);
if (webdata.getServletMappings() == null) {
webdata.setServletMappings(new ArrayList<ServletMappingMetaData>());
}
webdata.getServletMappings().add(mapping);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else {
setServletMappingPrefix(webdata, servletName, servlet);
}
}
}
if (!managementAdded && webdata.getServletMappings() != null) {
for (ServletMappingMetaData servletMapMeta : webdata.getServletMappings()) {
if (JAX_RS_SERVLET_NAME.equals(servletMapMeta.getServletName())) {
addManagement(deploymentUnit, resteasy);
break;
}
}
}
// suppress warning for EAR deployments, as we can't easily tell here the app is properly declared
if (deploymentUnit.getParent() == null && (webdata.getServletMappings() == null || webdata.getServletMappings().isEmpty())) {
JAXRS_LOGGER.noServletDeclaration(deploymentUnit.getName());
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class DistributableWebDeploymentDependencyProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
DeploymentUnit unit = context.getDeploymentUnit();
WarMetaData warMetaData = unit.getAttachment(WarMetaData.ATTACHMENT_KEY);
SharedSessionManagerConfig sharedConfig = unit.getAttachment(SharedSessionManagerConfig.ATTACHMENT_KEY);
if (((warMetaData != null) && (warMetaData.getMergedJBossWebMetaData() != null && warMetaData.getMergedJBossWebMetaData().getDistributable() != null)) || ((sharedConfig != null) && sharedConfig.isDistributable())) {
CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
DistributableWebDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY);
String name = (config != null) ? config.getSessionManagementName() : null;
DistributableSessionManagementProvider management = (name == null) && (config != null) ? config.getSessionManagement() : null;
List<String> immutableClasses = (config != null) ? config.getImmutableClasses() : Collections.emptyList();
for (String immutableClass : immutableClasses) {
unit.addToAttachmentList(DistributableSessionManagementProvider.IMMUTABILITY_ATTACHMENT_KEY, immutableClass);
}
if (management != null) {
LOGGER.debugf("%s will use a deployment-specific distributable session management provider", unit.getName());
ServiceTarget target = context.getServiceTarget();
DeploymentUnit parentUnit = unit.getParent();
String deploymentName = (parentUnit != null) ? parentUnit.getName() + "." + unit.getName() : unit.getName();
ServiceName serviceName = WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, deploymentName);
ServiceBuilder<?> builder = target.addService(serviceName);
Consumer<DistributableSessionManagementProvider> injector = builder.provides(serviceName);
Service service = Service.newInstance(injector, management);
builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
context.addDependency(serviceName, DistributableSessionManagementProvider.ATTACHMENT_KEY);
} else {
if (name != null) {
LOGGER.debugf("%s will use the '%s' distributable session management provider", unit.getName(), name);
} else {
LOGGER.debugf("%s will use the default distributable session management provider", unit.getName());
}
context.addDependency(WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER.getServiceName(support, name), DistributableSessionManagementProvider.ATTACHMENT_KEY);
}
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class ExternalTldParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
return;
}
TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
Map<String, TldMetaData> tlds = tldsMetaData.getTlds();
Set<String> sharedTldUris = new HashSet<>();
for (TldMetaData shared : tldsMetaData.getSharedTlds(deploymentUnit)) {
sharedTldUris.add(shared.getUri());
}
Module module = deploymentUnit.getAttachment(Attachments.MODULE);
try {
Iterator<Resource> resources = module.globResources("META-INF/**.tld");
while (resources.hasNext()) {
final Resource resource = resources.next();
// waste time re-parsing them
if (resource.getURL().toString().contains("com/sun/jsf-impl/main")) {
continue;
}
if (resource.getName().startsWith("META-INF/")) {
if (tlds.containsKey(resource.getName())) {
continue;
}
if (resource.getURL().getProtocol().equals("vfs")) {
continue;
}
final TldMetaData value = parseTLD(resource);
if (sharedTldUris.contains(value.getUri())) {
// don't re-include shared TLD's
continue;
}
String key = "/" + resource.getName();
if (!tlds.containsKey(key)) {
tlds.put(key, value);
}
if (!tlds.containsKey(value.getUri())) {
tlds.put(value.getUri(), value);
}
if (value.getListeners() != null) {
for (ListenerMetaData l : value.getListeners()) {
List<ListenerMetaData> listeners = warMetaData.getMergedJBossWebMetaData().getListeners();
if (listeners == null) {
warMetaData.getMergedJBossWebMetaData().setListeners(listeners = new ArrayList<ListenerMetaData>());
}
listeners.add(l);
}
}
}
}
} catch (ModuleLoadException e) {
throw new DeploymentUnitProcessingException(e);
}
}
use of org.jboss.as.web.common.WarMetaData in project wildfly by wildfly.
the class WarStructureDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
if (deploymentRoot == null) {
return;
}
// set the child first behaviour
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
if (moduleSpecification == null) {
return;
}
moduleSpecification.setPrivateModule(true);
// other sub deployments should not have access to classes in the war module
PrivateSubDeploymentMarker.mark(deploymentUnit);
// we do not want to index the resource root, only WEB-INF/classes and WEB-INF/lib
deploymentResourceRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
// Make sure the root does not end up in the module, only META-INF
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfFilter(), true));
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfSubdirectoriesFilter(), true));
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.acceptAll(), false));
ModuleRootMarker.mark(deploymentResourceRoot, true);
// TODO: This needs to be ported to add additional resource roots the standard way
final MountHandle mountHandle = deploymentResourceRoot.getMountHandle();
try {
// add standard resource roots, this should eventually replace ClassPathEntry
final List<ResourceRoot> resourceRoots = createResourceRoots(deploymentRoot, deploymentUnit);
for (ResourceRoot root : resourceRoots) {
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, root);
}
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
// Add the war metadata
final WarMetaData warMetaData = new WarMetaData();
deploymentUnit.putAttachment(WarMetaData.ATTACHMENT_KEY, warMetaData);
String deploymentName;
if (deploymentUnit.getParent() == null) {
deploymentName = deploymentUnit.getName();
} else {
deploymentName = deploymentUnit.getParent().getName() + "." + deploymentUnit.getName();
}
PathManager pathManager = deploymentUnit.getAttachment(Attachments.PATH_MANAGER);
File tempDir = new File(pathManager.getPathEntry(TEMP_DIR).resolvePath(), deploymentName);
tempDir.mkdirs();
warMetaData.setTempDir(tempDir);
moduleSpecification.addPermissionFactory(new ImmediatePermissionFactory(new FilePermission(tempDir.getAbsolutePath() + File.separatorChar + "-", "read,write,delete")));
// Add the shared TLDs metadata
final TldsMetaData tldsMetaData = new TldsMetaData();
tldsMetaData.setSharedTlds(sharedTldsMetaData);
deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
processExternalMounts(deploymentUnit, deploymentRoot);
}
Aggregations