package club.wpia.gigi.util;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
+import club.wpia.gigi.ocsp.OCSPResponder;
+
public class ServerConstants {
- private static String wwwHostName = "www.wpia.local";
+ public enum Host {
+ /**
+ * Serves the main application. Both via HTTP and HTTPS.
+ */
+ WWW("www"),
+ /**
+ * Serves static resource like css, js, for modal dialogs on
+ * delete-operations and similar things.
+ */
+ STATIC("static"),
+ /**
+ * Serves the same content as {@link #WWW}, but requires
+ * authentification via client certificate.
+ */
+ SECURE("secure"),
+ /**
+ * Serves the API for issuing certificates, receiving Quiz results.
+ */
+ API("api"),
+ /**
+ * Hosts a link-redirector (not served by Gigi) for external links from
+ * Gigi.
+ */
+ LINK("link"),
+ /**
+ * Hosts the certificate repository for the certificates generated
+ * during NRE. Also not served by Gigi.
+ */
+ CRT_REPO("g2.crt"),
+ /**
+ * Hosts the {@link OCSPResponder}.
+ */
+ OCSP_RESPONDER("g2.ocsp");
+
+ private final String value;
+
+ private Host(String value) {
+ this.value = value;
+ }
- private static String secureHostName = "secure.wpia.local";
+ public String getConfigName() {
+ return value;
+ }
- private static String staticHostName = "static.wpia.local";
+ public String getHostDefaultPrefix() {
+ return value;
+ }
+ }
- private static String apiHostName = "api.wpia.local";
+ private static Map<Host, String> hostnames;
private static String securePort, port, secureBindPort, bindPort;
private static String suffix = "wpia.local";
+ private static String appName = null;
+
+ private static String appIdentifier = null;
+
public static void init(Properties conf) {
securePort = port = "";
if ( !conf.getProperty("https.port").equals("443")) {
}
secureBindPort = conf.getProperty("https.bindPort", conf.getProperty("https.port"));
bindPort = conf.getProperty("http.bindPort", conf.getProperty("http.port"));
- wwwHostName = conf.getProperty("name.www");
- secureHostName = conf.getProperty("name.secure");
- staticHostName = conf.getProperty("name.static");
- apiHostName = conf.getProperty("name.api");
- suffix = conf.getProperty("name.suffix", conf.getProperty("name.www").substring(4));
-
- }
-
- public static String getSecureHostName() {
- return secureHostName;
- }
-
- public static String getStaticHostName() {
- return staticHostName;
- }
-
- public static String getWwwHostName() {
- return wwwHostName;
- }
- public static String getApiHostName() {
- return apiHostName;
- }
-
- public static String getSecureHostNamePortSecure() {
- return secureHostName + securePort;
- }
-
- public static String getStaticHostNamePortSecure() {
- return staticHostName + securePort;
- }
-
- public static String getWwwHostNamePortSecure() {
- return wwwHostName + securePort;
+ suffix = conf.getProperty("name.suffix", "wpia.local");
+ HashMap<Host, String> hostnames = new HashMap<>();
+ for (Host h : Host.values()) {
+ hostnames.put(h, conf.getProperty("name." + h.getConfigName(), h.getHostDefaultPrefix() + "." + suffix));
+ }
+ ServerConstants.hostnames = Collections.unmodifiableMap(hostnames);
+ appName = conf.getProperty("appName");
+ if (appName == null) {
+ throw new Error("App name missing");
+ }
+ appIdentifier = conf.getProperty("appIdentifier");
+ if (appIdentifier == null) {
+ throw new Error("App identifier missing");
+ }
}
- public static String getStaticHostNamePort() {
- return staticHostName + port;
+ public static String getHostName(Host h) {
+ return hostnames.get(h);
}
- public static String getWwwHostNamePort() {
- return wwwHostName + port;
+ public static String getHostNamePortSecure(Host h) {
+ return hostnames.get(h) + securePort;
}
- public static String getApiHostNamePort() {
- return apiHostName + securePort;
+ public static String getHostNamePort(Host h) {
+ return hostnames.get(h) + port;
}
public static int getSecurePort() {
}
public static String getSupportMailAddress() {
- return "support@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+ return "support@" + getSuffix();
}
public static String getBoardMailAddress() {
- return "board@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+ return "board@" + getSuffix();
}
public static String getQuizMailAddress() {
- return "quiz@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+ return "quiz@" + getSuffix();
}
public static String getQuizAdminMailAddress() {
- return "quiz-admin@" + ServerConstants.getWwwHostName().replaceFirst("^www\\.", "");
+ return "quiz-admin@" + getSuffix();
+ }
+
+ public static String getAppName() {
+ if (appName == null) {
+ throw new Error("AppName not initialized.");
+ }
+ return appName;
+ }
+
+ public static String getAppIdentifier() {
+ if (appIdentifier == null) {
+ throw new Error("AppIdentifier not initialized.");
+ }
+ return appIdentifier;
}
}