package org.argeo.cms.internal.kernel;
-import java.awt.image.Kernel;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogReaderService;
import org.osgi.service.useradmin.UserAdmin;
+import org.osgi.util.tracker.ServiceTracker;
/**
- * Activates the {@link Kernel} from the provided {@link BundleContext}. Gives
- * access to kernel information for the rest of the bundle (and only it)
+ * Activates the kernel. Gives access to kernel information for the rest of the
+ * bundle (and only it)
*/
public class Activator implements BundleActivator {
private final static Log log = LogFactory.getLog(Activator.class);
private static Activator instance;
private BundleContext bc;
- // private CmsSecurity nodeSecurity;
+
private LogReaderService logReaderService;
- // private ConfigurationAdmin configurationAdmin;
-// private NodeLogger logger;
+ private NodeLogger logger;
private CmsState nodeState;
private CmsDeployment nodeDeployment;
private CmsInstance nodeInstance;
+ private ServiceTracker<UserAdmin, NodeUserAdmin> userAdminSt;
+
@Override
public void start(BundleContext bundleContext) throws Exception {
+ Runtime.getRuntime().addShutdownHook(new CmsShutdown());
instance = this;
this.bc = bundleContext;
this.logReaderService = getService(LogReaderService.class);
- // this.configurationAdmin = getService(ConfigurationAdmin.class);
try {
- // nodeSecurity = new CmsSecurity();
initSecurity();
initArgeoLogger();
initNode();
- } catch (Exception e) {
+
+ userAdminSt = new ServiceTracker<>(instance.bc, UserAdmin.class, null);
+ userAdminSt.open();
+ log.debug("Kernel bundle started");
+ } catch (Throwable e) {
log.error("## FATAL: CMS activator failed", e);
- // throw new CmsException("Cannot initialize node", e);
}
}
}
// explicitly load JAAS configuration
Configuration.getConfiguration();
+
+ // ConditionalPermissionAdmin permissionAdmin = bc
+ // .getService(bc.getServiceReference(ConditionalPermissionAdmin.class));
+ // ConditionalPermissionUpdate update =
+ // permissionAdmin.newConditionalPermissionUpdate();
+ // // Self
+ // update.getConditionalPermissionInfos()
+ // .add(permissionAdmin.newConditionalPermissionInfo(null,
+ // new ConditionInfo[] {
+ // new ConditionInfo(BundleLocationCondition.class.getName(), new
+ // String[] { "*" }) },
+ // new PermissionInfo[] { new
+ // PermissionInfo(AllPermission.class.getName(), null, null) },
+ // ConditionalPermissionInfo.ALLOW));
+ //
}
private void initArgeoLogger() {
-// logger = new NodeLogger(logReaderService);
-// bc.registerService(ArgeoLogger.class, logger, null);
+ logger = new NodeLogger(logReaderService);
+ bc.registerService(ArgeoLogger.class, logger, null);
}
private void initNode() throws IOException {
@Override
public void stop(BundleContext bundleContext) throws Exception {
- nodeInstance.shutdown();
- nodeDeployment.shutdown();
- nodeState.shutdown();
-
- instance = null;
- this.bc = null;
- this.logReaderService = null;
- // this.configurationAdmin = null;
+ try {
+ if (nodeInstance != null)
+ nodeInstance.shutdown();
+ if (nodeDeployment != null)
+ nodeDeployment.shutdown();
+ if (nodeState != null)
+ nodeState.shutdown();
+
+ if (userAdminSt != null)
+ userAdminSt.close();
+
+ instance = null;
+ this.bc = null;
+ this.logReaderService = null;
+ // this.configurationAdmin = null;
+ } catch (Exception e) {
+ log.error("CMS activator shutdown failed", e);
+ }
}
private <T> T getService(Class<T> clazz) {
}
public static GSSCredential getAcceptorCredentials() {
- ServiceReference<UserAdmin> sr = instance.bc.getServiceReference(UserAdmin.class);
- NodeUserAdmin userAdmin = (NodeUserAdmin) instance.bc.getService(sr);
- return userAdmin.getAcceptorCredentials();
+ return getNodeUserAdmin().getAcceptorCredentials();
+ }
+
+ public static boolean isSingleUser() {
+ return getNodeUserAdmin().isSingleUser();
+ }
+
+ public static UserAdmin getUserAdmin() {
+ return (UserAdmin) getNodeUserAdmin();
+ }
+
+ public static String getHttpProxySslHeader() {
+ return KernelUtils.getFrameworkProp(NodeConstants.HTTP_PROXY_SSL_DN);
+ }
+
+ private static NodeUserAdmin getNodeUserAdmin() {
+ NodeUserAdmin res;
+ try {
+ res = instance.userAdminSt.waitForService(60000);
+ } catch (InterruptedException e) {
+ throw new CmsException("Cannot retrieve Node user admin", e);
+ }
+ if (res == null)
+ throw new CmsException("No Node user admin found");
+
+ return res;
+ // ServiceReference<UserAdmin> sr =
+ // instance.bc.getServiceReference(UserAdmin.class);
+ // NodeUserAdmin userAdmin = (NodeUserAdmin) instance.bc.getService(sr);
+ // return userAdmin;
+
}
// static CmsSecurity getCmsSecurity() {