Introduce node initialisation.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / NodeSecurity.java
index b43a9fdf5c393b5aef084b8eb9e5b3df35e808ee..6714bd6e706c6ca1847e4a97987c889f2f7f6a73 100644 (file)
@@ -1,5 +1,7 @@
 package org.argeo.cms.internal.kernel;
 
+import static org.argeo.cms.internal.kernel.KernelUtils.getOsgiInstanceDir;
+
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
@@ -25,13 +27,15 @@ import org.argeo.cms.auth.AuthConstants;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 
 /** Low-level kernel security */
-class NodeSecurity {
+class NodeSecurity implements KernelConstants {
        public final static int HARDENED = 3;
        public final static int STAGING = 2;
        public final static int DEV = 1;
 
        final static String SECURITY_PROVIDER = "BC";// Bouncy Castle
 
+       private final boolean firstInit;
+
        private final static Log log;
        static {
                log = LogFactory.getLog(NodeSecurity.class);
@@ -57,6 +61,8 @@ class NodeSecurity {
                System.setProperty("java.security.auth.login.config",
                                url.toExternalForm());
 
+               firstInit = !new File(getOsgiInstanceDir(), DIR_NODE).exists();
+
                this.kernelSubject = logInKernel();
        }
 
@@ -112,6 +118,10 @@ class NodeSecurity {
                return securityLevel;
        }
 
+       public boolean isFirstInit() {
+               return firstInit;
+       }
+
        public void setSecurityLevel(int newValue) {
                if (newValue != STAGING || newValue != DEV)
                        throw new CmsException("Invalid value for security level "