Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.ops4j.pax.web.service.internal;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.servlet.annotation.ServletSecurity;
import org.apache.tomcat.util.descriptor.web.LoginConfig;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.apache.tomcat.util.descriptor.web.WebXml;
import org.apache.tomcat.util.descriptor.web.WebXmlParser;
import org.ops4j.pax.web.service.PaxWebConstants;
import org.ops4j.pax.web.service.WebContainer;
import org.ops4j.pax.web.service.internal.views.ProcessingWebContainerView;
import org.ops4j.pax.web.service.spi.model.OsgiContextModel;
import org.ops4j.pax.web.service.spi.model.elements.LoginConfigModel;
import org.ops4j.pax.web.service.spi.model.elements.SecurityConstraintModel;
import org.ops4j.pax.web.service.spi.task.Batch;
import org.ops4j.pax.web.service.spi.task.ContextParamsChange;
import org.ops4j.pax.web.service.spi.task.ContextStartChange;
import org.ops4j.pax.web.service.spi.task.ContextStopChange;
import org.ops4j.pax.web.service.spi.task.OpCode;
import org.ops4j.pax.web.service.spi.task.SecurityConfigChange;
import org.ops4j.pax.web.service.spi.util.NamedThreadFactory;
import org.ops4j.pax.web.service.spi.util.Utils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
import org.osgi.service.cm.ManagedServiceFactory;
import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.BundleTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
Tracks CM factory configurations which, in declarative way, are used to provide additional configuration
* for given bundle's instance of {@link org.osgi.service.http.HttpService}/{@link WebContainer}.
*/
public class HttpContextProcessing implements ManagedServiceFactory {
public static final Logger LOG = LoggerFactory.getLogger(HttpContextProcessing.class);
public static final String PID = PaxWebConstants.PID + ".context";
private static final String KEY_CONTEXT_ID = "context.id";
private static final String KEY_BUNDLE_SN = "bundle.symbolicName";
private static final String KEY_WEB_FRAGMENT = "context.webFragment";
private static final String KEY_WHITEBOARD = "whiteboard";
private static final String PREFIX_CONTEXT_PARAM = "context.param.";
private static final String PREFIX_LOGIN_CONFIG = "login.config.";
private static final String PREFIX_SECURITY = "security.";
private static final String PREFIX_SECURITY_ROLE = "security.roles";
private final ExecutorService configExecutor = new ThreadPoolExecutor(0, 1,
20, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("paxweb-context"));
private final BundleContext serviceContext;
private final ConcurrentMap httpContextTrackers = new ConcurrentHashMap<>();
public HttpContextProcessing(BundleContext serviceContext) {
this.serviceContext = serviceContext;
}
@Override
public String getName() {
return PID;
}
@Override
public void updated(String pid, Dictionary properties) {
LOG.info("Updated configuration for pid={}", pid);
// we're in the context of ConfigurationAdmin UpdateThread, but we should not hold it too long
configExecutor.submit(new ConfigurationChangeTask(pid, properties));
}
@Override
public void deleted(String pid) {
LOG.info("Deleted configuration for pid={}", pid);
configExecutor.submit(new ConfigurationChangeTask(pid, null));
}
public void destroy() {
configExecutor.shutdown();
}
/**
* Synchronous task (single instance running at given time) that's handling an update to context processing
* configuration.
*/
private class ConfigurationChangeTask implements Runnable {
private final String pid;
private final Dictionary properties;
ConfigurationChangeTask(String pid, Dictionary properties) {
this.pid = pid;
this.properties = properties;
}
@Override
public void run() {
try {
LOG.debug("Processing {} PID {}", pid, properties == null ? "removal" : "change");
HttpContextTracker p = httpContextTrackers.computeIfAbsent(pid, HttpContextTracker::new);
p.reconfigure(properties);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
}
/**
*
A class that operates on {@link org.osgi.service.http.HttpService}/{@link WebContainer} scoped
* for given, configured {@link Bundle}.
*
We don't have to operate on wirings/revisions - that's not required for
* {@link org.osgi.framework.Constants#SCOPE_BUNDLE}.
*/
private class HttpContextTracker implements BundleTrackerCustomizer