]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/CmsDeployProperty.java
Fix IPA initialisation
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / CmsDeployProperty.java
1 package org.argeo.cms;
2
3 import java.util.Objects;
4
5 /** A property that can be used to configure a CMS node deployment. */
6 public enum CmsDeployProperty {
7 //
8 // DIRECTORY
9 //
10 DIRECTORY("argeo.directory", 64),
11 //
12 // DATABASE
13 //
14 /** URL of the database backend. */
15 DB_URL("argeo.db.url"),
16 /** DB user of the database backend. */
17 DB_USER("argeo.db.user"),
18 /** DB user password of the database backend. */
19 DB_PASSWORD("argeo.db.password"),
20 //
21 // NETWORK
22 //
23 /** Either a host or an IP address. Restricts all servers to it. */
24 HOST("argeo.host"),
25 /** Either a host or an IP address. Restricts all servers to it. */
26 DNS("argeo.dns", 16),
27 //
28 // HTTP
29 //
30 /** Request an HTTP server on this port. */
31 HTTP_PORT("argeo.http.port"),
32 /** Request an HTTPS server on this port. */
33 HTTPS_PORT("argeo.https.port"),
34 /**
35 * The HTTP header used to convey the DN of a client verified by a reverse
36 * proxy. Typically SSL_CLIENT_S_DN for Apache.
37 */
38 HTTP_PROXY_SSL_HEADER_DN("argeo.http.proxy.ssl.header.dn"),
39 //
40 // SSL
41 //
42 /** SSL keystore for the system. */
43 SSL_KEYSTORE("argeo.ssl.keystore"),
44 /** SSL keystore password for the system. */
45 SSL_PASSWORD("argeo.ssl.password"),
46 /** SSL keystore type password for the system. */
47 SSL_KEYSTORETYPE("argeo.ssl.keystoretype"),
48 /** SSL password for the private key. */
49 SSL_KEYPASSWORD("argeo.ssl.keypassword"),
50 /** Whether a client certificate is required. */
51 SSL_NEEDCLIENTAUTH("argeo.ssl.needclientauth"),
52 /** Whether a client certificate can be used. */
53 SSL_WANTCLIENTAUTH("argeo.ssl.wantclientauth"),
54 /** SSL protocol to use. */
55 SSL_PROTOCOL("argeo.ssl.protocol"),
56 /** SSL algorithm to use. */
57 SSL_ALGORITHM("argeo.ssl.algorithm"),
58 /** Custom SSL trust store. */
59 SSL_TRUSTSTORE("argeo.ssl.truststore"),
60 /** Custom SSL trust store type. */
61 SSL_TRUSTSTORETYPE("argeo.ssl.truststoretype"),
62 /** Custom SSL trust store type. */
63 SSL_TRUSTSTOREPASSWORD("argeo.ssl.truststorepassword"),
64 //
65 // WEBSOCKET
66 //
67 /** Whether web socket should be enables in web server. */
68 WEBSOCKET_ENABLED("argeo.websocket.enabled"),
69 //
70 // SSH
71 //
72 /** Request an HTTP server on this port. */
73 SSHD_PORT("argeo.sshd.port"),
74 /** Path to admin authorized keys file. */
75 SSHD_AUTHORIZEDKEYS("argeo.sshd.authorizedkeys"),
76 //
77 // INTERNATIONALIZATION
78 //
79 /** Locales enabled for this system, the first one is considered the default. */
80 LOCALE("argeo.locale", 256),
81 //
82 // NODE
83 //
84 /** Directories to copy to the data area during the first initialisation. */
85 NODE_INIT("argeo.node.init", 64),
86 //
87 // JAVA
88 //
89 /** Custom JAAS config. */
90 JAVA_LOGIN_CONFIG("java.security.auth.login.config", true),
91 //
92 // OSGi
93 //
94 /** OSGi writable data area. */
95 OSGI_INSTANCE_AREA("osgi.instance.area"),
96 /** OSGi writable configuration area. */
97 OSGI_CONFIGURATION_AREA("osgi.configuration.area"),
98 //
99 ;
100
101 private String property;
102 private boolean systemPropertyOnly = false;
103
104 private int maxCount = 1;
105
106 CmsDeployProperty(String property) {
107 this(property, 1, false);
108 }
109
110 CmsDeployProperty(String property, int maxCount) {
111 this(property, maxCount, false);
112 }
113
114 CmsDeployProperty(String property, boolean systemPropertyOnly) {
115 this.property = property;
116 }
117
118 CmsDeployProperty(String property, int maxCount, boolean systemPropertyOnly) {
119 this.property = property;
120 this.systemPropertyOnly = systemPropertyOnly;
121 this.maxCount = maxCount;
122 }
123
124 public String getProperty() {
125 return property;
126 }
127
128 public boolean isSystemPropertyOnly() {
129 return systemPropertyOnly;
130 }
131
132 public int getMaxCount() {
133 return maxCount;
134 }
135
136 public static CmsDeployProperty find(String property) {
137 int index = getPropertyIndex(property);
138 String propertyName = index == 0 ? property : property.substring(0, property.lastIndexOf('.'));
139 for (CmsDeployProperty deployProperty : values()) {
140 if (deployProperty.getProperty().equals(propertyName))
141 return deployProperty;
142 }
143 return null;
144 }
145
146 public static int getPropertyIndex(String property) {
147 Objects.requireNonNull(property);
148 int lastDot = property.lastIndexOf('.');
149 if (lastDot <= 0 || lastDot == (property.length() - 1)) {
150 throw new IllegalArgumentException("Property " + property + " is not qualified (must contain a dot).");
151 }
152 String lastSegment = property.substring(lastDot + 1);
153 int index;
154 try {
155 index = Integer.parseInt(lastSegment);
156 } catch (NumberFormatException e) {
157 index = 0;
158 }
159 return index;
160 }
161
162 }