X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Fclub%2Fwpia%2Fgigi%2Futil%2FServerConstants.java;h=4e2d9c928fd82d9f173a486b93773dac5b720e7e;hb=1d4b38bd5da9636f4ba80244d92c89b4b5cbdf88;hp=8e985fa9455acfb83212421712a994c3bf8c4740;hpb=d71624703243c182beb0f946ebc582e0366a4686;p=gigi.git diff --git a/src/club/wpia/gigi/util/ServerConstants.java b/src/club/wpia/gigi/util/ServerConstants.java index 8e985fa9..4e2d9c92 100644 --- a/src/club/wpia/gigi/util/ServerConstants.java +++ b/src/club/wpia/gigi/util/ServerConstants.java @@ -1,21 +1,73 @@ 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 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")) { @@ -26,60 +78,33 @@ public class ServerConstants { } 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; - } - - public static String getStaticHostNamePort() { - return staticHostName + port; - } - - public static String getWwwHostNamePort() { - return wwwHostName + port; + suffix = conf.getProperty("name.suffix", "wpia.local"); + HashMap 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 getApiHostNamePort() { - return apiHostName + securePort; + public static String getHostName(Host h) { + return hostnames.get(h); } - public static String getLinkHostNamePort() { - return "link." + getSuffix() + port; + public static String getHostNamePortSecure(Host h) { + return hostnames.get(h) + securePort; } - public static String getLinkHostNamePortSecure() { - return "link." + getSuffix() + securePort; + public static String getHostNamePort(Host h) { + return hostnames.get(h) + port; } public static int getSecurePort() { @@ -130,4 +155,18 @@ public class ServerConstants { 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; + } + }