import org.argeo.node.NodeInstance;
import org.argeo.node.NodeState;
import org.argeo.util.LangUtils;
+import org.ietf.jgss.GSSCredential;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
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 LogReaderService logReaderService;
- // private ConfigurationAdmin configurationAdmin;
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 {
- initSecurity();// must be first
+ 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);
}
}
private void initSecurity() {
if (System.getProperty(KernelConstants.JAAS_CONFIG_PROP) == null) {
- URL url = getClass().getClassLoader().getResource(KernelConstants.JAAS_CONFIG);
- // URL url =
- // getClass().getClassLoader().getResource(KernelConstants.JAAS_CONFIG_IPA);
- System.setProperty(KernelConstants.JAAS_CONFIG_PROP, url.toExternalForm());
+ String jaasConfig = KernelConstants.JAAS_CONFIG;
+ URL url = getClass().getClassLoader().getResource(jaasConfig);
+ // System.setProperty(KernelConstants.JAAS_CONFIG_PROP,
+ // url.toExternalForm());
+ KernelUtils.setJaasConfiguration(url);
}
+ // 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() {
@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) {
return instance.nodeState;
}
+ public static GSSCredential getAcceptorCredentials() {
+ return getNodeUserAdmin().getAcceptorCredentials();
+ }
+
+ public static boolean isSingleUser() {
+ return getNodeUserAdmin().isSingleUser();
+ }
+
+ public static UserAdmin getUserAdmin() {
+ return (UserAdmin) getNodeUserAdmin();
+ }
+
+ 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() {
+ // return instance.nodeSecurity;
+ // }
+
public String[] getLocales() {
// TODO optimize?
List<Locale> locales = getNodeState().getLocales();