]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - runtime/CmsStateImpl.java
1 package org
.argeo
.cms
.internal
.runtime
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.net
.InetAddress
;
7 import java
.net
.UnknownHostException
;
8 import java
.nio
.file
.Files
;
9 import java
.nio
.file
.Path
;
10 import java
.util
.TreeMap
;
11 import java
.util
.UUID
;
13 import javax
.security
.auth
.login
.Configuration
;
15 import org
.argeo
.api
.cms
.CmsConstants
;
16 import org
.argeo
.api
.cms
.CmsLog
;
17 import org
.argeo
.api
.cms
.CmsState
;
18 import org
.argeo
.api
.uuid
.UuidFactory
;
19 import org
.argeo
.cms
.auth
.ident
.IdentClient
;
20 import org
.argeo
.util
.directory
.ldap
.LdifParser
;
23 * Implementation of a {@link CmsState}, initialising the required services.
25 public class CmsStateImpl
implements CmsState
{
26 private final static CmsLog log
= CmsLog
.getLog(CmsStateImpl
.class);
29 private Long availableSince
;
32 // private final boolean cleanState;
33 private String hostname
;
35 private UuidFactory uuidFactory
;
38 // Runtime.getRuntime().addShutdownHook(new CmsShutdown());
44 if (log
.isTraceEnabled())
45 log
.trace("CMS State started");
47 // String stateUuidStr = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
48 // this.uuid = UUID.fromString(stateUuidStr);
49 this.uuid
= uuidFactory
.timeUUID();
50 // this.cleanState = stateUuid.equals(frameworkUuid);
52 this.hostname
= InetAddress
.getLocalHost().getHostName();
53 } catch (UnknownHostException e
) {
54 log
.error("Cannot set hostname: " + e
);
57 availableSince
= System
.currentTimeMillis();
58 if (log
.isDebugEnabled())
59 // log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
60 // (clean state) " : " "));
61 log
.debug("## CMS starting... (" + uuid
+ ")");
66 if (!Files
.exists(getDataPath(CmsConstants
.NODE
))) {// first init
70 } catch (RuntimeException
| IOException e
) {
71 log
.error("## FATAL: CMS activator failed", e
);
75 private void initSecurity() {
76 if (System
.getProperty(KernelConstants
.JAAS_CONFIG_PROP
) == null) {
77 String jaasConfig
= KernelConstants
.JAAS_CONFIG
;
78 URL url
= getClass().getResource(jaasConfig
);
79 // System.setProperty(KernelConstants.JAAS_CONFIG_PROP,
80 // url.toExternalForm());
81 KernelUtils
.setJaasConfiguration(url
);
83 // explicitly load JAAS configuration
84 Configuration
.getConfiguration();
88 if (log
.isDebugEnabled())
89 log
.debug("CMS stopping... (" + this.uuid
+ ")");
91 long duration
= ((System
.currentTimeMillis() - availableSince
) / 1000) / 60;
92 log
.info("## ARGEO CMS STOPPED after " + (duration
/ 60) + "h " + (duration
% 60) + "min uptime ##");
95 private void firstInit() throws IOException
{
96 log
.info("## FIRST INIT ##");
97 // FirstInit firstInit = new FirstInit();
98 InitUtils
.prepareFirstInitInstanceArea();
102 public String
getDeployProperty(String key
) {
103 return KernelUtils
.getFrameworkProp(key
);
107 public Path
getDataPath(String relativePath
) {
108 return KernelUtils
.getOsgiInstancePath(relativePath
);
112 public Long
getAvailableSince() {
113 return availableSince
;
119 public String
getHostname() {
124 public UUID
getUuid() {
128 public void setUuidFactory(UuidFactory uuidFactory
) {
129 this.uuidFactory
= uuidFactory
;
135 public static IdentClient
getIdentClient(String remoteAddr
) {
136 if (!IdentClient
.isDefaultAuthdPassphraseFileAvailable())
138 // TODO make passphrase more configurable
139 return new IdentClient(remoteAddr
);