]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java
1 package org
.argeo
.cms
.internal
.runtime
;
3 import java
.net
.InetAddress
;
5 import java
.net
.UnknownHostException
;
7 import javax
.security
.auth
.login
.Configuration
;
9 import org
.argeo
.api
.cms
.CmsLog
;
10 import org
.argeo
.api
.cms
.CmsState
;
11 import org
.argeo
.cms
.auth
.ident
.IdentClient
;
12 import org
.osgi
.framework
.Constants
;
15 * Implementation of a {@link CmsState}, initialising the required services.
17 public class CmsStateImpl
implements CmsState
{
18 private final static CmsLog log
= CmsLog
.getLog(CmsStateImpl
.class);
21 private Long availableSince
;
23 private String stateUuid
;
24 // private final boolean cleanState;
25 private String hostname
;
28 // Runtime.getRuntime().addShutdownHook(new CmsShutdown());
34 if (log
.isTraceEnabled())
35 log
.trace("CMS State started");
37 this.stateUuid
= KernelUtils
.getFrameworkProp(Constants
.FRAMEWORK_UUID
);
38 // this.cleanState = stateUuid.equals(frameworkUuid);
40 this.hostname
= InetAddress
.getLocalHost().getHostName();
41 } catch (UnknownHostException e
) {
42 log
.error("Cannot set hostname: " + e
);
45 availableSince
= System
.currentTimeMillis();
46 if (log
.isDebugEnabled())
47 // log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
48 // (clean state) " : " "));
49 log
.debug("## CMS starting... (" + stateUuid
+ ")");
54 } catch (RuntimeException e
) {
55 log
.error("## FATAL: CMS activator failed", e
);
59 private void initSecurity() {
60 if (System
.getProperty(KernelConstants
.JAAS_CONFIG_PROP
) == null) {
61 String jaasConfig
= KernelConstants
.JAAS_CONFIG
;
62 URL url
= getClass().getResource(jaasConfig
);
63 // System.setProperty(KernelConstants.JAAS_CONFIG_PROP,
64 // url.toExternalForm());
65 KernelUtils
.setJaasConfiguration(url
);
67 // explicitly load JAAS configuration
68 Configuration
.getConfiguration();
72 if (log
.isDebugEnabled())
73 log
.debug("CMS stopping... (" + this.stateUuid
+ ")");
75 long duration
= ((System
.currentTimeMillis() - availableSince
) / 1000) / 60;
76 log
.info("## ARGEO CMS STOPPED after " + (duration
/ 60) + "h " + (duration
% 60) + "min uptime ##");
81 public Long
getAvailableSince() {
82 return availableSince
;
88 public String
getHostname() {
95 public static IdentClient
getIdentClient(String remoteAddr
) {
96 if (!IdentClient
.isDefaultAuthdPassphraseFileAvailable())
98 // TODO make passphrase more configurable
99 return new IdentClient(remoteAddr
);