1 package org
.argeo
.cms
.internal
.osgi
;
3 import java
.security
.AllPermission
;
4 import java
.util
.Dictionary
;
6 import org
.argeo
.api
.cms
.CmsLog
;
7 import org
.osgi
.framework
.BundleActivator
;
8 import org
.osgi
.framework
.BundleContext
;
9 import org
.osgi
.framework
.Constants
;
10 import org
.osgi
.service
.condpermadmin
.BundleLocationCondition
;
11 import org
.osgi
.service
.condpermadmin
.ConditionInfo
;
12 import org
.osgi
.service
.condpermadmin
.ConditionalPermissionAdmin
;
13 import org
.osgi
.service
.condpermadmin
.ConditionalPermissionInfo
;
14 import org
.osgi
.service
.condpermadmin
.ConditionalPermissionUpdate
;
15 import org
.osgi
.service
.permissionadmin
.PermissionInfo
;
18 * Activates the kernel. Gives access to kernel information for the rest of the
19 * bundle (and only it)
21 public class CmsActivator
implements BundleActivator
{
22 private final static CmsLog log
= CmsLog
.getLog(CmsActivator
.class);
24 // TODO make it configurable
25 private boolean hardened
= false;
27 private static BundleContext bundleContext
;
29 // private LogReaderService logReaderService;
31 // private CmsOsgiLogger logger;
34 // Runtime.getRuntime().addShutdownHook(new CmsShutdown());
36 // this.bc = bundleContext;
37 // if (bundleContext != null)
38 // this.logReaderService = getService(LogReaderService.class);
40 // this.internalExecutorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
44 //// initArgeoLogger();
47 // if (log.isTraceEnabled())
48 // log.trace("Kernel bundle started");
49 // } catch (Throwable e) {
50 // log.error("## FATAL: CMS activator failed", e);
57 // this.logReaderService = null;
58 } catch (Exception e
) {
59 log
.error("CMS activator shutdown failed", e
);
62 new GogoShellKiller().start();
65 private void initSecurity() {
66 // code-level permissions
67 String osgiSecurity
= bundleContext
.getProperty(Constants
.FRAMEWORK_SECURITY
);
68 if (osgiSecurity
!= null && Constants
.FRAMEWORK_SECURITY_OSGI
.equals(osgiSecurity
)) {
69 // TODO rather use a tracker?
70 ConditionalPermissionAdmin permissionAdmin
= bundleContext
71 .getService(bundleContext
.getServiceReference(ConditionalPermissionAdmin
.class));
73 // All permissions to all bundles
74 ConditionalPermissionUpdate update
= permissionAdmin
.newConditionalPermissionUpdate();
75 update
.getConditionalPermissionInfos().add(permissionAdmin
.newConditionalPermissionInfo(null,
77 new ConditionInfo(BundleLocationCondition
.class.getName(), new String
[] { "*" }) },
78 new PermissionInfo
[] { new PermissionInfo(AllPermission
.class.getName(), null, null) },
79 ConditionalPermissionInfo
.ALLOW
));
80 // TODO data admin permission
81 // PermissionInfo dataAdminPerm = new PermissionInfo(AuthPermission.class.getName(),
82 // "createLoginContext." + NodeConstants.LOGIN_CONTEXT_DATA_ADMIN, null);
83 // update.getConditionalPermissionInfos().add(permissionAdmin.newConditionalPermissionInfo(null,
84 // new ConditionInfo[] {
85 // new ConditionInfo(BundleLocationCondition.class.getName(), new String[] { "*" }) },
86 // new PermissionInfo[] { dataAdminPerm }, ConditionalPermissionInfo.DENY));
87 // update.getConditionalPermissionInfos().add(permissionAdmin.newConditionalPermissionInfo(null,
88 // new ConditionInfo[] {
89 // new ConditionInfo(BundleSignerCondition.class.getName(), new String[] { "CN=\"Eclipse.org Foundation, Inc.\", OU=IT, O=\"Eclipse.org Foundation, Inc.\", L=Nepean, ST=Ontario, C=CA" }) },
90 // new PermissionInfo[] { dataAdminPerm }, ConditionalPermissionInfo.ALLOW));
93 SecurityProfile securityProfile
= new SecurityProfile() {
95 securityProfile
.applySystemPermissions(permissionAdmin
);
101 // private void initArgeoLogger() {
102 // logger = new CmsOsgiLogger(logReaderService);
103 // if (bundleContext != null)
104 // bundleContext.registerService(ArgeoLogger.class, logger, null);
108 public static <T
> void registerService(Class
<T
> clss
, T service
, Dictionary
<String
, ?
> properties
) {
109 if (bundleContext
!= null) {
110 bundleContext
.registerService(clss
, service
, properties
);
115 public static <T
> T
getService(Class
<T
> clss
) {
116 if (bundleContext
!= null) {
117 return bundleContext
.getService(bundleContext
.getServiceReference(clss
));
128 public void start(BundleContext bc
) throws Exception
{
136 public void stop(BundleContext bc
) throws Exception
{
139 bundleContext
= null;
143 public static BundleContext
getBundleContext() {
144 return bundleContext
;