OS user as single user
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / FirstInit.java
index 8bd348f8e5efb147943e90a1f4ea344a341d51c0..6175e4d030c79abe9d99d7eaec0561391f1677fa 100644 (file)
@@ -56,8 +56,8 @@ class FirstInit {
                String httpPort = getFrameworkProp("org.osgi.service.http.port");
                String httpsPort = getFrameworkProp("org.osgi.service.http.port.secure");
                /// TODO make it more generic
-               String httpHost = getFrameworkProp(JettyConstants.PROPERTY_PREFIX + '.' + JettyConstants.HTTP_HOST);
-               String httpsHost = getFrameworkProp(JettyConstants.PROPERTY_PREFIX + '.' + JettyConstants.HTTPS_HOST);
+               String httpHost = getFrameworkProp(JettyConstants.PROPERTY_PREFIX + JettyConstants.HTTP_HOST);
+               String httpsHost = getFrameworkProp(JettyConstants.PROPERTY_PREFIX + JettyConstants.HTTPS_HOST);
 
                final Hashtable<String, Object> props = new Hashtable<String, Object>();
                // try {
@@ -71,11 +71,11 @@ class FirstInit {
                                props.put(JettyConstants.HTTPS_ENABLED, true);
                                Path keyStorePath = KernelUtils.getOsgiInstancePath(KernelConstants.DEFAULT_KEYSTORE_PATH);
                                String keyStorePassword = getFrameworkProp(
-                                               JettyConstants.PROPERTY_PREFIX + '.' + JettyConstants.SSL_PASSWORD);
+                                               JettyConstants.PROPERTY_PREFIX + JettyConstants.SSL_PASSWORD);
                                if (keyStorePassword == null)
                                        keyStorePassword = "changeit";
                                if (!Files.exists(keyStorePath))
-                                       createSelfSignedKeyStore(keyStorePath);
+                                       createSelfSignedKeyStore(keyStorePath, keyStorePassword);
                                props.put(JettyConstants.SSL_KEYSTORETYPE, "PKCS12");
                                props.put(JettyConstants.SSL_KEYSTORE, keyStorePath.toString());
                                props.put(JettyConstants.SSL_PASSWORD, keyStorePassword);
@@ -100,7 +100,8 @@ class FirstInit {
                String nodeRolesUri = getFrameworkProp(NodeConstants.ROLES_URI);
                String baseNodeRoleDn = NodeConstants.ROLES_BASEDN;
                if (nodeRolesUri == null) {
-                       File nodeRolesFile = new File(nodeBaseDir, baseNodeRoleDn + ".ldif");
+                       nodeRolesUri = baseNodeRoleDn + ".ldif";
+                       File nodeRolesFile = new File(nodeBaseDir, nodeRolesUri);
                        if (!nodeRolesFile.exists())
                                try {
                                        FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(baseNodeRoleDn + ".ldif"),
@@ -108,30 +109,26 @@ class FirstInit {
                                } catch (IOException e) {
                                        throw new CmsException("Cannot copy demo resource", e);
                                }
-                       nodeRolesUri = nodeRolesFile.toURI().toString();
+                       // nodeRolesUri = nodeRolesFile.toURI().toString();
                }
                uris.add(nodeRolesUri);
 
                // Business roles
                String userAdminUris = getFrameworkProp(NodeConstants.USERADMIN_URIS);
                if (userAdminUris == null) {
-                       String kerberosDomain = Activator.getCmsSecurity().getKerberosDomain();
-                       if (kerberosDomain != null) {
-                               userAdminUris = "ipa:///" + kerberosDomain;
-                       } else {
-                               String demoBaseDn = "dc=example,dc=com";
-                               File businessRolesFile = new File(nodeBaseDir, demoBaseDn + ".ldif");
-                               if (!businessRolesFile.exists())
-                                       try {
-                                               FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(demoBaseDn + ".ldif"),
-                                                               businessRolesFile);
-                                       } catch (IOException e) {
-                                               throw new CmsException("Cannot copy demo resource", e);
-                                       }
-                               userAdminUris = businessRolesFile.toURI().toString();
-                               log.warn("## DEV Using dummy base DN " + demoBaseDn);
-                               // TODO downgrade security level
-                       }
+                       String demoBaseDn = "dc=example,dc=com";
+                       userAdminUris = demoBaseDn + ".ldif";
+                       File businessRolesFile = new File(nodeBaseDir, userAdminUris);
+                       if (!businessRolesFile.exists())
+                               try {
+                                       FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(demoBaseDn + ".ldif"),
+                                                       businessRolesFile);
+                               } catch (IOException e) {
+                                       throw new CmsException("Cannot copy demo resource", e);
+                               }
+                       // userAdminUris = businessRolesFile.toURI().toString();
+                       log.warn("## DEV Using dummy base DN " + demoBaseDn);
+                       // TODO downgrade security level
                }
                for (String userAdminUri : userAdminUris.split(" "))
                        uris.add(userAdminUri);
@@ -147,11 +144,11 @@ class FirstInit {
                                        if (uri.startsWith("/") || uri.startsWith("./") || uri.startsWith("../"))
                                                u = new File(uri).getCanonicalFile().toURI();
                                        else if (!uri.contains("/")) {
-                                               u = KernelUtils.getOsgiInstanceUri(KernelConstants.DIR_NODE + '/' + uri);
-                                               // u = new URI(nodeBaseDir.toURI() + uri);
+                                               // u = KernelUtils.getOsgiInstanceUri(KernelConstants.DIR_NODE + '/' + uri);
+                                               u = new URI(uri);
                                        } else
                                                throw new CmsException("Cannot interpret " + uri + " as an uri");
-                               } else if (u.getScheme().equals("file")) {
+                               } else if (u.getScheme().equals(UserAdminConf.SCHEME_FILE)) {
                                        u = new File(u).getCanonicalFile().toURI();
                                }
                        } catch (Exception e) {
@@ -165,8 +162,8 @@ class FirstInit {
        }
 
        /**
-        * Called before node initialisation, in order populate OSGi instance are
-        * with some files (typically LDIF, etc).
+        * Called before node initialisation, in order populate OSGi instance are with
+        * some files (typically LDIF, etc).
         */
        static void prepareInstanceArea() {
                String nodeInit = getFrameworkProp(NodeConstants.NODE_INIT);
@@ -201,11 +198,11 @@ class FirstInit {
                        }
        }
 
-       private void createSelfSignedKeyStore(Path keyStorePath) {
+       private void createSelfSignedKeyStore(Path keyStorePath, String keyStorePassword) {
                // for (Provider provider : Security.getProviders())
                // System.out.println(provider.getName());
                File keyStoreFile = keyStorePath.toFile();
-               char[] ksPwd = "changeit".toCharArray();
+               char[] ksPwd = keyStorePassword.toCharArray();
                char[] keyPwd = Arrays.copyOf(ksPwd, ksPwd.length);
                if (!keyStoreFile.exists()) {
                        try {