+ private void initTrackers() {
+ ServiceTracker<?, ?> httpSt = new ServiceTracker<HttpService, HttpService>(bc, HttpService.class, null) {
+
+ @Override
+ public HttpService addingService(ServiceReference<HttpService> sr) {
+ httpAvailable = true;
+ Object httpPort = sr.getProperty("http.port");
+ Object httpsPort = sr.getProperty("https.port");
+ log.info(httpPortsMsg(httpPort, httpsPort));
+ checkReadiness();
+ return super.addingService(sr);
+ }
+ };
+ // httpSt.open();
+ KernelUtils.asyncOpen(httpSt);
+
+ ServiceTracker<?, ?> repoContextSt = new RepositoryContextStc();
+ // repoContextSt.open();
+ KernelUtils.asyncOpen(repoContextSt);
+
+ ServiceTracker<?, ?> userAdminSt = new ServiceTracker<UserAdmin, UserAdmin>(bc, UserAdmin.class, null) {
+ @Override
+ public UserAdmin addingService(ServiceReference<UserAdmin> reference) {
+ UserAdmin userAdmin = super.addingService(reference);
+ addStandardSystemRoles(userAdmin);
+ userAdminAvailable = true;
+ checkReadiness();
+ return userAdmin;
+ }
+ };
+ // userAdminSt.open();
+ KernelUtils.asyncOpen(userAdminSt);
+
+ ServiceTracker<?, ?> confAdminSt = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>(bc,
+ ConfigurationAdmin.class, null) {
+ @Override
+ public ConfigurationAdmin addingService(ServiceReference<ConfigurationAdmin> reference) {
+ ConfigurationAdmin configurationAdmin = bc.getService(reference);
+ boolean isClean;
+ try {
+ Configuration[] confs = configurationAdmin
+ .listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
+ isClean = confs == null || confs.length == 0;
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot analyse clean state", e);
+ }
+ deployConfig = new DeployConfig(configurationAdmin, dataModels, isClean);
+ httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
+ try {
+ Configuration[] configs = configurationAdmin
+ .listConfigurations("(service.factoryPid=" + NodeConstants.NODE_USER_ADMIN_PID + ")");
+
+ boolean hasDomain = false;
+ for (Configuration config : configs) {
+ Object realm = config.getProperties().get(UserAdminConf.realm.name());
+ if (realm != null) {
+ log.debug("Found realm: " + realm);
+ hasDomain = true;
+ }
+ }
+ if (hasDomain) {
+ loadIpaJaasConfiguration();
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot initialize config", e);
+ }
+ return super.addingService(reference);
+ }
+ };
+ // confAdminSt.open();
+ KernelUtils.asyncOpen(confAdminSt);
+ }
+
+ private String httpPortsMsg(Object httpPort, Object httpsPort) {
+ return (httpPort != null ? "HTTP " + httpPort + " " : " ") + (httpsPort != null ? "HTTPS " + httpsPort : "");
+ }
+
+ private void addStandardSystemRoles(UserAdmin userAdmin) {
+ // we assume UserTransaction is already available (TODO make it more robust)
+ UserTransaction userTransaction = bc.getService(bc.getServiceReference(UserTransaction.class));
+ try {
+ userTransaction.begin();
+ Role adminRole = userAdmin.getRole(NodeConstants.ROLE_ADMIN);
+ if (adminRole == null) {
+ adminRole = userAdmin.createRole(NodeConstants.ROLE_ADMIN, Role.GROUP);
+ }
+ if (userAdmin.getRole(NodeConstants.ROLE_USER_ADMIN) == null) {
+ Group userAdminRole = (Group) userAdmin.createRole(NodeConstants.ROLE_USER_ADMIN, Role.GROUP);
+ userAdminRole.addMember(adminRole);
+ }
+ userTransaction.commit();
+ } catch (Exception e) {
+ try {
+ userTransaction.rollback();
+ } catch (Exception e1) {
+ // silent
+ }
+ throw new IllegalStateException("Cannot add standard system roles", e);
+ }