import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
import javax.jcr.Repository;
import javax.jcr.RepositoryFactory;
import org.argeo.cms.internal.transaction.SimpleTransactionManager;
import org.argeo.jackrabbit.OsgiJackrabbitRepositoryFactory;
import org.argeo.jcr.ArgeoJcrConstants;
-import org.argeo.security.core.InternalAuthentication;
import org.eclipse.equinox.http.servlet.ExtendedHttpService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
-import org.springframework.security.core.context.SecurityContextHolder;
/**
* Argeo CMS Kernel. Responsible for :
Thread.currentThread().setContextClassLoader(
Kernel.class.getClassLoader());
long begin = System.currentTimeMillis();
- InternalAuthentication initAuth = new InternalAuthentication(
- KernelConstants.DEFAULT_SECURITY_KEY);
- SecurityContextHolder.getContext().setAuthentication(initAuth);
try {
// Transaction
transactionManager = new SimpleTransactionManager();
- bundleContext.registerService(TransactionManager.class,
- transactionManager, null);
- bundleContext.registerService(UserTransaction.class,
- transactionManager, null);
- bundleContext.registerService(
- TransactionSynchronizationRegistry.class,
- transactionManager.getTransactionSynchronizationRegistry(),
- null);
// Jackrabbit node
node = new JackrabbitNode(bundleContext);
transactionManager);
// Equinox dependency
- ExtendedHttpService httpService = waitForHttpService();
- nodeHttp = new NodeHttp(httpService, node, nodeSecurity);
+ // ExtendedHttpService httpService = waitForHttpService();
+ // nodeHttp = new NodeHttp(httpService, node);
+ ServiceReference<ExtendedHttpService> sr = bundleContext
+ .getServiceReference(ExtendedHttpService.class);
+ if (sr != null)
+ addHttpService(sr);
// Kernel thread
kernelThread = new KernelThread(this);
kernelThread.start();
// Publish services to OSGi
+ bundleContext.registerService(TransactionManager.class,
+ transactionManager, null);
+ bundleContext.registerService(UserTransaction.class,
+ transactionManager, null);
+ bundleContext.registerService(
+ TransactionSynchronizationRegistry.class,
+ transactionManager.getTransactionSynchronizationRegistry(),
+ null);
nodeSecurity.publish();
node.publish(repositoryFactory);
bundleContext.registerService(RepositoryFactory.class,
@Override
public void serviceChanged(ServiceEvent event) {
ServiceReference<?> sr = event.getServiceReference();
- Object jcrRepoAlias = sr
- .getProperty(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS);
- if (jcrRepoAlias != null) {// JCR repository
- String alias = jcrRepoAlias.toString();
- Repository repository = (Repository) bundleContext.getService(sr);
- Map<String, Object> props = new HashMap<String, Object>();
- for (String key : sr.getPropertyKeys())
- props.put(key, sr.getProperty(key));
- if (ServiceEvent.REGISTERED == event.getType()) {
- try {
- repositoryFactory.register(repository, props);
- nodeHttp.registerRepositoryServlets(alias, repository);
- } catch (Exception e) {
- throw new CmsException("Could not publish JCR repository "
- + alias, e);
+ Object service = bundleContext.getService(sr);
+ if (service instanceof Repository) {
+ Object jcrRepoAlias = sr
+ .getProperty(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS);
+ if (jcrRepoAlias != null) {// JCR repository
+ String alias = jcrRepoAlias.toString();
+ Repository repository = (Repository) bundleContext
+ .getService(sr);
+ Map<String, Object> props = new HashMap<String, Object>();
+ for (String key : sr.getPropertyKeys())
+ props.put(key, sr.getProperty(key));
+ if (ServiceEvent.REGISTERED == event.getType()) {
+ try {
+ repositoryFactory.register(repository, props);
+ nodeHttp.registerRepositoryServlets(alias, repository);
+ } catch (Exception e) {
+ throw new CmsException(
+ "Could not publish JCR repository " + alias, e);
+ }
+ } else if (ServiceEvent.UNREGISTERING == event.getType()) {
+ repositoryFactory.unregister(repository, props);
+ nodeHttp.unregisterRepositoryServlets(alias);
}
+ }
+ } else if (service instanceof ExtendedHttpService) {
+ if (ServiceEvent.REGISTERED == event.getType()) {
+ addHttpService(sr);
} else if (ServiceEvent.UNREGISTERING == event.getType()) {
- repositoryFactory.unregister(repository, props);
- nodeHttp.unregisterRepositoryServlets(alias);
+ nodeHttp.destroy();
+ nodeHttp = null;
}
}
+ }
+ private void addHttpService(ServiceReference<?> sr) {
+// for (String key : sr.getPropertyKeys())
+// log.debug(key + "=" + sr.getProperty(key));
+ ExtendedHttpService httpService = (ExtendedHttpService) bundleContext
+ .getService(sr);
+ // TODO find constants
+ Object httpPort = sr.getProperty("http.port");
+ Object httpsPort = sr.getProperty("https.port");
+ nodeHttp = new NodeHttp(httpService, node);
+ if (log.isDebugEnabled())
+ log.debug("HTTP " + httpPort
+ + (httpsPort != null ? " - HTTPS " + httpsPort : ""));
}
private ExtendedHttpService waitForHttpService() {