diff --git a/application.yml b/application.yml index b1fe996..1598e0c 100644 --- a/application.yml +++ b/application.yml @@ -1,6 +1,11 @@ mongoUri: mongodb://158.69.26.208:27027/MineHQ redisUri: redis://209.222.96.50:6379 +network: + name: MineHQ Network + appealUrl: minehq.com/appeal + rootPermission: minehq + http: port: 80 keystoreFile: diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index d1752ab..4cbe21f 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -152,18 +152,16 @@ public final class APIv3 extends AbstractVerticle implements ApplicationContextA } private void setupHttpServer() { - Environment environment = SpringUtils.getBean(Environment.class); - HttpServerOptions httpServerOptions = new HttpServerOptions(); httpServerOptions.setCompressionSupported(true); - if (!environment.getProperty("http.keystoreFile").isEmpty()) { + if (!SpringUtils.getProperty("http.keystoreFile").isEmpty()) { httpServerOptions.setSsl(true); httpServerOptions.setKeyStoreOptions( new JksOptions() - .setPassword(environment.getProperty("http.keystorePassword")) - .setPath(environment.getProperty("http.keystoreFile")) + .setPassword(SpringUtils.getProperty("http.keystorePassword")) + .setPath(SpringUtils.getProperty("http.keystoreFile")) ); } @@ -292,7 +290,7 @@ public final class APIv3 extends AbstractVerticle implements ApplicationContextA httpGet(router, "/whoami", GETWhoAmI.class); httpPost(router, "/logout", POSTLogout.class); - int port = environment.getProperty("http.port", Integer.class); + int port = SpringUtils.getProperty("http.port", Integer.class); webServer.requestHandler(router::accept).listen(port); } diff --git a/src/main/java/net/frozenorb/apiv3/model/IpBan.java b/src/main/java/net/frozenorb/apiv3/model/IpBan.java index 7abf313..d8cbec2 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpBan.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpBan.java @@ -145,15 +145,15 @@ public final class IpBan { String accessDenialReason; if (linkedIpBanUser != null) { - accessDenialReason = "Your IP address has been suspended from the MineHQ Network for a punishment related to " + linkedIpBanUser.getLastUsername() + ". \n\n"; + accessDenialReason = "Your IP address has been suspended from the " + SpringUtils.getProperty("network.name") + " for a punishment related to " + linkedIpBanUser.getLastUsername() + ". \n\n"; } else { - accessDenialReason = "Your IP address has been suspended from the MineHQ Network. \n\n"; + accessDenialReason = "Your IP address has been suspended from the " + SpringUtils.getProperty("network.name") + ". \n\n"; } if (getExpiresAt() != null) { accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now())); } else { - accessDenialReason += "Appeal at MineHQ.com/appeal"; + accessDenialReason += "Appeal at " + SpringUtils.getProperty("network.appealUrl"); } return accessDenialReason; diff --git a/src/main/java/net/frozenorb/apiv3/model/IpIntel.java b/src/main/java/net/frozenorb/apiv3/model/IpIntel.java index 9ff7957..05f3fe3 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpIntel.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpIntel.java @@ -151,7 +151,7 @@ public final class IpIntel { private IpIntel(String ip, GeoIpInfo result) { this.id = ip; - this.hashedIp = Hashing.sha256().hashString(id + SpringUtils.getBean(Environment.class).getProperty("ipHashing.salt"), Charsets.UTF_8).toString(); + this.hashedIp = Hashing.sha256().hashString(id + SpringUtils.getProperty("ipHashing.salt"), Charsets.UTF_8).toString(); this.lastUpdatedAt = Instant.now(); this.result = result; this.location = new GeoJsonPoint(result.getLocation()); diff --git a/src/main/java/net/frozenorb/apiv3/model/IpLogEntry.java b/src/main/java/net/frozenorb/apiv3/model/IpLogEntry.java index 05ea179..90b5e32 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpLogEntry.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpLogEntry.java @@ -81,7 +81,7 @@ public final class IpLogEntry { this.id = new ObjectId().toString(); this.user = user.getId(); this.userIp = userIp; - this.hashedUserIp = Hashing.sha256().hashString(userIp + SpringUtils.getBean(Environment.class).getProperty("ipHashing.salt"), Charsets.UTF_8).toString(); + this.hashedUserIp = Hashing.sha256().hashString(userIp + SpringUtils.getProperty("ipHashing.salt"), Charsets.UTF_8).toString(); this.firstSeenAt = Instant.now(); this.lastSeenAt = Instant.now(); this.uses = 0; diff --git a/src/main/java/net/frozenorb/apiv3/model/Punishment.java b/src/main/java/net/frozenorb/apiv3/model/Punishment.java index 10c1b74..86c5da8 100644 --- a/src/main/java/net/frozenorb/apiv3/model/Punishment.java +++ b/src/main/java/net/frozenorb/apiv3/model/Punishment.java @@ -141,14 +141,14 @@ public final class Punishment { public String getAccessDenialReason() { switch (type) { case BLACKLIST: - return "Your account has been blacklisted from the MineHQ Network. \n\nThis type of punishment cannot be appealed."; + return "Your account has been blacklisted from the " + SpringUtils.getProperty("network.name") + ". \n\nThis type of punishment cannot be appealed."; case BAN: - String accessDenialReason = "Your account has been suspended from the MineHQ Network. \n\n"; + String accessDenialReason = "Your account has been suspended from the " + SpringUtils.getProperty("network.name") + ". \n\n"; if (getExpiresAt() != null) { accessDenialReason += "Expires in " + TimeUtils.formatIntoDetailedString(TimeUtils.getSecondsBetween(getExpiresAt(), Instant.now())); } else { - accessDenialReason += "Appeal at MineHQ.com/appeal"; + accessDenialReason += "Appeal at " + SpringUtils.getProperty("network.appealUrl"); } return accessDenialReason; diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index d711a71..8a453bc 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -438,12 +438,12 @@ public final class User { if (!userType.isAllowed()) { proposedAccess = ImmutableMap.of( "allowed", false, - "message", "You cannot join the server from a VPN." + "message", "You cannot join the " + SpringUtils.getProperty("network.name") + " from a VPN." ); } else if (BannedAsn.findById(geoIpInfo.getTraits().getAsn()) != null) { proposedAccess = ImmutableMap.of( "allowed", false, - "message", "You cannot join the server from this ISP." + "message", "You cannot join the " + SpringUtils.getProperty("network.name") + " from this ISP." ); } diff --git a/src/main/java/net/frozenorb/apiv3/unsorted/Permissions.java b/src/main/java/net/frozenorb/apiv3/unsorted/Permissions.java index af69b5d..11c5b80 100644 --- a/src/main/java/net/frozenorb/apiv3/unsorted/Permissions.java +++ b/src/main/java/net/frozenorb/apiv3/unsorted/Permissions.java @@ -1,16 +1,20 @@ package net.frozenorb.apiv3.unsorted; +import net.frozenorb.apiv3.util.SpringUtils; + import lombok.experimental.UtilityClass; @UtilityClass public class Permissions { - public static final String PROTECTED_PUNISHMENT = "minehq.punishment.protected"; - public static final String BYPASS_VPN_CHECK = "minehq.vpn.bypass"; - public static final String REQUIRE_TOTP_CODE = "minehq.totp.require"; - public static final String CREATE_PUNISHMENT = "minehq.punishment.create"; - public static final String REMOVE_PUNISHMENT = "minehq.punishment.remove"; - public static final String CREATE_GRANT = "minehq.grant.create"; - public static final String REMOVE_GRANT = "minehq.grant.remove"; + private static final String rootPermission = SpringUtils.getProperty("network.rootPermission"); + + public static final String PROTECTED_PUNISHMENT = rootPermission + ".punishment.protected"; + public static final String BYPASS_VPN_CHECK = rootPermission + ".vpn.bypass"; + public static final String REQUIRE_TOTP_CODE = rootPermission + ".totp.require"; + public static final String CREATE_PUNISHMENT = rootPermission + ".punishment.create"; + public static final String REMOVE_PUNISHMENT = rootPermission + ".punishment.remove"; + public static final String CREATE_GRANT = rootPermission + ".grant.create"; + public static final String REMOVE_GRANT = rootPermission + ".grant.remove"; } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/util/SpringUtils.java b/src/main/java/net/frozenorb/apiv3/util/SpringUtils.java index d4fd69b..01a0eb4 100644 --- a/src/main/java/net/frozenorb/apiv3/util/SpringUtils.java +++ b/src/main/java/net/frozenorb/apiv3/util/SpringUtils.java @@ -1,6 +1,7 @@ package net.frozenorb.apiv3.util; import org.springframework.beans.factory.BeanFactory; +import org.springframework.core.env.Environment; import lombok.Getter; import lombok.Setter; @@ -13,4 +14,12 @@ public final class SpringUtils { return beanFactory.getBean(type); } + public static String getProperty(String key) { + return beanFactory.getBean(Environment.class).getProperty(key); + } + + public static T getProperty(String key, Class type) { + return beanFactory.getBean(Environment.class).getProperty(key, type); + } + } \ No newline at end of file