import java.io.IOException;
import java.net.URL;
import java.security.AllPermission;
+import java.util.Dictionary;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import org.argeo.api.NodeDeployment;
import org.argeo.api.NodeInstance;
import org.argeo.api.NodeState;
-import org.argeo.cms.CmsException;
import org.argeo.ident.IdentClient;
import org.ietf.jgss.GSSCredential;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.service.condpermadmin.BundleLocationCondition;
import org.osgi.service.condpermadmin.ConditionInfo;
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
// TODO make it configurable
private boolean hardened = false;
- private BundleContext bc;
+ private static BundleContext bundleContext;
private LogReaderService logReaderService;
private ServiceTracker<UserAdmin, NodeUserAdmin> userAdminSt;
private ExecutorService internalExecutorService;
- @Override
- public void start(BundleContext bundleContext) throws Exception {
+ static {
+ Bundle bundle = FrameworkUtil.getBundle(Activator.class);
+ if (bundle != null) {
+ bundleContext = bundle.getBundleContext();
+ }
+ }
+
+ void init() {
Runtime.getRuntime().addShutdownHook(new CmsShutdown());
instance = this;
- this.bc = bundleContext;
- this.logReaderService = getService(LogReaderService.class);
+// this.bc = bundleContext;
+ if (bundleContext != null)
+ this.logReaderService = getService(LogReaderService.class);
this.internalExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
try {
initArgeoLogger();
initNode();
- userAdminSt = new ServiceTracker<>(instance.bc, UserAdmin.class, null);
- userAdminSt.open();
if (log.isTraceEnabled())
log.trace("Kernel bundle started");
} catch (Throwable e) {
}
}
+ void destroy() {
+ try {
+ if (nodeInstance != null)
+ nodeInstance.shutdown();
+ if (nodeDeployment != null)
+ nodeDeployment.shutdown();
+ if (nodeState != null)
+ nodeState.shutdown();
+
+ if (userAdminSt != null)
+ userAdminSt.close();
+
+ internalExecutorService.shutdown();
+ instance = null;
+ bundleContext = null;
+ this.logReaderService = null;
+ // this.configurationAdmin = null;
+ } catch (Exception e) {
+ log.error("CMS activator shutdown failed", e);
+ }
+ }
+
private void initSecurity() {
if (System.getProperty(KernelConstants.JAAS_CONFIG_PROP) == null) {
String jaasConfig = KernelConstants.JAAS_CONFIG;
- URL url = getClass().getClassLoader().getResource(jaasConfig);
+ URL url = getClass().getResource(jaasConfig);
// System.setProperty(KernelConstants.JAAS_CONFIG_PROP,
// url.toExternalForm());
KernelUtils.setJaasConfiguration(url);
String osgiSecurity = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_SECURITY);
if (osgiSecurity != null && Constants.FRAMEWORK_SECURITY_OSGI.equals(osgiSecurity)) {
// TODO rather use a tracker?
- ConditionalPermissionAdmin permissionAdmin = bc
- .getService(bc.getServiceReference(ConditionalPermissionAdmin.class));
+ ConditionalPermissionAdmin permissionAdmin = bundleContext
+ .getService(bundleContext.getServiceReference(ConditionalPermissionAdmin.class));
if (!hardened) {
// All permissions to all bundles
ConditionalPermissionUpdate update = permissionAdmin.newConditionalPermissionUpdate();
private void initArgeoLogger() {
logger = new NodeLogger(logReaderService);
- bc.registerService(ArgeoLogger.class, logger, null);
+ if (bundleContext != null)
+ bundleContext.registerService(ArgeoLogger.class, logger, null);
}
private void initNode() throws IOException {
nodeState = new CmsState();
// Dictionary<String, Object> regProps = LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_STATE_PID);
// regProps.put(NodeConstants.CN, stateUuid);
- bc.registerService(NodeState.class, nodeState, null);
+ registerService(NodeState.class, nodeState, null);
// Node deployment
nodeDeployment = new CmsDeployment();
- bc.registerService(NodeDeployment.class, nodeDeployment, null);
+ registerService(NodeDeployment.class, nodeDeployment, null);
// Node instance
nodeInstance = new CmsInstance();
- bc.registerService(NodeInstance.class, nodeInstance, null);
+ registerService(NodeInstance.class, nodeInstance, null);
}
- @Override
- public void stop(BundleContext bundleContext) throws Exception {
- try {
- if (nodeInstance != null)
- nodeInstance.shutdown();
- if (nodeDeployment != null)
- nodeDeployment.shutdown();
- if (nodeState != null)
- nodeState.shutdown();
+ public static <T> void registerService(Class<T> clss, T service, Dictionary<String, ?> properties) {
+ if (bundleContext != null) {
+ bundleContext.registerService(clss, service, properties);
+ }
- if (userAdminSt != null)
- userAdminSt.close();
+ }
- internalExecutorService.shutdown();
- instance = null;
- this.bc = null;
- this.logReaderService = null;
- // this.configurationAdmin = null;
- } catch (Exception e) {
- log.error("CMS activator shutdown failed", e);
+ public static <T> T getService(Class<T> clss) {
+ if (bundleContext != null) {
+ return bundleContext.getService(bundleContext.getServiceReference(clss));
+ } else {
+ return null;
}
}
- private <T> T getService(Class<T> clazz) {
- ServiceReference<T> sr = bc.getServiceReference(clazz);
- if (sr == null)
- throw new CmsException("No service available for " + clazz);
- return bc.getService(sr);
+ /*
+ * OSGi
+ */
+
+ @Override
+ public void start(BundleContext bc) throws Exception {
+ if (!bc.getBundle().equals(bundleContext.getBundle()))
+ throw new IllegalStateException(
+ "Bundle " + bc.getBundle() + " is not consistent with " + bundleContext.getBundle());
+ init();
+ userAdminSt = new ServiceTracker<>(bundleContext, UserAdmin.class, null);
+ userAdminSt.open();
}
+ @Override
+ public void stop(BundleContext bc) throws Exception {
+ if (!bc.getBundle().equals(bundleContext.getBundle()))
+ throw new IllegalStateException(
+ "Bundle " + bc.getBundle() + " is not consistent with " + bundleContext.getBundle());
+ destroy();
+ }
+
+// private <T> T getService(Class<T> clazz) {
+// ServiceReference<T> sr = bundleContext.getServiceReference(clazz);
+// if (sr == null)
+// throw new IllegalStateException("No service available for " + clazz);
+// return bundleContext.getService(sr);
+// }
+
public static NodeState getNodeState() {
return instance.nodeState;
}
try {
res = instance.userAdminSt.waitForService(60000);
} catch (InterruptedException e) {
- throw new CmsException("Cannot retrieve Node user admin", e);
+ throw new IllegalStateException("Cannot retrieve Node user admin", e);
}
if (res == null)
- throw new CmsException("No Node user admin found");
+ throw new IllegalStateException("No Node user admin found");
return res;
// ServiceReference<UserAdmin> sr =
return res;
}
+ static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public static void main(String[] args) {
+ instance = new Activator();
+ instance.init();
+ }
+
}
public CmsShutdown() {
super("CMS Shutdown Hook");
- framework = (Framework) FrameworkUtil.getBundle(CmsShutdown.class).getBundleContext().getBundle(0);
+ framework = FrameworkUtil.getBundle(CmsShutdown.class) != null
+ ? (Framework) FrameworkUtil.getBundle(CmsShutdown.class).getBundleContext().getBundle(0)
+ : null;
}
@Override
public void run() {
- if (framework.getState() != Bundle.ACTIVE) {
+ if (framework != null && framework.getState() != Bundle.ACTIVE) {
return;
}
-
+
if (log.isDebugEnabled())
log.debug("Shutting down OSGi framework...");
try {
- // shutdown framework
- framework.stop();
- // wait for shutdown
- FrameworkEvent shutdownEvent = framework.waitForStop(timeout);
- int stoppedType = shutdownEvent.getType();
- Runtime runtime = Runtime.getRuntime();
- if (stoppedType == FrameworkEvent.STOPPED) {
- // close VM
- //System.exit(EXIT_OK);
- } else if (stoppedType == FrameworkEvent.ERROR) {
- log.error("The OSGi framework stopped with an error");
- runtime.halt(EXIT_ERROR);
- } else if (stoppedType == FrameworkEvent.WAIT_TIMEDOUT) {
- log.error("The OSGi framework hasn't stopped after " + timeout + "ms."
- + " Forcibly terminating the JVM...");
- runtime.halt(EXIT_TIMEOUT);
- } else {
- log.error("Unknown state of OSGi framework after " + timeout + "ms."
- + " Forcibly terminating the JVM... (" + shutdownEvent + ")");
- runtime.halt(EXIT_UNKNOWN);
+ if (framework != null) {
+ // shutdown framework
+ framework.stop();
+ // wait for shutdown
+ FrameworkEvent shutdownEvent = framework.waitForStop(timeout);
+ int stoppedType = shutdownEvent.getType();
+ Runtime runtime = Runtime.getRuntime();
+ if (stoppedType == FrameworkEvent.STOPPED) {
+ // close VM
+ // System.exit(EXIT_OK);
+ } else if (stoppedType == FrameworkEvent.ERROR) {
+ log.error("The OSGi framework stopped with an error");
+ runtime.halt(EXIT_ERROR);
+ } else if (stoppedType == FrameworkEvent.WAIT_TIMEDOUT) {
+ log.error("The OSGi framework hasn't stopped after " + timeout + "ms."
+ + " Forcibly terminating the JVM...");
+ runtime.halt(EXIT_TIMEOUT);
+ } else {
+ log.error("Unknown state of OSGi framework after " + timeout + "ms."
+ + " Forcibly terminating the JVM... (" + shutdownEvent + ")");
+ runtime.halt(EXIT_UNKNOWN);
+ }
}
} catch (Exception e) {
e.printStackTrace();
import org.argeo.cms.LocaleUtils;
import org.argeo.transaction.simple.SimpleTransactionManager;
import org.argeo.util.LangUtils;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.service.cm.ManagedServiceFactory;
/**
*/
public class CmsState implements NodeState {
private final static Log log = LogFactory.getLog(CmsState.class);
- private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
+// private final BundleContext bc = FrameworkUtil.getBundle(CmsState.class).getBundleContext();
// REFERENCES
private Long availableSince;
// JCR
RepositoryServiceFactory repositoryServiceFactory = new RepositoryServiceFactory();
stopHooks.add(() -> repositoryServiceFactory.shutdown());
- bc.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
+ Activator.registerService(ManagedServiceFactory.class, repositoryServiceFactory,
LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_REPOS_FACTORY_PID));
NodeRepositoryFactory repositoryFactory = new NodeRepositoryFactory();
- bc.registerService(RepositoryFactory.class, repositoryFactory, null);
+ Activator.registerService(RepositoryFactory.class, repositoryFactory, null);
// Security
NodeUserAdmin userAdmin = new NodeUserAdmin(NodeConstants.ROLES_BASEDN, NodeConstants.TOKENS_BASEDN);
stopHooks.add(() -> userAdmin.destroy());
- bc.registerService(ManagedServiceFactory.class, userAdmin,
+ Activator.registerService(ManagedServiceFactory.class, userAdmin,
LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_USER_ADMIN_PID));
// File System
// for (FileSystemProvider fsp : FileSystemProvider.installedProviders()) {
// log.debug("Installed FileSystemProvider " + fsp);
// }
- bc.registerService(FileSystemProvider.class, cmsFsProvider,
+ Activator.registerService(FileSystemProvider.class, cmsFsProvider,
LangUtils.dict(Constants.SERVICE_PID, NodeConstants.NODE_FS_PROVIDER_PID));
}
private void initSimpleTransactionManager() {
SimpleTransactionManager transactionManager = new SimpleTransactionManager();
- bc.registerService(TransactionManager.class, transactionManager, null);
- bc.registerService(UserTransaction.class, transactionManager, null);
+ Activator.registerService(TransactionManager.class, transactionManager, null);
+ Activator.registerService(UserTransaction.class, transactionManager, null);
// TODO TransactionSynchronizationRegistry
}
import org.argeo.cms.CmsException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.util.tracker.ServiceTracker;
/** Package utilities */
.getInstance("JavaLoginConfig", uriParameter);
javax.security.auth.login.Configuration.setConfiguration(jaasConfiguration);
} catch (Exception e) {
- throw new CmsException("Cannot set configuration " + jaasConfigurationUrl, e);
+ throw new IllegalArgumentException("Cannot set configuration " + jaasConfigurationUrl, e);
}
}
try {
props.load(cl.getResourceAsStream(resource));
} catch (IOException e) {
- throw new CmsException("Cannot load " + resource + " from classpath", e);
+ throw new IllegalArgumentException("Cannot load " + resource + " from classpath", e);
}
return asDictionary(props);
}
try {
return new File(executionDir, relativePath).getCanonicalFile();
} catch (IOException e) {
- throw new CmsException("Cannot get canonical file", e);
+ throw new IllegalArgumentException("Cannot get canonical file", e);
}
}
static URI getOsgiInstanceUri(String relativePath) {
String osgiInstanceBaseUri = getFrameworkProp(OSGI_INSTANCE_AREA);
- return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : ""));
+ if (osgiInstanceBaseUri != null)
+ return safeUri(osgiInstanceBaseUri + (relativePath != null ? relativePath : ""));
+ else
+ return Paths.get(System.getProperty("user.dir")).toUri();
}
static File getOsgiConfigurationFile(String relativePath) {
return new File(new URI(getBundleContext().getProperty(OSGI_CONFIGURATION_AREA) + relativePath))
.getCanonicalFile();
} catch (Exception e) {
- throw new CmsException("Cannot get configuration file for " + relativePath, e);
+ throw new IllegalArgumentException("Cannot get configuration file for " + relativePath, e);
}
}
static String getFrameworkProp(String key, String def) {
- String value = getBundleContext().getProperty(key);
+ BundleContext bundleContext = Activator.getBundleContext();
+ String value;
+ if (bundleContext != null)
+ value = bundleContext.getProperty(key);
+ else
+ value = System.getProperty(key);
if (value == null)
return def;
return value;
loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_DATA_ADMIN);
loginContext.login();
} catch (LoginException e1) {
- throw new CmsException("Could not login as data admin", e1);
+ throw new IllegalStateException("Could not login as data admin", e1);
} finally {
Thread.currentThread().setContextClassLoader(currentCl);
}
try {
return repository.login(workspaceName);
} catch (RepositoryException e) {
- throw new CmsException("Cannot open admin session", e);
+ throw new IllegalStateException("Cannot open admin session", e);
}
}
* class, never null.
* @throws CmsException if the related bundle is not active
*/
- static BundleContext getBundleContext(Class<?> clzz) {
- Bundle bundle = FrameworkUtil.getBundle(clzz);
- BundleContext bc = bundle.getBundleContext();
- if (bc == null)
- throw new CmsException("Bundle " + bundle.getSymbolicName() + " is not active");
- return bc;
- }
+// static BundleContext getBundleContext(Class<?> clzz) {
+//// Bundle bundle = FrameworkUtil.getBundle(clzz);
+// BundleContext bc = Activator.getBundleContext();
+// if (bc == null)
+// throw new CmsException("Bundle " + bundle.getSymbolicName() + " is not active");
+// return bc;
+// }
static BundleContext getBundleContext() {
- return getBundleContext(KernelUtils.class);
+ return Activator.getBundleContext();
}
static boolean asBoolean(String value) {
case "false":
return false;
default:
- throw new CmsException("Unsupported value for attribute " + DataModelNamespace.ABSTRACT + ": " + value);
+ throw new IllegalArgumentException(
+ "Unsupported value for attribute " + DataModelNamespace.ABSTRACT + ": " + value);
}
}
private static URI safeUri(String uri) {
if (uri == null)
- throw new CmsException("URI cannot be null");
+ throw new IllegalArgumentException("URI cannot be null");
try {
return new URI(uri);
} catch (URISyntaxException e) {
- throw new CmsException("Dadly formatted URI " + uri, e);
+ throw new IllegalArgumentException("Badly formatted URI " + uri, e);
}
}
};
public NodeLogger(LogReaderService lrs) {
- Enumeration<LogEntry> logEntries = lrs.getLog();
- while (logEntries.hasMoreElements())
- logged(logEntries.nextElement());
- lrs.addLogListener(this);
-
- // configure log4j watcher
- String log4jConfiguration = KernelUtils.getFrameworkProp("log4j.configuration");
- if (log4jConfiguration != null && log4jConfiguration.startsWith("file:")) {
- if (log4jConfiguration.contains("..")) {
- if (log4jConfiguration.startsWith("file://"))
- log4jConfiguration = log4jConfiguration.substring("file://".length());
- else if (log4jConfiguration.startsWith("file:"))
- log4jConfiguration = log4jConfiguration.substring("file:".length());
- }
- try {
- Path log4jconfigPath;
- if (log4jConfiguration.startsWith("file:"))
- log4jconfigPath = Paths.get(new URI(log4jConfiguration));
- else
- log4jconfigPath = Paths.get(log4jConfiguration);
- Thread log4jConfWatcher = new Log4jConfWatcherThread(log4jconfigPath);
- log4jConfWatcher.start();
- } catch (Exception e) {
- stdErr("Badly formatted log4j configuration URI " + log4jConfiguration + ": " + e.getMessage());
+ if (lrs != null) {
+ Enumeration<LogEntry> logEntries = lrs.getLog();
+ while (logEntries.hasMoreElements())
+ logged(logEntries.nextElement());
+ lrs.addLogListener(this);
+
+ // configure log4j watcher
+ String log4jConfiguration = KernelUtils.getFrameworkProp("log4j.configuration");
+ if (log4jConfiguration != null && log4jConfiguration.startsWith("file:")) {
+ if (log4jConfiguration.contains("..")) {
+ if (log4jConfiguration.startsWith("file://"))
+ log4jConfiguration = log4jConfiguration.substring("file://".length());
+ else if (log4jConfiguration.startsWith("file:"))
+ log4jConfiguration = log4jConfiguration.substring("file:".length());
+ }
+ try {
+ Path log4jconfigPath;
+ if (log4jConfiguration.startsWith("file:"))
+ log4jconfigPath = Paths.get(new URI(log4jConfiguration));
+ else
+ log4jconfigPath = Paths.get(log4jConfiguration);
+ Thread log4jConfWatcher = new Log4jConfWatcherThread(log4jconfigPath);
+ log4jConfWatcher.start();
+ } catch (Exception e) {
+ stdErr("Badly formatted log4j configuration URI " + log4jConfiguration + ": " + e.getMessage());
+ }
}
}
}
*/
class NodeRepositoryFactory implements RepositoryFactory {
private final Log log = LogFactory.getLog(getClass());
- private final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
+// private final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
// private Resource fileRepositoryConfiguration = new ClassPathResource(
// "/org/argeo/cms/internal/kernel/repository-localfs.xml");
protected Repository getRepositoryByAlias(String alias) {
- try {
- Collection<ServiceReference<Repository>> srs = bundleContext.getServiceReferences(Repository.class,
- "(" + NodeConstants.CN + "=" + alias + ")");
- if (srs.size() == 0)
- throw new IllegalArgumentException("No repository with alias " + alias + " found in OSGi registry");
- else if (srs.size() > 1)
- throw new IllegalArgumentException(
- srs.size() + " repositories with alias " + alias + " found in OSGi registry");
- return bundleContext.getService(srs.iterator().next());
- } catch (InvalidSyntaxException e) {
- throw new IllegalArgumentException("Cannot find repository with alias " + alias, e);
+ BundleContext bundleContext = Activator.getBundleContext();
+ if (bundleContext != null) {
+ try {
+ Collection<ServiceReference<Repository>> srs = bundleContext.getServiceReferences(Repository.class,
+ "(" + NodeConstants.CN + "=" + alias + ")");
+ if (srs.size() == 0)
+ throw new IllegalArgumentException("No repository with alias " + alias + " found in OSGi registry");
+ else if (srs.size() > 1)
+ throw new IllegalArgumentException(
+ srs.size() + " repositories with alias " + alias + " found in OSGi registry");
+ return bundleContext.getService(srs.iterator().next());
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalArgumentException("Cannot find repository with alias " + alias, e);
+ }
+ } else {
+ // TODO ability to filter static services
+ return null;
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.api.NodeConstants;
-import org.argeo.cms.CmsException;
import org.argeo.cms.internal.http.client.HttpCredentialProvider;
import org.argeo.cms.internal.http.client.SpnegoAuthScheme;
import org.argeo.naming.DnsBrowser;
import org.ietf.jgss.Oid;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
import org.osgi.service.useradmin.Authorization;
*/
class NodeUserAdmin extends AggregatingUserAdmin implements ManagedServiceFactory, KernelConstants {
private final static Log log = LogFactory.getLog(NodeUserAdmin.class);
- private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
+// private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
// OSGi
private Map<String, LdapName> pidToBaseDn = new HashMap<>();
- private Map<String, ServiceRegistration<UserDirectory>> pidToServiceRegs = new HashMap<>();
+// private Map<String, ServiceRegistration<UserDirectory>> pidToServiceRegs = new HashMap<>();
// private ServiceRegistration<UserAdmin> userAdminReg;
// JTA
public NodeUserAdmin(String systemRolesBaseDn, String tokensBaseDn) {
super(systemRolesBaseDn, tokensBaseDn);
- tmTracker = new ServiceTracker<>(bc, TransactionManager.class, null);
- tmTracker.open();
+ BundleContext bc = Activator.getBundleContext();
+ if (bc != null) {
+ tmTracker = new ServiceTracker<>(bc, TransactionManager.class, null);
+ tmTracker.open();
+ } else {
+ tmTracker = null;
+ }
}
@Override
} else
u = new URI(uri);
} catch (URISyntaxException e) {
- throw new CmsException("Badly formatted URI " + uri, e);
+ throw new IllegalArgumentException("Badly formatted URI " + uri, e);
}
// Create
userDirectory = new OsUserDirectory(u, properties);
singleUser = true;
} else {
- throw new CmsException("Unsupported scheme " + u.getScheme());
+ throw new IllegalArgumentException("Unsupported scheme " + u.getScheme());
}
Object realm = userDirectory.getProperties().get(UserAdminConf.realm.name());
addUserDirectory(userDirectory);
if (isSystemRolesBaseDn(baseDn))
regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
regProps.put(UserAdminConf.baseDn.name(), baseDn);
- ServiceRegistration<UserDirectory> reg = bc.registerService(UserDirectory.class, userDirectory, regProps);
+ // ServiceRegistration<UserDirectory> reg =
+ // bc.registerService(UserDirectory.class, userDirectory, regProps);
+ Activator.registerService(UserDirectory.class, userDirectory, regProps);
pidToBaseDn.put(pid, baseDn);
- pidToServiceRegs.put(pid, reg);
+ // pidToServiceRegs.put(pid, reg);
if (log.isDebugEnabled())
log.debug("User directory " + userDirectory.getBaseDn() + " [" + u.getScheme() + "] enabled."
Dictionary<String, Object> userAdminregProps = new Hashtable<>();
userAdminregProps.put(NodeConstants.CN, NodeConstants.DEFAULT);
userAdminregProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
- bc.registerService(UserAdmin.class, this, userAdminregProps);
+ Activator.registerService(UserAdmin.class, this, userAdminregProps);
}
// if (isSystemRolesBaseDn(baseDn))
@Override
public void deleted(String pid) {
- assert pidToServiceRegs.get(pid) != null;
+ // assert pidToServiceRegs.get(pid) != null;
assert pidToBaseDn.get(pid) != null;
- pidToServiceRegs.remove(pid).unregister();
+ // pidToServiceRegs.remove(pid).unregister();
LdapName baseDn = pidToBaseDn.remove(pid);
removeUserDirectory(baseDn);
}
protected void postAdd(AbstractUserDirectory userDirectory) {
// JTA
- TransactionManager tm = tmTracker.getService();
+ TransactionManager tm = tmTracker != null ? tmTracker.getService() : null;
if (tm == null)
- throw new CmsException("A JTA transaction manager must be available.");
+ throw new IllegalStateException("A JTA transaction manager must be available.");
userDirectory.setTransactionManager(tm);
// if (tmTracker.getService() instanceof BitronixTransactionManager)
// EhCacheXAResourceProducer.registerXAResource(cacheName, userDirectory.getXaResource());
nodeLc.login();
acceptorCredentials = logInAsAcceptor(nodeLc.getSubject(), servicePrincipal);
} catch (LoginException e) {
- throw new CmsException("Cannot log in kernel", e);
+ throw new IllegalStateException("Cannot log in kernel", e);
}
}
}
log.debug("GSS acceptor configured for " + krb5Principal);
return serverCredentials;
} catch (Exception gsse) {
- throw new CmsException("Cannot create acceptor credentials for " + krb5Principal, gsse);
+ throw new IllegalStateException("Cannot create acceptor credentials for " + krb5Principal, gsse);
}
}
package org.argeo.cms.internal.kernel;
-import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX;
-
-import java.io.IOException;
import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.Dictionary;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Map;
import javax.jcr.Repository;
import javax.jcr.RepositoryFactory;
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jackrabbit.core.RepositoryContext;
-import org.apache.jackrabbit.server.remoting.davex.JcrRemotingServlet;
import org.argeo.api.NodeConstants;
-import org.argeo.cms.CmsException;
-import org.argeo.cms.internal.http.CmsRemotingServlet;
-import org.argeo.cms.internal.http.HttpUtils;
import org.argeo.cms.internal.jcr.RepoConf;
import org.argeo.cms.internal.jcr.RepositoryBuilder;
import org.argeo.util.LangUtils;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.http.NamespaceException;
-import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
/** A {@link ManagedServiceFactory} creating or referencing JCR repositories. */
class RepositoryServiceFactory implements ManagedServiceFactory {
private final static Log log = LogFactory.getLog(RepositoryServiceFactory.class);
- private final BundleContext bc = FrameworkUtil.getBundle(RepositoryServiceFactory.class).getBundleContext();
+// private final BundleContext bc = FrameworkUtil.getBundle(RepositoryServiceFactory.class).getBundleContext();
private Map<String, RepositoryContext> repositories = new HashMap<String, RepositoryContext>();
private Map<String, Object> pidToCn = new HashMap<String, Object>();
@Override
public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
if (repositories.containsKey(pid))
- throw new CmsException("Already a repository registered for " + pid);
+ throw new IllegalArgumentException("Already a repository registered for " + pid);
if (properties == null)
return;
RepositoryBuilder repositoryBuilder = new RepositoryBuilder();
RepositoryContext repositoryContext = repositoryBuilder.createRepositoryContext(properties);
repositories.put(pid, repositoryContext);
- Dictionary<String, Object> props = LangUtils.dico(Constants.SERVICE_PID, pid);
+ Dictionary<String, Object> props = LangUtils.dict(Constants.SERVICE_PID, pid);
// props.put(ArgeoJcrConstants.JCR_REPOSITORY_URI,
// properties.get(RepoConf.labeledUri.name()));
Object cn = properties.get(NodeConstants.CN);
// props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
pidToCn.put(pid, cn);
}
- bc.registerService(RepositoryContext.class, repositoryContext, props);
+ Activator.registerService(RepositoryContext.class, repositoryContext, props);
} else {
try {
Object cn = properties.get(NodeConstants.CN);
if (defaultWorkspace == null)
defaultWorkspace = RepoConf.defaultWorkspace.getDefault();
URI uri = new URI(labeledUri.toString());
- RepositoryFactory repositoryFactory = bc
- .getService(bc.getServiceReference(RepositoryFactory.class));
+// RepositoryFactory repositoryFactory = bc
+// .getService(bc.getServiceReference(RepositoryFactory.class));
+ RepositoryFactory repositoryFactory = Activator.getService(RepositoryFactory.class);
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(RepoConf.labeledUri.name(), uri.toString());
parameters.put(RepoConf.defaultWorkspace.name(), defaultWorkspace.toString());
Repository repository = repositoryFactory.getRepository(parameters);
// Repository repository = NodeUtils.getRepositoryByUri(repositoryFactory,
// uri.toString());
- Dictionary<String, Object> props = LangUtils.dico(Constants.SERVICE_PID, pid);
+ Dictionary<String, Object> props = LangUtils.dict(Constants.SERVICE_PID, pid);
props.put(RepoConf.labeledUri.name(),
new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), null, null)
.toString());
// props.put(NodeConstants.JCR_REPOSITORY_ALIAS, cn);
pidToCn.put(pid, cn);
}
- bc.registerService(Repository.class, repository, props);
+ Activator.registerService(Repository.class, repository, props);
// home
if (cn.equals(NodeConstants.NODE_REPOSITORY)) {
- Dictionary<String, Object> homeProps = LangUtils.dico(NodeConstants.CN,
+ Dictionary<String, Object> homeProps = LangUtils.dict(NodeConstants.CN,
NodeConstants.EGO_REPOSITORY);
EgoRepository homeRepository = new EgoRepository(repository, true);
- bc.registerService(Repository.class, homeRepository, homeProps);
+ Activator.registerService(Repository.class, homeRepository, homeProps);
}
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
} catch (Exception e) {
- throw new CmsException("Cannot create Jackrabbit repository " + pid, e);
+ throw new IllegalStateException("Cannot create Jackrabbit repository " + pid, e);
}
}