diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/CompositeResolver.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/CompositeResolver.java index 1c82c69ed..30ab13680 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/CompositeResolver.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/CompositeResolver.java @@ -23,7 +23,7 @@ import java.util.Optional; /** * Utility Resolver for organizing resolution in a tree-like structure. *

- * CompositeResolver removes first part of the target with {@link URLTarget#omitFirst()} + * CompositeResolver removes first part of the target with {@link URIPath#omitFirst()} * before calling the child Resolvers. * * @author Rsl1122 @@ -42,7 +42,7 @@ public final class CompositeResolver implements Resolver { return new Builder(); } - private Optional getResolver(URLTarget target) { + private Optional getResolver(URIPath target) { return target.getPart(0).flatMap(this::find); } @@ -63,16 +63,16 @@ public final class CompositeResolver implements Resolver { } @Override - public boolean canAccess(WebUser permissions, URLTarget target, Parameters parameters) { + public boolean canAccess(WebUser permissions, URIPath target, URIQuery query) { return getResolver(target) - .map(resolver -> resolver.canAccess(permissions, target.omitFirst(), parameters)) + .map(resolver -> resolver.canAccess(permissions, target.omitFirst(), query)) .orElse(true); } @Override - public Optional resolve(URLTarget target, Parameters parameters) { + public Optional resolve(URIPath target, URIQuery query) { return getResolver(target) - .flatMap(resolver -> resolver.resolve(target.omitFirst(), parameters)); + .flatMap(resolver -> resolver.resolve(target.omitFirst(), query)); } public static class Builder { @@ -86,7 +86,7 @@ public final class CompositeResolver implements Resolver { * Add a new resolver to the CompositeResolver. * * @param prefix Start of the target (first part of the target string, eg "example" in "/example/target/", or "" in "/") - * @param resolver Resolver to call for this target, {@link URLTarget#omitFirst()} will be called for Resolver method calls. + * @param resolver Resolver to call for this target, {@link URIPath#omitFirst()} will be called for Resolver method calls. * @return this builder. */ public Builder add(String prefix, Resolver resolver) { diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Resolver.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Resolver.java index 5d452979f..3d31763c6 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Resolver.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Resolver.java @@ -27,23 +27,35 @@ public interface Resolver { * * @param permissions WebUser that is accessing this page. * @param target Target that is being accessed, /example/target - * @param parameters Parameters in the URL, ?param=value etc. + * @param query Parameters in the URL, ?param=value etc. * @return true if allowed or invalid target, false if response should be 403 (forbidden) */ - boolean canAccess(WebUser permissions, URLTarget target, Parameters parameters); + boolean canAccess(WebUser permissions, URIPath target, URIQuery query); /** * Implement request resolution. * - * @param target Target that is being accessed, /example/target - * @param parameters Parameters in the URL, ?param=value etc. + * @param target Target that is being accessed, /example/target + * @param query Parameters in the URL, ?param=value etc. * @return Response or empty if the response should be 404 (not found). * @see Response for return value */ - Optional resolve(URLTarget target, Parameters parameters); + Optional resolve(URIPath target, URIQuery query); default ResponseBuilder newResponseBuilder() { - return new ResponseBuilder(); + return Response.builder(); } + /** + * Override this method with false to always allow using this resolver. + *

+ * Use this when content/style is needed for displaying pages where authentication is not available/needed. + * + * @param target Target that is being accessed, /example/target + * @param query Parameters in the URL, ?param=value etc. + * @return true by default. If false is returned {@link #canAccess(WebUser, URIPath, URIQuery)} will not be called. + */ + default boolean requiresAuth(URIPath target, URIQuery query) { + return true; + } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Response.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Response.java index d81e3f9c3..2ea1e169b 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Response.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Response.java @@ -38,6 +38,10 @@ public final class Response { headers = new HashMap<>(); } + public static ResponseBuilder builder() { + return new ResponseBuilder(); + } + public byte[] getBytes() { return bytes; } @@ -54,4 +58,8 @@ public final class Response { return Optional.ofNullable(charset); } + public boolean isErrorResponse() { + return code >= 400; + } + } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URLTarget.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIPath.java similarity index 63% rename from Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URLTarget.java rename to Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIPath.java index 295685ab3..ce15c1e5d 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URLTarget.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIPath.java @@ -18,29 +18,20 @@ package com.djrapitops.plan.delivery.web.resolver; import java.util.Optional; -public final class URLTarget { +public final class URIPath { - private final String full; + private final String path; - public URLTarget(String target) { - full = target; - } - - /** - * Obtain the full target. - * - * @return Example: "/target/path/in/url" - */ - public String asString() { - return full; + public URIPath(String path) { + this.path = path; } /** * Removes parts of the URL before an index. *

- * Example: /example/target, 0 returns /example/target - * Example: /example/target, 1 returns /target - * Example: /example/target, 2 returns '' + * Example: /example/path, 0 returns /example/path + * Example: /example/path, 1 returns /path + * Example: /example/path, 2 returns '' * Example: /, 0 returns / * Example: /, 1 returns '' * @@ -67,26 +58,35 @@ public final class URLTarget { } /** - * Obtain part of the target by index of slashes in the URL. + * Obtain the full path. + * + * @return Example: "/target/path/in/url" + */ + public String asString() { + return path; + } + + /** + * Obtain part of the path by index of slashes in the URL. *

- * Example: "/example/target", 0 returns "example" - * Example: "/example/target", 1 returns "target" - * Example: "/example/target", 2 returns empty optional - * Example: "/example/target/", 2 returns "" + * Example: "/example/path", 0 returns "example" + * Example: "/example/path", 1 returns "path" + * Example: "/example/path", 2 returns empty optional + * Example: "/example/path/", 2 returns "" * Example: "/", 0 returns "" * Example: "/", 1 returns empty optional * * @param index Index from root, eg. /0/1/2/3 etc - * @return part after a '/' in the target, + * @return part after a '/' in the path, */ public Optional getPart(int index) { - String leftover = removePartsBefore(full, index); + String leftover = removePartsBefore(path, index); if (leftover.isEmpty()) return Optional.empty(); // Remove the leading slash to find ending slash leftover = leftover.substring(1); - // Remove rest of the target (Ends in the next slash) + // Remove rest of the path (Ends in the next slash) int nextSlash = leftover.indexOf('/'); if (nextSlash == -1) { return Optional.of(leftover); @@ -96,19 +96,27 @@ public final class URLTarget { } public boolean endsWith(String suffix) { - return full.endsWith(suffix); + return path.endsWith(suffix); } /** - * Immutable modification, removes first part of the target string. + * Immutable modification, removes first part of the path string. *

- * Example: URLTarget "/example/target" return value of omitFirst URLTarget is "/target" - * Example: URLTarget "/example" return value of omitFirst URLTarget is "/" - * Example: URLTarget "/" return value of omitFirst URLTarget is "" + * Example: URIPath "/example/path" return value of omitFirst URIPath is "/path" + * Example: URIPath "/example" return value of omitFirst URIPath is "/" + * Example: URIPath "/" return value of omitFirst URIPath is "" * - * @return new URLTarget with first part removed. + * @return new URIPath with first part removed. */ - public URLTarget omitFirst() { - return new URLTarget(removePartsBefore(full, 1)); + public URIPath omitFirst() { + return new URIPath(removePartsBefore(path, 1)); + } + + public int length() { + int count = 0; + for (char c : path.toCharArray()) { + if (c == '/') count++; + } + return count; } } diff --git a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Parameters.java b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIQuery.java similarity index 59% rename from Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Parameters.java rename to Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIQuery.java index 759ada8ee..0039f2230 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/Parameters.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/delivery/web/resolver/URIQuery.java @@ -16,6 +16,10 @@ */ package com.djrapitops.plan.delivery.web.resolver; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -24,14 +28,37 @@ import java.util.Optional; * * @author Rsl1122 */ -public final class Parameters { +public final class URIQuery { private final Map byKey; - public Parameters(Map byKey) { + public URIQuery(Map byKey) { this.byKey = byKey; } + public URIQuery(String fromURI) { + this.byKey = parseParameters(fromURI); + } + + private Map parseParameters(String fromURI) { + if (fromURI == null || fromURI.isEmpty()) { + return Collections.emptyMap(); + } + + Map parameters = new HashMap<>(); + String[] keysAndValues = StringUtils.split(fromURI, '&'); + for (String kv : keysAndValues) { + if (kv.isEmpty()) { + continue; + } + String[] keyAndValue = StringUtils.split(kv, "=", 2); + if (keyAndValue.length >= 2) { + parameters.put(keyAndValue[0], keyAndValue[1]); + } + } + return parameters; + } + /** * Obtain an URI parameter by key. * diff --git a/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java b/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java index 136ed9729..911f8453e 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/settings/SettingsService.java @@ -33,7 +33,7 @@ import java.util.function.Supplier; public interface SettingsService { static SettingsService getInstance() { - return Optional.ofNullable(SettingsServiceHolder.service) + return Optional.ofNullable(Holder.service) .orElseThrow(() -> new IllegalStateException("SettingsService has not been initialised yet.")); } @@ -64,15 +64,15 @@ public interface SettingsService { */ List getStringList(String path, Supplier> defaultValue); - class SettingsServiceHolder { + class Holder { static SettingsService service; - private SettingsServiceHolder() { + private Holder() { /* Static variable holder */ } static void set(SettingsService service) { - SettingsServiceHolder.service = service; + Holder.service = service; } } diff --git a/Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URLTargetTest.java b/Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URIPathTest.java similarity index 78% rename from Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URLTargetTest.java rename to Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URIPathTest.java index 923aea001..9076bb82e 100644 --- a/Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URLTargetTest.java +++ b/Plan/api/src/test/java/com/djrapitops/plan/delivery/web/resolver/URIPathTest.java @@ -25,16 +25,16 @@ import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertEquals; /** - * Tests for {@link URLTarget} behavior. + * Tests for {@link URIPath} behavior. * * @author Rsl1122 */ @RunWith(JUnitPlatform.class) -class URLTargetTest { +class URIPathTest { @Test void firstPartEmptyForRoot() { - URLTarget target = new URLTarget("/"); + URIPath target = new URIPath("/"); Optional expected = Optional.of(""); Optional result = target.getPart(0); assertEquals(expected, result); @@ -42,7 +42,7 @@ class URLTargetTest { @Test void fullTargetForRoot() { - URLTarget target = new URLTarget("/"); + URIPath target = new URIPath("/"); String expected = "/"; String result = target.asString(); assertEquals(expected, result); @@ -50,7 +50,7 @@ class URLTargetTest { @Test void firstPart() { - URLTarget target = new URLTarget("/example/target"); + URIPath target = new URIPath("/example/target"); Optional expected = Optional.of("example"); Optional result = target.getPart(0); assertEquals(expected, result); @@ -58,7 +58,7 @@ class URLTargetTest { @Test void fullTarget() { - URLTarget target = new URLTarget("/example/target"); + URIPath target = new URIPath("/example/target"); String expected = "/example/target"; String result = target.asString(); assertEquals(expected, result); @@ -66,7 +66,7 @@ class URLTargetTest { @Test void secondPart() { - URLTarget target = new URLTarget("/example/target"); + URIPath target = new URIPath("/example/target"); Optional expected = Optional.of("target"); Optional result = target.getPart(1); assertEquals(expected, result); @@ -74,7 +74,7 @@ class URLTargetTest { @Test void noPart() { - URLTarget target = new URLTarget("/example/target"); + URIPath target = new URIPath("/example/target"); Optional expected = Optional.empty(); Optional result = target.getPart(2); assertEquals(expected, result); @@ -82,7 +82,7 @@ class URLTargetTest { @Test void emptyLastPart() { - URLTarget target = new URLTarget("/example/target/"); + URIPath target = new URIPath("/example/target/"); Optional expected = Optional.of(""); Optional result = target.getPart(2); assertEquals(expected, result); @@ -90,7 +90,7 @@ class URLTargetTest { @Test void omitRoot() { - URLTarget target = new URLTarget("/").omitFirst(); + URIPath target = new URIPath("/").omitFirst(); String expected = ""; String result = target.asString(); assertEquals(expected, result); @@ -98,7 +98,7 @@ class URLTargetTest { @Test void omitRootPart() { - URLTarget target = new URLTarget("/").omitFirst(); + URIPath target = new URIPath("/").omitFirst(); Optional expected = Optional.empty(); Optional result = target.getPart(0); assertEquals(expected, result); @@ -106,7 +106,7 @@ class URLTargetTest { @Test void omitFirstPart() { - URLTarget target = new URLTarget("/example/target").omitFirst(); + URIPath target = new URIPath("/example/target").omitFirst(); Optional expected = Optional.of("target"); Optional result = target.getPart(0); assertEquals(expected, result); @@ -114,7 +114,7 @@ class URLTargetTest { @Test void omitFirstFullTarget() { - URLTarget target = new URLTarget("/example/target").omitFirst(); + URIPath target = new URIPath("/example/target").omitFirst(); String expected = "/target"; String result = target.asString(); assertEquals(expected, result); @@ -124,7 +124,7 @@ class URLTargetTest { void partsAreRemoved() { String test = "/example/target"; String expected = "/target"; - String result = URLTarget.removePartsBefore(test, 1); + String result = URIPath.removePartsBefore(test, 1); assertEquals(expected, result); } @@ -132,7 +132,7 @@ class URLTargetTest { void partsAreRemoved2() { String test = "/example/target/"; String expected = "/"; - String result = URLTarget.removePartsBefore(test, 2); + String result = URIPath.removePartsBefore(test, 2); assertEquals(expected, result); } @@ -140,7 +140,7 @@ class URLTargetTest { void partsAreRemoved3() { String test = "/example/target"; String expected = ""; - String result = URLTarget.removePartsBefore(test, 2); + String result = URIPath.removePartsBefore(test, 2); assertEquals(expected, result); } @@ -148,7 +148,7 @@ class URLTargetTest { void partsAreRemoved4() { String test = "/example/target"; String expected = "/example/target"; - String result = URLTarget.removePartsBefore(test, 0); + String result = URIPath.removePartsBefore(test, 0); assertEquals(expected, result); } @@ -156,7 +156,7 @@ class URLTargetTest { void partsAreRemoved5() { String test = "/example/target/"; String expected = "/"; - String result = URLTarget.removePartsBefore(test, 2); + String result = URIPath.removePartsBefore(test, 2); assertEquals(expected, result); } @@ -164,7 +164,7 @@ class URLTargetTest { void noPartsToRemove() { String test = ""; String expected = ""; - String result = URLTarget.removePartsBefore(test, 1); + String result = URIPath.removePartsBefore(test, 1); assertEquals(expected, result); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java index 074e2ba64..a68990d9b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java @@ -20,6 +20,7 @@ import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.capability.CapabilitySvc; import com.djrapitops.plan.delivery.DeliveryUtilities; import com.djrapitops.plan.delivery.export.ExportSystem; +import com.djrapitops.plan.delivery.web.ResolverSvc; import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker; import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.WebServerSystem; @@ -77,6 +78,7 @@ public class PlanSystem implements SubSystem { private final ImportSystem importSystem; private final ExportSystem exportSystem; private final DeliveryUtilities deliveryUtilities; + private final ResolverSvc resolverService; private final ExtensionSvc extensionService; private final QuerySvc queryService; private final SettingsSvc settingsService; @@ -100,6 +102,7 @@ public class PlanSystem implements SubSystem { ImportSystem importSystem, ExportSystem exportSystem, DeliveryUtilities deliveryUtilities, + ResolverSvc resolverService, ExtensionSvc extensionService, QuerySvc queryService, SettingsSvc settingsService, @@ -122,6 +125,7 @@ public class PlanSystem implements SubSystem { this.importSystem = importSystem; this.exportSystem = exportSystem; this.deliveryUtilities = deliveryUtilities; + this.resolverService = resolverService; this.extensionService = extensionService; this.queryService = queryService; this.settingsService = settingsService; @@ -153,6 +157,11 @@ public class PlanSystem implements SubSystem { public void enable() throws EnableException { CapabilitySvc.initialize(); + extensionService.register(); + resolverService.register(); + settingsService.register(); + queryService.register(); + enableSystems( files, configSystem, @@ -176,9 +185,7 @@ public class PlanSystem implements SubSystem { )); } - settingsService.register(); - queryService.register(); - extensionService.register(); + extensionService.registerExtensions(); enabled = true; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/RegisterCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/RegisterCommand.java index efdb6c735..0cca45414 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/RegisterCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/RegisterCommand.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.commands.subcommands; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.processing.Processing; @@ -129,7 +129,7 @@ public class RegisterCommand extends CommandNode { Verify.isTrue(userName.length() <= 100, () -> new IllegalArgumentException("Username can only be 100 characters long.")); int permLevel = Integer.parseInt(args[2]); String passHash = PassEncryptUtil.createHash(args[0]); - registerUser(new WebUser(userName, passHash, permLevel), sender); + registerUser(new WebUser_old(userName, passHash, permLevel), sender); } private void playerRegister(String[] args, Sender sender) throws PassEncryptUtil.CannotPerformOperationException { @@ -138,7 +138,7 @@ public class RegisterCommand extends CommandNode { String user = sender.getName(); String pass = PassEncryptUtil.createHash(args[0]); int permLvl = getPermissionLevel(sender); - registerUser(new WebUser(user, pass, permLvl), sender); + registerUser(new WebUser_old(user, pass, permLvl), sender); } else if (sender.hasPermission(Permissions.MANAGE_WEB.getPermission())) { consoleRegister(args, sender, notEnoughArgsMsg); } else { @@ -162,7 +162,7 @@ public class RegisterCommand extends CommandNode { return 100; } - private void registerUser(WebUser webUser, Sender sender) { + private void registerUser(WebUser_old webUser, Sender sender) { processing.submitCritical(() -> { String userName = webUser.getName(); try { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebCheckCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebCheckCommand.java index 05144209e..439457589 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebCheckCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebCheckCommand.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.commands.subcommands.webuser; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.settings.Permissions; import com.djrapitops.plan.settings.locale.Locale; @@ -85,12 +85,12 @@ public class WebCheckCommand extends CommandNode { processing.submitNonCritical(() -> { try { Database db = dbSystem.getDatabase(); - Optional found = db.query(WebUserQueries.fetchWebUser(user)); + Optional found = db.query(WebUserQueries.fetchWebUser(user)); if (!found.isPresent()) { sender.sendMessage(locale.getString(CommandLang.FAIL_WEB_USER_NOT_EXISTS)); return; } - WebUser info = found.get(); + WebUser_old info = found.get(); sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, info.getName(), info.getPermLevel())); } catch (Exception e) { errorHandler.log(L.ERROR, this.getClass(), e); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebDeleteCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebDeleteCommand.java index 4c05fe30b..b611a6c69 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebDeleteCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebDeleteCommand.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.commands.subcommands.webuser; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.settings.Permissions; import com.djrapitops.plan.settings.locale.Locale; @@ -86,7 +86,7 @@ public class WebDeleteCommand extends CommandNode { processing.submitNonCritical(() -> { try { Database db = dbSystem.getDatabase(); - Optional found = db.query(WebUserQueries.fetchWebUser(user)); + Optional found = db.query(WebUserQueries.fetchWebUser(user)); if (!found.isPresent()) { sender.sendMessage("§c[Plan] User Doesn't exist."); return; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebListUsersCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebListUsersCommand.java index e4dbc368a..aadb9bf89 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebListUsersCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/webuser/WebListUsersCommand.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.commands.subcommands.webuser; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.processing.Processing; import com.djrapitops.plan.settings.Permissions; import com.djrapitops.plan.settings.locale.Locale; @@ -76,9 +76,9 @@ public class WebListUsersCommand extends CommandNode { processing.submitNonCritical(() -> { try { - List users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers()); + List users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers()); sender.sendMessage(locale.getString(CommandLang.HEADER_WEB_USERS, users.size())); - for (WebUser user : users) { + for (WebUser_old user : users) { sender.sendMessage(locale.getString(CommandLang.WEB_USER_LIST, user.getName(), user.getPermLevel())); } sender.sendMessage(">"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser_old.java similarity index 65% rename from Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser.java rename to Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser_old.java index 591e07e6d..6af423cda 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/WebUser_old.java @@ -16,6 +16,8 @@ */ package com.djrapitops.plan.delivery.domain; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; /** @@ -23,13 +25,14 @@ import java.util.Objects; * * @author Rsl1122 */ -public class WebUser { +@Deprecated +public class WebUser_old { private final String user; private final String saltedPassHash; private final int permLevel; - public WebUser(String user, String saltedPassHash, int permLevel) { + public WebUser_old(String user, String saltedPassHash, int permLevel) { this.user = user; this.saltedPassHash = saltedPassHash; this.permLevel = permLevel; @@ -51,7 +54,7 @@ public class WebUser { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - WebUser webUser = (WebUser) o; + WebUser_old webUser = (WebUser_old) o; return permLevel == webUser.permLevel && Objects.equals(user, webUser.user) && Objects.equals(saltedPassHash, webUser.saltedPassHash); @@ -61,4 +64,24 @@ public class WebUser { public int hashCode() { return Objects.hash(user, saltedPassHash, permLevel); } + + public com.djrapitops.plan.delivery.web.resolver.WebUser toNewWebUser() { + List permissions = new ArrayList<>(); + if (permLevel <= 0) { + permissions.add("page.network"); + permissions.add("page.server"); + permissions.add("page.debug"); + // TODO Add JSON Permissions + } + if (permLevel <= 1) { + permissions.add("page.players"); + permissions.add("page.player.other"); + } + if (permLevel <= 2) { + permissions.add("page.player.self"); + } + return new com.djrapitops.plan.delivery.web.resolver.WebUser( + user, permissions.toArray(new String[0]) + ); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java index 397bc5618..9b0d6af40 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/Exporter.java @@ -17,7 +17,6 @@ package com.djrapitops.plan.delivery.export; import com.djrapitops.plan.exceptions.ExportException; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.settings.config.PlanConfig; @@ -86,7 +85,7 @@ public class Exporter extends FileExporter { serverPageExporter.export(toDirectory, server); } return true; - } catch (IOException | NotFoundException | GenerationException e) { + } catch (IOException | NotFoundException e) { failedServers.add(serverUUID); throw new ExportException("Failed to export server: " + server.getIdentifiableName() + " (Attempts disabled until next reload), " + e.toString(), e); } @@ -125,7 +124,7 @@ public class Exporter extends FileExporter { try { playerPageExporter.export(toDirectory, playerUUID, playerName); return true; - } catch (IOException | NotFoundException | GenerationException e) { + } catch (IOException | NotFoundException e) { throw new ExportException("Failed to export player: " + playerName + ", " + e.toString(), e); } } @@ -137,7 +136,7 @@ public class Exporter extends FileExporter { try { playersPageExporter.export(toDirectory); return true; - } catch (IOException | NotFoundException | GenerationException e) { + } catch (IOException | NotFoundException e) { throw new ExportException("Failed to export players page, " + e.toString(), e); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java index d36b3cceb..330c14991 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java @@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page; import com.djrapitops.plan.delivery.rendering.pages.PageFactory; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.identification.Server; @@ -76,7 +75,7 @@ public class NetworkPageExporter extends FileExporter { exportPaths = new ExportPaths(); } - public void export(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException { + public void export(Path toDirectory, Server server) throws IOException, NotFoundException { Database.State dbState = dbSystem.getDatabase().getState(); if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return; @@ -87,7 +86,7 @@ public class NetworkPageExporter extends FileExporter { exportPaths.clear(); } - private void exportHtml(Path toDirectory) throws IOException, GenerationException { + private void exportHtml(Path toDirectory) throws IOException { Path to = toDirectory .resolve("network") .resolve("index.html"); @@ -122,7 +121,7 @@ public class NetworkPageExporter extends FileExporter { } private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException { - Response found = getJSONResponse(resource); + Response_old found = getJSONResponse(resource); if (found instanceof ErrorResponse) { throw new NotFoundException(resource + " was not properly exported: " + found.getContent()); } @@ -140,7 +139,7 @@ public class NetworkPageExporter extends FileExporter { return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""}); } - private Response getJSONResponse(String resource) { + private Response_old getJSONResponse(String resource) { try { return jsonHandler.resolve(null, new RequestTarget(URI.create(resource))); } catch (WebException e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java index 42dfd55fc..26b896f96 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java @@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page; import com.djrapitops.plan.delivery.rendering.pages.PageFactory; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.settings.locale.Locale; @@ -73,7 +72,7 @@ public class PlayerPageExporter extends FileExporter { this.theme = theme; } - public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException, GenerationException { + public void export(Path toDirectory, UUID playerUUID, String playerName) throws IOException, NotFoundException { Database.State dbState = dbSystem.getDatabase().getState(); if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return; if (!dbSystem.getDatabase().query(PlayerFetchQueries.isPlayerRegistered(playerUUID))) return; @@ -89,7 +88,7 @@ public class PlayerPageExporter extends FileExporter { exportPaths.clear(); } - private void exportHtml(ExportPaths exportPaths, Path playerDirectory, UUID playerUUID) throws IOException, GenerationException, NotFoundException { + private void exportHtml(ExportPaths exportPaths, Path playerDirectory, UUID playerUUID) throws IOException, NotFoundException { Path to = playerDirectory.resolve("index.html"); try { @@ -105,7 +104,7 @@ public class PlayerPageExporter extends FileExporter { } private void exportJSON(ExportPaths exportPaths, Path toDirectory, String resource, String playerName) throws NotFoundException, IOException { - Response found = getJSONResponse(resource); + Response_old found = getJSONResponse(resource); if (found instanceof ErrorResponse) { throw new NotFoundException(resource + " was not properly exported: " + found.getContent()); } @@ -120,7 +119,7 @@ public class PlayerPageExporter extends FileExporter { return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "player="}, new String[]{"-", "_", "", ""}); } - private Response getJSONResponse(String resource) { + private Response_old getJSONResponse(String resource) { try { return jsonHandler.resolve(null, new RequestTarget(URI.create(resource))); } catch (WebException e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java index 51f5e870d..74a24f932 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java @@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page; import com.djrapitops.plan.delivery.rendering.pages.PageFactory; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.identification.ServerInfo; @@ -79,7 +78,7 @@ public class PlayersPageExporter extends FileExporter { exportPaths = new ExportPaths(); } - public void export(Path toDirectory) throws IOException, NotFoundException, GenerationException { + public void export(Path toDirectory) throws IOException, NotFoundException { Database.State dbState = dbSystem.getDatabase().getState(); if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return; @@ -90,7 +89,7 @@ public class PlayersPageExporter extends FileExporter { exportPaths.clear(); } - private void exportHtml(Path toDirectory) throws IOException, GenerationException { + private void exportHtml(Path toDirectory) throws IOException { Path to = toDirectory .resolve("players") .resolve("index.html"); @@ -100,7 +99,7 @@ public class PlayersPageExporter extends FileExporter { } private void exportJSON(Path toDirectory) throws NotFoundException, IOException { - Response found = getJSONResponse("players"); + Response_old found = getJSONResponse("players"); if (found instanceof ErrorResponse) { throw new NotFoundException("players page was not properly exported: " + found.getContent()); } @@ -118,7 +117,7 @@ public class PlayersPageExporter extends FileExporter { return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""}); } - private Response getJSONResponse(String resource) { + private Response_old getJSONResponse(String resource) { try { return jsonHandler.resolve(null, new RequestTarget(URI.create(resource))); } catch (WebException e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ServerPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ServerPageExporter.java index b114aef03..16477b5b9 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ServerPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ServerPageExporter.java @@ -20,9 +20,8 @@ import com.djrapitops.plan.delivery.rendering.pages.Page; import com.djrapitops.plan.delivery.rendering.pages.PageFactory; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.errors.ErrorResponse; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.identification.Server; @@ -81,7 +80,7 @@ public class ServerPageExporter extends FileExporter { exportPaths = new ExportPaths(); } - public void export(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException { + public void export(Path toDirectory, Server server) throws IOException, NotFoundException { Database.State dbState = dbSystem.getDatabase().getState(); if (dbState == Database.State.CLOSED || dbState == Database.State.CLOSING) return; @@ -92,7 +91,7 @@ public class ServerPageExporter extends FileExporter { exportPaths.clear(); } - private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException, GenerationException { + private void exportHtml(Path toDirectory, Server server) throws IOException, NotFoundException { UUID serverUUID = server.getUuid(); Path to = toDirectory .resolve(serverInfo.getServer().isProxy() ? "server/" + toFileName(server.getName()) : "server") @@ -134,7 +133,7 @@ public class ServerPageExporter extends FileExporter { } private void exportJSON(Path toDirectory, String resource) throws NotFoundException, IOException { - Response found = getJSONResponse(resource); + Response_old found = getJSONResponse(resource); if (found instanceof ErrorResponse) { throw new NotFoundException(resource + " was not properly exported: " + found.getContent()); } @@ -152,7 +151,7 @@ public class ServerPageExporter extends FileExporter { return StringUtils.replaceEach(resource, new String[]{"?", "&", "type=", "server="}, new String[]{"-", "_", "", ""}); } - private Response getJSONResponse(String resource) { + private Response_old getJSONResponse(String resource) { try { return jsonHandler.resolve(null, new RequestTarget(URI.create(resource))); } catch (WebException e) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/DebugPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/DebugPage.java index 09c4e5788..6bd04384c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/DebugPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/DebugPage.java @@ -19,6 +19,8 @@ package com.djrapitops.plan.delivery.rendering.pages; import com.djrapitops.plan.delivery.domain.keys.SessionKeys; import com.djrapitops.plan.delivery.formatting.Formatter; import com.djrapitops.plan.delivery.formatting.Formatters; +import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; +import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.rendering.html.icon.Icon; import com.djrapitops.plan.delivery.rendering.html.structure.TabsElement; @@ -52,6 +54,7 @@ import java.util.*; */ public class DebugPage implements Page { + private final String template; private final Database database; private final ServerInfo serverInfo; private final VersionCheckSystem versionCheckSystem; @@ -62,6 +65,8 @@ public class DebugPage implements Page { private final Formatter yearFormatter; DebugPage( + String htmlTemplate, + Database database, ServerInfo serverInfo, Formatters formatters, @@ -70,6 +75,8 @@ public class DebugPage implements Page { Timings timings, ErrorHandler errorHandler ) { + this.template = htmlTemplate; + this.database = database; this.serverInfo = serverInfo; this.versionCheckSystem = versionCheckSystem; @@ -82,6 +89,17 @@ public class DebugPage implements Page { @Override public String toHtml() { + PlaceholderReplacer placeholders = new PlaceholderReplacer(); + placeholders.put("title", Icon.called("bug") + " Debug Information"); + placeholders.put("titleText", "Debug Information"); + placeholders.put("paragraph", createContent()); + placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); + placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); + placeholders.put("contributors", Contributors.generateContributorHtml()); + return placeholders.apply(template); + } + + private String createContent() { StringBuilder preContent = new StringBuilder(); String issueLink = Html.LINK_EXTERNAL.create("https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new", "Create new issue on Github"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/InternalErrorPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/InternalErrorPage.java new file mode 100644 index 000000000..1a2914465 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/InternalErrorPage.java @@ -0,0 +1,91 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.delivery.rendering.pages; + +import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; +import com.djrapitops.plan.delivery.rendering.html.Contributors; +import com.djrapitops.plan.delivery.rendering.html.Html; +import com.djrapitops.plan.delivery.rendering.html.icon.Icon; +import com.djrapitops.plan.version.VersionCheckSystem; + +/** + * Page to display error stacktrace. + * + * @author Rsl1122 + */ +public class InternalErrorPage implements Page { + + private final String template; + private final String errorMsg; + private final Throwable error; + + private final VersionCheckSystem versionCheckSystem; + + public InternalErrorPage( + String template, String errorMsg, Throwable error, + VersionCheckSystem versionCheckSystem + ) { + this.template = template; + this.errorMsg = errorMsg; + this.error = error; + this.versionCheckSystem = versionCheckSystem; + } + + @Override + public String toHtml() { + + PlaceholderReplacer placeholders = new PlaceholderReplacer(); + placeholders.put("title", Icon.called("bug") + " 500 Internal Error occurred"); + placeholders.put("titleText", "500 Internal Error occurred"); + placeholders.put("paragraph", createContent()); + placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); + placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); + placeholders.put("contributors", Contributors.generateContributorHtml()); + return placeholders.apply(template); + } + + private String createContent() { + StringBuilder paragraph = new StringBuilder(); + paragraph.append("Please report this issue here: "); + paragraph.append(Html.LINK.create("https://github.com/Rsl1122/Plan-PlayerAnalytics/issues", "Issues")); + paragraph.append("

");
+        paragraph.append(error).append(" | ").append(errorMsg);
+
+        for (StackTraceElement element : error.getStackTrace()) {
+            paragraph.append("
"); + paragraph.append(" ").append(element); + } + if (error.getCause() != null) { + appendCause(error.getCause(), paragraph); + } + + paragraph.append("
"); + + return paragraph.toString(); + } + + private void appendCause(Throwable cause, StringBuilder paragraph) { + paragraph.append("
Caused by: ").append(cause); + for (StackTraceElement element : cause.getStackTrace()) { + paragraph.append("
"); + paragraph.append(" ").append(element); + } + if (cause.getCause() != null) { + appendCause(cause.getCause(), paragraph); + } + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java index d94bb38be..2c83c5394 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/NetworkPage.java @@ -22,7 +22,6 @@ import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.extension.implementation.results.ExtensionData; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery; import com.djrapitops.plan.identification.ServerInfo; @@ -31,7 +30,6 @@ import com.djrapitops.plan.settings.config.paths.ProxySettings; import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.storage.database.DBSystem; -import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.version.VersionCheckSystem; import org.apache.commons.lang3.StringUtils; @@ -45,27 +43,28 @@ import java.util.UUID; */ public class NetworkPage implements Page { + private final String templateHtml; private final DBSystem dbSystem; private final VersionCheckSystem versionCheckSystem; - private final PlanFiles files; private final PlanConfig config; private final Theme theme; private final ServerInfo serverInfo; private final Formatters formatters; NetworkPage( + String templateHtml, + DBSystem dbSystem, VersionCheckSystem versionCheckSystem, - PlanFiles files, PlanConfig config, Theme theme, ServerInfo serverInfo, Formatters formatters ) { + this.templateHtml = templateHtml; this.dbSystem = dbSystem; this.versionCheckSystem = versionCheckSystem; - this.files = files; this.config = config; this.theme = theme; this.serverInfo = serverInfo; @@ -73,42 +72,38 @@ public class NetworkPage implements Page { } @Override - public String toHtml() throws GenerationException { - try { - PlaceholderReplacer placeholders = new PlaceholderReplacer(); + public String toHtml() { + PlaceholderReplacer placeholders = new PlaceholderReplacer(); - UUID serverUUID = serverInfo.getServerUUID(); - placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME)); - placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME)); - placeholders.put("serverUUID", serverUUID.toString()); + UUID serverUUID = serverInfo.getServerUUID(); + placeholders.put("networkDisplayName", config.get(ProxySettings.NETWORK_NAME)); + placeholders.put("serverName", config.get(ProxySettings.NETWORK_NAME)); + placeholders.put("serverUUID", serverUUID.toString()); - placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE)); - placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE)); - placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW)); - placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH)); - placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING)); - placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING)); - placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING)); - placeholders.put("timeZone", config.getTimeZoneOffsetHours()); + placeholders.put("gmPieColors", theme.getValue(ThemeVal.GRAPH_GM_PIE)); + placeholders.put("playersGraphColor", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE)); + placeholders.put("worldMapColLow", theme.getValue(ThemeVal.WORLD_MAP_LOW)); + placeholders.put("worldMapColHigh", theme.getValue(ThemeVal.WORLD_MAP_HIGH)); + placeholders.put("maxPingColor", theme.getValue(ThemeVal.GRAPH_MAX_PING)); + placeholders.put("minPingColor", theme.getValue(ThemeVal.GRAPH_MIN_PING)); + placeholders.put("avgPingColor", theme.getValue(ThemeVal.GRAPH_AVG_PING)); + placeholders.put("timeZone", config.getTimeZoneOffsetHours()); - placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); - placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); - placeholders.put("contributors", Contributors.generateContributorHtml()); + placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); + placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); + placeholders.put("contributors", Contributors.generateContributorHtml()); - CachingSupplier pluginTabs = new CachingSupplier<>(() -> { - List extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID)); - return new ServerPluginTabs(extensionData, formatters); - }); + CachingSupplier pluginTabs = new CachingSupplier<>(() -> { + List extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID)); + return new ServerPluginTabs(extensionData, formatters); + }); - String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); - String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); + String nav = JSONCache.getOrCacheString(DataID.EXTENSION_NAV, serverUUID, () -> pluginTabs.get().getNav()); + String tabs = JSONCache.getOrCacheString(DataID.EXTENSION_TABS, serverUUID, () -> pluginTabs.get().getTabs()); - placeholders.put("navPluginsTabs", nav); - placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}")); + placeholders.put("navPluginsTabs", nav); + placeholders.put("tabsPlugins", StringUtils.remove(tabs, "${backButton}")); - return placeholders.apply(files.getCustomizableResourceOrDefault("web/network.html").asString()); - } catch (Exception e) { - throw new GenerationException(e); - } + return placeholders.apply(templateHtml); } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/Page.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/Page.java index 9241a29c5..79b3d9b7b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/Page.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/Page.java @@ -16,14 +16,11 @@ */ package com.djrapitops.plan.delivery.rendering.pages; -import com.djrapitops.plan.exceptions.GenerationException; - /** * Interface for generating page HTML String. * * @author Rsl1122 */ public interface Page { - - String toHtml() throws GenerationException; + String toHtml(); } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java index 90b8e12a5..5822271a2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PageFactory.java @@ -38,6 +38,7 @@ import dagger.Lazy; import javax.inject.Inject; import javax.inject.Singleton; +import java.io.IOException; import java.util.*; /** @@ -49,7 +50,7 @@ import java.util.*; public class PageFactory { private final Lazy versionCheckSystem; - private final Lazy fileSystem; + private final Lazy files; private final Lazy config; private final Lazy theme; private final Lazy dbSystem; @@ -62,7 +63,7 @@ public class PageFactory { @Inject public PageFactory( Lazy versionCheckSystem, - Lazy fileSystem, + Lazy files, Lazy config, Lazy theme, Lazy dbSystem, @@ -73,7 +74,7 @@ public class PageFactory { Lazy errorHandler ) { this.versionCheckSystem = versionCheckSystem; - this.fileSystem = fileSystem; + this.files = files; this.config = config; this.theme = theme; this.dbSystem = dbSystem; @@ -84,38 +85,40 @@ public class PageFactory { this.errorHandler = errorHandler; } - public DebugPage debugPage() { + public DebugPage debugPage() throws IOException { return new DebugPage( + getResource("web/error.html"), dbSystem.get().getDatabase(), serverInfo.get(), formatters.get(), versionCheckSystem.get(), debugLogger.get(), timings.get(), errorHandler.get() ); } - public PlayersPage playersPage() { - return new PlayersPage(versionCheckSystem.get(), fileSystem.get(), config.get(), serverInfo.get()); + public PlayersPage playersPage() throws IOException { + return new PlayersPage(getResource("web/players.html"), versionCheckSystem.get(), config.get(), serverInfo.get()); } - public ServerPage serverPage(UUID serverUUID) throws NotFoundException { - return dbSystem.get().getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)) - .map(server -> new ServerPage( - server, - config.get(), - theme.get(), - versionCheckSystem.get(), - fileSystem.get(), - dbSystem.get(), - serverInfo.get(), - formatters.get() - )).orElseThrow(() -> new NotFoundException("Server not found in the database")); + public ServerPage serverPage(UUID serverUUID) throws NotFoundException, IOException { + Server server = dbSystem.get().getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)) + .orElseThrow(() -> new NotFoundException("Server not found in the database")); + return new ServerPage( + getResource("web/server.html"), + server, + config.get(), + theme.get(), + versionCheckSystem.get(), + dbSystem.get(), + serverInfo.get(), + formatters.get() + ); } - public PlayerPage playerPage(UUID playerUUID) { + public PlayerPage playerPage(UUID playerUUID) throws IOException { Database db = dbSystem.get().getDatabase(); PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(playerUUID)); return new PlayerPage( - player, + getResource("web/player.html"), player, versionCheckSystem.get(), - fileSystem.get(), config.get(), this, theme.get(), + config.get(), this, theme.get(), formatters.get(), serverInfo.get() ); } @@ -153,8 +156,25 @@ public class PageFactory { return new PlayerPluginTab(navs.toString(), tabs.toString()); } - public NetworkPage networkPage() { - return new NetworkPage(dbSystem.get(), - versionCheckSystem.get(), fileSystem.get(), config.get(), theme.get(), serverInfo.get(), formatters.get()); + public NetworkPage networkPage() throws IOException { + return new NetworkPage(getResource("web/network.html"), + dbSystem.get(), + versionCheckSystem.get(), config.get(), theme.get(), serverInfo.get(), formatters.get()); + } + + public Page internalErrorPage(String message, Throwable error) { + try { + return new InternalErrorPage( + getResource("web/error.html"), message, error, + versionCheckSystem.get()); + } catch (IOException noParse) { + return () -> "Error occurred: " + error.toString() + + ", additional error occurred when attempting to render error page to user: " + + noParse.toString(); + } + } + + public String getResource(String name) throws IOException { + return files.get().getCustomizableResourceOrDefault(name).asString(); } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayerPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayerPage.java index ea5930269..ba127bb7e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayerPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayerPage.java @@ -23,15 +23,12 @@ import com.djrapitops.plan.delivery.formatting.Formatters; import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.rendering.html.Html; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.ThemeVal; -import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.version.VersionCheckSystem; -import java.io.IOException; import java.util.UUID; /** @@ -41,11 +38,11 @@ import java.util.UUID; */ public class PlayerPage implements Page { + private final String templateHtml; private final PlayerContainer player; private final VersionCheckSystem versionCheckSystem; - private final PlanFiles files; private final PlanConfig config; private final PageFactory pageFactory; private final Theme theme; @@ -55,18 +52,18 @@ public class PlayerPage implements Page { private final Formatter secondLongFormatter; PlayerPage( + String templateHtml, PlayerContainer player, VersionCheckSystem versionCheckSystem, - PlanFiles files, PlanConfig config, PageFactory pageFactory, Theme theme, Formatters formatters, ServerInfo serverInfo ) { + this.templateHtml = templateHtml; this.player = player; this.versionCheckSystem = versionCheckSystem; - this.files = files; this.config = config; this.pageFactory = pageFactory; this.theme = theme; @@ -77,18 +74,14 @@ public class PlayerPage implements Page { } @Override - public String toHtml() throws GenerationException { + public String toHtml() { if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) { throw new IllegalStateException("Player is not registered"); } - try { - return createFor(player); - } catch (Exception e) { - throw new GenerationException(e); - } + return createFor(player); } - public String createFor(PlayerContainer player) throws IOException { + public String createFor(PlayerContainer player) { long now = System.currentTimeMillis(); UUID playerUUID = player.getUnsafe(PlayerKeys.UUID); @@ -116,6 +109,6 @@ public class PlayerPage implements Page { placeholders.put("navPluginsTabs", pluginTabs.getNav()); placeholders.put("pluginsTabs", pluginTabs.getTab()); - return placeholders.apply(files.getCustomizableResourceOrDefault("web/player.html").asString()); + return placeholders.apply(templateHtml); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayersPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayersPage.java index 13d041a5a..754ca076f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayersPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/PlayersPage.java @@ -18,12 +18,10 @@ package com.djrapitops.plan.delivery.rendering.pages; import com.djrapitops.plan.delivery.formatting.PlaceholderReplacer; import com.djrapitops.plan.delivery.rendering.html.Contributors; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.identification.ServerInfo; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.PluginSettings; import com.djrapitops.plan.settings.config.paths.ProxySettings; -import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.version.VersionCheckSystem; /** @@ -33,40 +31,36 @@ import com.djrapitops.plan.version.VersionCheckSystem; */ public class PlayersPage implements Page { + private final String templateHtml; private final VersionCheckSystem versionCheckSystem; - private final PlanFiles files; private final PlanConfig config; private final ServerInfo serverInfo; PlayersPage( + String templateHtml, VersionCheckSystem versionCheckSystem, - PlanFiles files, PlanConfig config, ServerInfo serverInfo ) { + this.templateHtml = templateHtml; this.versionCheckSystem = versionCheckSystem; - this.files = files; this.config = config; this.serverInfo = serverInfo; } @Override - public String toHtml() throws GenerationException { - try { - PlaceholderReplacer placeholders = new PlaceholderReplacer(); + public String toHtml() { + PlaceholderReplacer placeholders = new PlaceholderReplacer(); - placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); - placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); - placeholders.put("contributors", Contributors.generateContributorHtml()); - if (serverInfo.getServer().isProxy()) { - placeholders.put("networkName", config.get(ProxySettings.NETWORK_NAME)); - } else { - placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME)); - } - - return placeholders.apply(files.getCustomizableResourceOrDefault("web/players.html").asString()); - } catch (Exception e) { - throw new GenerationException(e); + placeholders.put("version", versionCheckSystem.getUpdateButton().orElse(versionCheckSystem.getCurrentVersionButton())); + placeholders.put("updateModal", versionCheckSystem.getUpdateModal()); + placeholders.put("contributors", Contributors.generateContributorHtml()); + if (serverInfo.getServer().isProxy()) { + placeholders.put("networkName", config.get(ProxySettings.NETWORK_NAME)); + } else { + placeholders.put("networkName", config.get(PluginSettings.SERVER_NAME)); } + + return placeholders.apply(templateHtml); } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java index e48cfeaa2..65d4dcebd 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/pages/ServerPage.java @@ -26,7 +26,6 @@ import com.djrapitops.plan.delivery.rendering.html.Contributors; import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.extension.implementation.results.ExtensionData; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery; import com.djrapitops.plan.identification.Server; @@ -36,10 +35,8 @@ import com.djrapitops.plan.settings.config.paths.DisplaySettings; import com.djrapitops.plan.settings.theme.Theme; import com.djrapitops.plan.settings.theme.ThemeVal; import com.djrapitops.plan.storage.database.DBSystem; -import com.djrapitops.plan.storage.file.PlanFiles; import com.djrapitops.plan.version.VersionCheckSystem; -import java.io.IOException; import java.util.List; import java.util.UUID; @@ -52,37 +49,36 @@ import static com.djrapitops.plan.delivery.domain.keys.AnalysisKeys.*; */ public class ServerPage implements Page { + private final String templateHtml; private final Server server; private final PlanConfig config; private final Theme theme; private final VersionCheckSystem versionCheckSystem; - private final PlanFiles files; private final DBSystem dbSystem; private final ServerInfo serverInfo; private final Formatters formatters; ServerPage( - Server server, + String templateHtml, Server server, PlanConfig config, Theme theme, VersionCheckSystem versionCheckSystem, - PlanFiles files, DBSystem dbSystem, ServerInfo serverInfo, Formatters formatters ) { + this.templateHtml = templateHtml; this.server = server; this.config = config; this.theme = theme; this.versionCheckSystem = versionCheckSystem; - this.files = files; this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.formatters = formatters; } @Override - public String toHtml() throws GenerationException { + public String toHtml() { PlaceholderReplacer placeholders = new PlaceholderReplacer(); UUID serverUUID = server.getUuid(); @@ -139,10 +135,6 @@ public class ServerPage implements Page { placeholders.put("navPluginsTabs", nav); placeholders.put("tabsPlugins", tabs); - try { - return placeholders.apply(files.getCustomizableResourceOrDefault("web/server.html").asString()); - } catch (IOException e) { - throw new GenerationException(e); - } + return placeholders.apply(templateHtml); } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/ResolverSvc.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/ResolverSvc.java new file mode 100644 index 000000000..476def004 --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/web/ResolverSvc.java @@ -0,0 +1,92 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.delivery.web; + +import com.djrapitops.plan.delivery.web.resolver.Resolver; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; +import java.util.function.Predicate; +import java.util.regex.Pattern; + +/** + * ResolverService Implementation. + * + * @author Rsl1122 + */ +@Singleton +public class ResolverSvc implements ResolverService { + + private final Collection basicResolvers; + private final Collection regexResolvers; + + @Inject + public ResolverSvc() { + basicResolvers = new ArrayList<>(); + regexResolvers = new ArrayList<>(); + } + + public void register() { + ResolverService.Holder.set(this); + } + + @Override + public void registerResolver(String pluginName, String start, Resolver resolver) { + basicResolvers.add(new Container(pluginName, checking -> checking.startsWith(start), resolver)); + } + + @Override + public void registerResolverForMatches(String pluginName, Pattern pattern, Resolver resolver) { + regexResolvers.add(new Container(pluginName, pattern.asPredicate(), resolver)); + } + + @Override + public Optional getResolver(String target) { + for (Container container : basicResolvers) { + if (container.matcher.test(target)) return Optional.of(container.resolver); + } + for (Container container : regexResolvers) { + if (container.matcher.test(target)) return Optional.of(container.resolver); + } + return Optional.empty(); + } + + public Optional getPluginInChargeOf(String target) { + for (Container container : basicResolvers) { + if (container.matcher.test(target)) return Optional.of(container.plugin); + } + for (Container container : regexResolvers) { + if (container.matcher.test(target)) return Optional.of(container.plugin); + } + return Optional.empty(); + } + + private static class Container { + final String plugin; + final Predicate matcher; + final Resolver resolver; + + public Container(String plugin, Predicate matcher, Resolver resolver) { + this.plugin = plugin; + this.matcher = matcher; + this.resolver = resolver; + } + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/Request.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/Request.java index 2d8b22eaa..b1011e10c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/Request.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/Request.java @@ -16,6 +16,8 @@ */ package com.djrapitops.plan.delivery.webserver; +import com.djrapitops.plan.delivery.web.resolver.URIPath; +import com.djrapitops.plan.delivery.web.resolver.URIQuery; import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.settings.locale.Locale; import com.sun.net.httpserver.HttpExchange; @@ -68,8 +70,12 @@ public class Request { return requestURI.getPath() + '?' + requestURI.getQuery(); } - public RequestTarget getTarget() { - return new RequestTarget(requestURI); + public URIPath getPath() { + return new URIPath(requestURI.getPath()); + } + + public URIQuery getQuery() { + return new URIQuery(requestURI.getQuery()); } public InputStream getRequestBody() { @@ -88,4 +94,9 @@ public class Request { public Locale getLocale() { return locale; } + + @Deprecated + public RequestTarget getRequestTarget() { + return new RequestTarget(requestURI); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java index fb453655f..334fd6c81 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestHandler.java @@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver; import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.auth.BasicAuthentication; import com.djrapitops.plan.delivery.webserver.response.PromptAuthorizationResponse; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.errors.ForbiddenResponse; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.PluginSettings; @@ -96,11 +96,11 @@ public class RequestHandler implements HttpHandler { request.setAuth(getAuthorization(requestHeaders)); try { - Response response = shouldPreventRequest(request.getRemoteAddress()) // Forbidden response (Optional) + Response_old response = shouldPreventRequest(request.getRemoteAddress()) // Forbidden response (Optional) .orElseGet(() -> responseResolver.getResponse(request)); // Or the actual requested response // Increase attempt count and block if too high - Optional forbid = handlePasswordBruteForceAttempts(request, response); + Optional forbid = handlePasswordBruteForceAttempts(request, response); if (forbid.isPresent()) { response = forbid.get(); } @@ -124,7 +124,7 @@ public class RequestHandler implements HttpHandler { } } - private Optional shouldPreventRequest(String accessor) { + private Optional shouldPreventRequest(String accessor) { Integer attempts = failedLoginAttempts.getIfPresent(accessor); if (attempts == null) { attempts = 0; @@ -137,7 +137,7 @@ public class RequestHandler implements HttpHandler { return Optional.empty(); } - private Optional handlePasswordBruteForceAttempts(Request request, Response response) { + private Optional handlePasswordBruteForceAttempts(Request request, Response_old response) { if (request.getAuth().isPresent() && response instanceof PromptAuthorizationResponse) { // Authentication was attempted, but failed so new attempt is going to be given if not forbidden @@ -166,7 +166,7 @@ public class RequestHandler implements HttpHandler { return Optional.empty(); } - private Optional createForbiddenResponse() { + private Optional createForbiddenResponse() { return Optional.of(responseFactory.forbidden403("You have too many failed login attempts. Please wait 2 minutes until attempting again.")); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestTarget.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestTarget.java index f1c25c7ef..78f5004e1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestTarget.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/RequestTarget.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; * * @author Rsl1122 */ +@Deprecated public class RequestTarget { private final String resourceString; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java index 494263e6a..32c08cc44 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/ResponseResolver.java @@ -16,12 +16,17 @@ */ package com.djrapitops.plan.delivery.webserver; +import com.djrapitops.plan.delivery.web.ResolverService; +import com.djrapitops.plan.delivery.web.ResolverSvc; +import com.djrapitops.plan.delivery.web.resolver.Resolver; +import com.djrapitops.plan.delivery.web.resolver.URIPath; +import com.djrapitops.plan.delivery.web.resolver.URIQuery; import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.pages.*; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; import com.djrapitops.plan.delivery.webserver.response.OptionsResponse; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.BadRequestException; import com.djrapitops.plan.exceptions.connection.ForbiddenException; @@ -55,10 +60,12 @@ public class ResponseResolver extends CompositePageResolver { private final ErrorHandler errorHandler; private final ServerInfo serverInfo; + private final ResolverService resolverService; private final Lazy webServer; @Inject public ResponseResolver( + ResolverSvc resolverService, ResponseFactory responseFactory, Lazy webServer, ServerInfo serverInfo, @@ -72,6 +79,7 @@ public class ResponseResolver extends CompositePageResolver { ErrorHandler errorHandler ) { super(responseFactory); + this.resolverService = resolverService; this.webServer = webServer; this.serverInfo = serverInfo; this.debugPageResolver = debugPageResolver; @@ -83,19 +91,20 @@ public class ResponseResolver extends CompositePageResolver { } public void registerPages() { - registerPage("debug", debugPageResolver); + resolverService.registerResolver("Plan", "/debug", debugPageResolver); registerPage("players", playersPageResolver); registerPage("player", playerPageResolver); registerPage("network", serverPageResolver); registerPage("server", serverPageResolver); + // TODO Figure out how to deal with stuff like this registerPage("", new RootPageResolver(responseFactory, webServer.get(), serverInfo)); registerPage("v1", rootJSONResolver); } - public Response getResponse(Request request) { + public Response_old getResponse(Request request) { try { return tryToGetResponse(request); } catch (NotFoundException e) { @@ -112,15 +121,47 @@ public class ResponseResolver extends CompositePageResolver { } } - private Response tryToGetResponse(Request request) throws WebException { - Optional authentication = request.getAuth(); - RequestTarget target = request.getTarget(); - String resource = target.getResourceString(); - + private Response_old tryToGetResponse(Request request) throws WebException { if ("OPTIONS".equalsIgnoreCase(request.getRequestMethod())) { return new OptionsResponse(); } + Optional authentication = request.getAuth(); + + URIPath target = request.getPath(); + URIQuery query = request.getQuery(); + + Optional foundResolver = resolverService.getResolver(target.asString()); + if (!foundResolver.isPresent()) return tryToGetResponse_old(request); // TODO Replace with 404 after refactoring + + Resolver resolver = foundResolver.get(); + + if (resolver.requiresAuth(target, query)) { + // Get required auth + boolean isAuthRequired = webServer.get().isAuthRequired(); + if (isAuthRequired && !authentication.isPresent()) { + if (webServer.get().isUsingHTTPS()) { + return responseFactory.basicAuth(); + } else { + return responseFactory.forbidden403(); + } + } + + if (!isAuthRequired || resolver.canAccess(authentication.get().getWebUser().toNewWebUser(), target, query)) { + return resolver.resolve(target, query).map(Response_old::from).orElseGet(responseFactory::pageNotFound404); + } else { + return responseFactory.forbidden403(); + } + } else { + return resolver.resolve(target, query).map(Response_old::from).orElseGet(responseFactory::pageNotFound404); + } + } + + private Response_old tryToGetResponse_old(Request request) throws WebException { + RequestTarget target = request.getRequestTarget(); + Optional authentication = request.getAuth(); + String resource = target.getResourceString(); + // TODO Turn into resolvers if (target.endsWith(".css")) { return responseFactory.cssResponse(resource); } @@ -136,7 +177,6 @@ public class ResponseResolver extends CompositePageResolver { if (target.endsWithAny(".woff", ".woff2", ".eot", ".ttf")) { return responseFactory.fontResponse(resource); } - boolean isAuthRequired = webServer.get().isAuthRequired(); if (isAuthRequired && !authentication.isPresent()) { if (webServer.get().isUsingHTTPS()) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/Authentication.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/Authentication.java index 3912fcddf..3914f25ad 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/Authentication.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/Authentication.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.delivery.webserver.auth; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.exceptions.WebUserAuthException; /** @@ -26,6 +26,6 @@ import com.djrapitops.plan.exceptions.WebUserAuthException; */ public interface Authentication { - WebUser getWebUser() throws WebUserAuthException; + WebUser_old getWebUser() throws WebUserAuthException; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/BasicAuthentication.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/BasicAuthentication.java index 0a1797868..f768536b2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/BasicAuthentication.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/auth/BasicAuthentication.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.delivery.webserver.auth; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.exceptions.PassEncryptException; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.database.DBOpException; @@ -45,7 +45,7 @@ public class BasicAuthentication implements Authentication { } @Override - public WebUser getWebUser() throws WebUserAuthException { + public WebUser_old getWebUser() throws WebUserAuthException { String decoded = Base64Util.decode(authenticationString); String[] userInfo = StringUtils.split(decoded, ':'); @@ -62,7 +62,7 @@ public class BasicAuthentication implements Authentication { } try { - WebUser webUser = database.query(WebUserQueries.fetchWebUser(user)) + WebUser_old webUser = database.query(WebUserQueries.fetchWebUser(user)) .orElseThrow(() -> new WebUserAuthException(FailReason.USER_DOES_NOT_EXIST, user)); boolean correctPass = PassEncryptUtil.verifyPassword(passwordRaw, webUser.getSaltedPassHash()); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/cache/JSONCache.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/cache/JSONCache.java index f07cfcd29..75d1834cd 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/cache/JSONCache.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/cache/JSONCache.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.delivery.webserver.cache; import com.djrapitops.plan.delivery.webserver.pages.json.RootJSONResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.storage.file.ResourceCache; import com.djrapitops.plugin.task.AbsRunnable; @@ -47,7 +47,7 @@ public class JSONCache { // Static class } - public static Response getOrCache(String identifier, Supplier jsonResponseSupplier) { + public static Response_old getOrCache(String identifier, Supplier jsonResponseSupplier) { String found = cache.getIfPresent(identifier); if (found == null) { JSONResponse response = jsonResponseSupplier.get(); @@ -68,11 +68,11 @@ public class JSONCache { return found; } - public static Response getOrCache(DataID dataID, Supplier jsonResponseSupplier) { + public static Response_old getOrCache(DataID dataID, Supplier jsonResponseSupplier) { return getOrCache(dataID.name(), jsonResponseSupplier); } - public static Response getOrCache(DataID dataID, UUID serverUUID, Supplier jsonResponseSupplier) { + public static Response_old getOrCache(DataID dataID, UUID serverUUID, Supplier jsonResponseSupplier) { return getOrCache(dataID.of(serverUUID), jsonResponseSupplier); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/CompositePageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/CompositePageResolver.java index 13c47cc22..743524f9a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/CompositePageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/CompositePageResolver.java @@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver.pages; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -37,6 +37,7 @@ import java.util.Map; * * @author Rsl1122 */ +@Deprecated public abstract class CompositePageResolver implements PageResolver { protected final ResponseFactory responseFactory; @@ -48,14 +49,16 @@ public abstract class CompositePageResolver implements PageResolver { pages = new HashMap<>(); } + @Deprecated public void registerPage(String targetPage, PageResolver resolver) { pages.put(targetPage, resolver); } + @Deprecated public void registerPage(String targetPage, PageResolver resolver, int requiredPerm) { pages.put(targetPage, new PageResolver() { @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { return resolver.resolve(request, target); } @@ -66,10 +69,11 @@ public abstract class CompositePageResolver implements PageResolver { }); } - public void registerPage(String targetPage, Response response, int requiredPerm) { + @Deprecated + public void registerPage(String targetPage, Response_old response, int requiredPerm) { pages.put(targetPage, new PageResolver() { @Override - public Response resolve(Request request, RequestTarget target) { + public Response_old resolve(Request request, RequestTarget target) { return response; } @@ -81,13 +85,15 @@ public abstract class CompositePageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + @Deprecated + public Response_old resolve(Request request, RequestTarget target) throws WebException { PageResolver pageResolver = getPageResolver(target); return pageResolver != null ? pageResolver.resolve(request, target) : responseFactory.pageNotFound404(); } + @Deprecated public PageResolver getPageResolver(RequestTarget target) { if (target.isEmpty()) { return pages.get(""); @@ -97,6 +103,7 @@ public abstract class CompositePageResolver implements PageResolver { return pages.get(targetPage); } + @Deprecated public PageResolver getPageResolver(String targetPage) { return pages.get(targetPage); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/DebugPageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/DebugPageResolver.java index a99ea4ea7..9bf7cdf07 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/DebugPageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/DebugPageResolver.java @@ -16,16 +16,18 @@ */ package com.djrapitops.plan.delivery.webserver.pages; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; +import com.djrapitops.plan.delivery.web.resolver.*; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import javax.inject.Inject; import javax.inject.Singleton; +import java.util.Optional; /** * Resolves /debug URL. @@ -33,7 +35,7 @@ import javax.inject.Singleton; * @author Rsl1122 */ @Singleton -public class DebugPageResolver implements PageResolver { +public class DebugPageResolver implements PageResolver, Resolver { private final ResponseFactory responseFactory; @@ -43,13 +45,23 @@ public class DebugPageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) { - return responseFactory.debugPageResponse(); + public boolean canAccess(WebUser permissions, URIPath target, URIQuery query) { + return permissions.hasPermission("page.debug"); + } + + @Override + public Optional resolve(URIPath target, URIQuery query) { + return Optional.of(responseFactory.debugPageResponse()); + } + + @Override + public Response_old resolve(Request request, RequestTarget target) { + return responseFactory.debugPageResponse_old(); } @Override public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException { - WebUser webUser = auth.getWebUser(); + WebUser_old webUser = auth.getWebUser(); return webUser.getPermLevel() <= 0; } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PageResolver.java index 9fd06c90e..d5a38d13f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PageResolver.java @@ -19,7 +19,7 @@ package com.djrapitops.plan.delivery.webserver.pages; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -29,6 +29,7 @@ import com.djrapitops.plan.exceptions.connection.WebException; * @author Rsl1122 * @see CompositePageResolver for larger depth resolution than 1. */ +@Deprecated public interface PageResolver { /** @@ -38,7 +39,7 @@ public interface PageResolver { * @param target Rest of the target coordinates after this page has been solved. * @return Appropriate response. */ - Response resolve(Request request, RequestTarget target) throws WebException; + Response_old resolve(Request request, RequestTarget target) throws WebException; default boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException { return true; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayerPageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayerPageResolver.java index ae033ddba..92e5d4262 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayerPageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayerPageResolver.java @@ -16,12 +16,12 @@ */ package com.djrapitops.plan.delivery.webserver.pages; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.ForbiddenException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -57,7 +57,7 @@ public class PlayerPageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { if (target.isEmpty()) { return responseFactory.pageNotFound404(); } @@ -82,7 +82,7 @@ public class PlayerPageResolver implements PageResolver { @Override public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException { - WebUser webUser = auth.getWebUser(); + WebUser_old webUser = auth.getWebUser(); return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1)); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayersPageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayersPageResolver.java index 27b998c39..991b4e6fe 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayersPageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/PlayersPageResolver.java @@ -19,8 +19,8 @@ package com.djrapitops.plan.delivery.webserver.pages; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.ForbiddenException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -51,7 +51,7 @@ public class PlayersPageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { Database.State dbState = dbSystem.getDatabase().getState(); if (dbState != Database.State.OPEN) { throw new ForbiddenException("Database is " + dbState.name() + " - Please try again later. You can check database status with /plan info"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageResolver.java index 39271213b..5ea3ef4b6 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/RootPageResolver.java @@ -16,14 +16,14 @@ */ package com.djrapitops.plan.delivery.webserver.pages; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.rendering.html.Html; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.connection.WebException; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.ServerInfo; @@ -48,7 +48,7 @@ public class RootPageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { Server server = serverInfo.getServer(); if (!webServer.isAuthRequired()) { return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName())); @@ -59,7 +59,7 @@ public class RootPageResolver implements PageResolver { return responseFactory.basicAuth(); } - WebUser webUser = auth.get().getWebUser(); + WebUser_old webUser = auth.get().getWebUser(); int permLevel = webUser.getPermLevel(); switch (permLevel) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageResolver.java index acf348664..bfc35f75b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/ServerPageResolver.java @@ -21,8 +21,8 @@ import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.WebServer; import com.djrapitops.plan.delivery.webserver.auth.Authentication; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseFactory; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.ForbiddenException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -65,7 +65,7 @@ public class ServerPageResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { Optional serverUUID = getServerUUID(target); boolean proxy = serverInfo.getServer().isProxy(); if (serverUUID.isPresent()) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/GraphsJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/GraphsJSONResolver.java index be5d7c688..9892ddec3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/GraphsJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/GraphsJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.BadRequestException; @@ -56,7 +56,7 @@ public class GraphsJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { String type = target.getParameter("type") .orElseThrow(() -> new BadRequestException("'type' parameter was not defined.")); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/NetworkTabJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/NetworkTabJSONResolver.java index 1956f7f36..34604c801 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/NetworkTabJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/NetworkTabJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; @@ -45,7 +45,7 @@ public class NetworkTabJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) { + public Response_old resolve(Request request, RequestTarget target) { return JSONCache.getOrCache(dataID, () -> new JSONResponse(jsonCreator.get())); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerJSONResolver.java index a83462b1e..eb9248ea4 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerJSONResolver.java @@ -16,13 +16,13 @@ */ package com.djrapitops.plan.delivery.webserver.pages.json; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.rendering.json.PlayerJSONCreator; import com.djrapitops.plan.delivery.webserver.Request; import com.djrapitops.plan.delivery.webserver.RequestTarget; import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -45,14 +45,14 @@ public class PlayerJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { UUID playerUUID = identifiers.getPlayerUUID(target); // Can throw BadRequestException return new JSONResponse(jsonCreator.createJSONAsMap(playerUUID)); } @Override public boolean isAuthorized(Authentication auth, RequestTarget target) throws WebUserAuthException { - WebUser webUser = auth.getWebUser(); + WebUser_old webUser = auth.getWebUser(); return webUser.getPermLevel() <= 1 || webUser.getName().equalsIgnoreCase(target.get(target.size() - 1)); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerKillsJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerKillsJSONResolver.java index 912456a98..77fb3e7e0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerKillsJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayerKillsJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -55,7 +55,7 @@ public class PlayerKillsJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { UUID serverUUID = identifiers.getServerUUID(target); return JSONCache.getOrCache(DataID.KILLS, serverUUID, () -> new JSONResponse(Collections.singletonMap("player_kills", jsonFactory.serverPlayerKillsAsJSONMap(serverUUID))) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayersTableJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayersTableJSONResolver.java index bb74500c5..7142b0762 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayersTableJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/PlayersTableJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -54,7 +54,7 @@ public class PlayersTableJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { if (target.getParameter("server").isPresent()) { UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException return JSONCache.getOrCache(DataID.PLAYERS, serverUUID, () -> new JSONResponse(jsonFactory.serverPlayersTableJSON(serverUUID))); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/ServerTabJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/ServerTabJSONResolver.java index cac1458aa..7c8fd7ee0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/ServerTabJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/ServerTabJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -54,7 +54,7 @@ public class ServerTabJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { UUID serverUUID = identifiers.getServerUUID(target); // Can throw BadRequestException return JSONCache.getOrCache(dataID, serverUUID, () -> new JSONResponse(jsonCreator.apply(serverUUID))); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/SessionsJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/SessionsJSONResolver.java index b6dae4fbf..12cf02753 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/SessionsJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/pages/json/SessionsJSONResolver.java @@ -23,7 +23,7 @@ import com.djrapitops.plan.delivery.webserver.auth.Authentication; import com.djrapitops.plan.delivery.webserver.cache.DataID; import com.djrapitops.plan.delivery.webserver.cache.JSONCache; import com.djrapitops.plan.delivery.webserver.pages.PageResolver; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.delivery.webserver.response.data.JSONResponse; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.WebException; @@ -55,7 +55,7 @@ public class SessionsJSONResolver implements PageResolver { } @Override - public Response resolve(Request request, RequestTarget target) throws WebException { + public Response_old resolve(Request request, RequestTarget target) throws WebException { if (target.getParameter("server").isPresent()) { UUID serverUUID = identifiers.getServerUUID(target); return JSONCache.getOrCache(DataID.SESSIONS, serverUUID, () -> diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ByteResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ByteResponse.java index 3ca48c558..28d6f7119 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ByteResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ByteResponse.java @@ -26,11 +26,11 @@ import java.io.InputStream; import java.io.OutputStream; /** - * {@link Response} for raw bytes. + * {@link Response_old} for raw bytes. * * @author Rsl1122 */ -public class ByteResponse extends Response { +public class ByteResponse extends Response_old { private final PlanFiles files; private final String fileName; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/FileResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/FileResponse.java index 94a9202b3..eef72d07b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/FileResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/FileResponse.java @@ -29,7 +29,7 @@ import java.io.IOException; * * @author Rsl1122 */ -public class FileResponse extends Response { +public class FileResponse extends Response_old { public FileResponse(String fileName, PlanFiles files) throws IOException { super.setHeader("HTTP/1.1 200 OK"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/OptionsResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/OptionsResponse.java index f108fc6c2..b9b94f977 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/OptionsResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/OptionsResponse.java @@ -22,7 +22,7 @@ package com.djrapitops.plan.delivery.webserver.response; * * @author Rsl1122 */ -public class OptionsResponse extends Response { +public class OptionsResponse extends Response_old { public OptionsResponse() { setHeader("HTTP/1.1 204 No Content"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/RedirectResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/RedirectResponse.java index ea3a9d561..45b10d733 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/RedirectResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/RedirectResponse.java @@ -25,7 +25,7 @@ import java.io.IOException; /** * @author Rsl1122 */ -public class RedirectResponse extends Response { +public class RedirectResponse extends Response_old { private final String direct; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ResponseFactory.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ResponseFactory.java index da45a618d..2eb7938b0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ResponseFactory.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/ResponseFactory.java @@ -16,10 +16,12 @@ */ package com.djrapitops.plan.delivery.webserver.response; +import com.djrapitops.plan.delivery.rendering.pages.Page; import com.djrapitops.plan.delivery.rendering.pages.PageFactory; +import com.djrapitops.plan.delivery.web.resolver.MimeType; +import com.djrapitops.plan.delivery.web.resolver.Response; import com.djrapitops.plan.delivery.webserver.response.errors.*; import com.djrapitops.plan.delivery.webserver.response.pages.*; -import com.djrapitops.plan.exceptions.GenerationException; import com.djrapitops.plan.exceptions.WebUserAuthException; import com.djrapitops.plan.exceptions.connection.NotFoundException; import com.djrapitops.plan.settings.locale.Locale; @@ -35,7 +37,7 @@ import java.io.IOException; import java.util.UUID; /** - * Factory for creating different {@link Response} objects. + * Factory for creating different {@link Response_old} objects. * * @author Rsl1122 */ @@ -64,6 +66,28 @@ public class ResponseFactory { } public Response debugPageResponse() { + try { + return forPage(pageFactory.debugPage()); + } catch (IOException e) { + return forInternalError("Failed to generate debug page", e); + } + } + + public Response forPage(Page page) throws IOException { + return Response.builder().setContent(page.toHtml()) + .setMimeType(MimeType.HTML) + .build(); + } + + public Response forInternalError(String cause, Throwable error) { + return Response.builder().setContent(pageFactory.internalErrorPage(cause, error).toHtml()) + .setMimeType(MimeType.HTML) + .setStatus(500) + .build(); + } + + @Deprecated + public Response_old debugPageResponse_old() { try { return new DebugPageResponse(pageFactory.debugPage(), versionCheckSystem, files); } catch (IOException e) { @@ -71,10 +95,10 @@ public class ResponseFactory { } } - public Response playersPageResponse() { + public Response_old playersPageResponse() { try { return new PlayersPageResponse(pageFactory.playersPage()); - } catch (GenerationException e) { + } catch (IOException e) { return internalErrorResponse(e, "Failed to generate players page"); } } @@ -91,18 +115,18 @@ public class ResponseFactory { } } - public Response networkPageResponse() { + public Response_old networkPageResponse() { try { return new PageResponse(pageFactory.networkPage()); - } catch (GenerationException e) { + } catch (IOException e) { return internalErrorResponse(e, "Failed to generate network page"); } } - public Response serverPageResponse(UUID serverUUID) throws NotFoundException { + public Response_old serverPageResponse(UUID serverUUID) throws NotFoundException { try { return new PageResponse(pageFactory.serverPage(serverUUID)); - } catch (GenerationException e) { + } catch (IOException e) { return internalErrorResponse(e, "Failed to generate server page"); } } @@ -111,7 +135,7 @@ public class ResponseFactory { return new RawPlayerDataResponse(dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(uuid))); } - public Response javaScriptResponse(String fileName) { + public Response_old javaScriptResponse(String fileName) { try { return new JavaScriptResponse(fileName, files, locale); } catch (IOException e) { @@ -119,7 +143,7 @@ public class ResponseFactory { } } - public Response cssResponse(String fileName) { + public Response_old cssResponse(String fileName) { try { return new CSSResponse(fileName, files); } catch (IOException e) { @@ -127,11 +151,11 @@ public class ResponseFactory { } } - public Response imageResponse(String fileName) { + public Response_old imageResponse(String fileName) { return new ByteResponse(ResponseType.IMAGE, FileResponse.format(fileName), files); } - public Response fontResponse(String fileName) { + public Response_old fontResponse(String fileName) { ResponseType type = ResponseType.FONT_BYTESTREAM; if (fileName.endsWith(".woff")) { type = ResponseType.FONT_WOFF; @@ -151,11 +175,11 @@ public class ResponseFactory { * @param location Starts with '/' * @return Redirection response. */ - public Response redirectResponse(String location) { + public Response_old redirectResponse(String location) { return new RedirectResponse(location); } - public Response faviconResponse() { + public Response_old faviconResponse() { return new ByteResponse(ResponseType.X_ICON, "web/favicon.ico", files); } @@ -212,12 +236,12 @@ public class ResponseFactory { return new BadRequestResponse(errorMessage + " (when requesting '" + target + "')"); } - public Response playerPageResponse(UUID playerUUID) { + public Response_old playerPageResponse(UUID playerUUID) { try { return new PageResponse(pageFactory.playerPage(playerUUID)); } catch (IllegalStateException e) { return playerNotFound404(); - } catch (GenerationException e) { + } catch (IOException e) { return internalErrorResponse(e, "Failed to generate player page"); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response_old.java similarity index 83% rename from Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response.java rename to Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response_old.java index 1394ca43c..99251debf 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/Response_old.java @@ -25,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -33,7 +34,8 @@ import java.util.zip.GZIPOutputStream; /** * @author Rsl1122 */ -public abstract class Response { +@Deprecated +public abstract class Response_old { private String type; private String header; @@ -41,14 +43,14 @@ public abstract class Response { protected Headers responseHeaders; - public Response(ResponseType type) { + public Response_old(ResponseType type) { this.type = type.get(); } /** * Default Response constructor that defaults ResponseType to HTML. */ - public Response() { + public Response_old() { this(ResponseType.HTML); } @@ -94,13 +96,16 @@ public abstract class Response { return getHeader(null).map(h -> Integer.parseInt(StringUtils.split(h, ' ')[1])).orElse(500); } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Response response = (Response) o; - return Objects.equals(header, response.header) && - Objects.equals(content, response.content); + @Deprecated + public static Response_old from(com.djrapitops.plan.delivery.web.resolver.Response apiResponse) { + Response_old response = new Response_old() {}; + response.setContent(apiResponse.getCharset().map(charset -> new String(apiResponse.getBytes(), charset)) + .orElse(new String(apiResponse.getBytes()))); + response.setHeader("HTTP/1.1 " + apiResponse.getCode() + " "); + for (Map.Entry header : apiResponse.getHeaders().entrySet()) { + response.header += header.getKey() + ": " + header.getValue() + ";\r\n"; + } + return response; } @Override @@ -145,4 +150,13 @@ public abstract class Response { public String toString() { return header + " | " + getResponse(); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Response_old response = (Response_old) o; + return Objects.equals(header, response.header) && + Objects.equals(content, response.content); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/TextResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/TextResponse.java index f56558e49..1b5bfe80c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/TextResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/TextResponse.java @@ -21,7 +21,7 @@ package com.djrapitops.plan.delivery.webserver.response; * * @author Rsl1122 */ -public class TextResponse extends Response { +public class TextResponse extends Response_old { public TextResponse(String content) { setHeader("HTTP/1.1 200 OK"); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/data/JSONResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/data/JSONResponse.java index df754d95b..c855ed707 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/data/JSONResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/data/JSONResponse.java @@ -16,8 +16,8 @@ */ package com.djrapitops.plan.delivery.webserver.response.data; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseType; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.google.gson.Gson; import com.google.gson.JsonElement; @@ -28,7 +28,7 @@ import com.google.gson.JsonElement; * * @author Rsl1122 */ -public class JSONResponse extends Response { +public class JSONResponse extends Response_old { public JSONResponse(Object object) { this(new Gson().toJson(object)); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/errors/BadRequestResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/errors/BadRequestResponse.java index 2fbdfcb83..0ef06c70d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/errors/BadRequestResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/errors/BadRequestResponse.java @@ -16,12 +16,12 @@ */ package com.djrapitops.plan.delivery.webserver.response.errors; -import com.djrapitops.plan.delivery.webserver.response.Response; +import com.djrapitops.plan.delivery.webserver.response.Response_old; /** * @author Fuzzlemann */ -public class BadRequestResponse extends Response { +public class BadRequestResponse extends Response_old { public BadRequestResponse(String error) { super.setHeader("HTTP/1.1 400 Bad Request " + error); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PageResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PageResponse.java index e114f6d2d..d111efb76 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PageResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PageResponse.java @@ -17,9 +17,8 @@ package com.djrapitops.plan.delivery.webserver.response.pages; import com.djrapitops.plan.delivery.rendering.pages.Page; -import com.djrapitops.plan.delivery.webserver.response.Response; import com.djrapitops.plan.delivery.webserver.response.ResponseType; -import com.djrapitops.plan.exceptions.GenerationException; +import com.djrapitops.plan.delivery.webserver.response.Response_old; import com.djrapitops.plan.settings.locale.Locale; import com.djrapitops.plan.settings.theme.Theme; import com.googlecode.htmlcompressor.compressor.HtmlCompressor; @@ -32,7 +31,7 @@ import java.io.IOException; * * @author Rsl1122 */ -public class PageResponse extends Response { +public class PageResponse extends Response_old { private static final HtmlCompressor HTML_COMPRESSOR = new HtmlCompressor(); @@ -44,7 +43,7 @@ public class PageResponse extends Response { super(type); } - public PageResponse(Page page) throws GenerationException { + public PageResponse(Page page) { this(ResponseType.HTML); super.setHeader("HTTP/1.1 200 OK"); setContent(page.toHtml()); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PlayersPageResponse.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PlayersPageResponse.java index 00bc14bc1..e5cb3a4af 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PlayersPageResponse.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/response/pages/PlayersPageResponse.java @@ -17,14 +17,13 @@ package com.djrapitops.plan.delivery.webserver.response.pages; import com.djrapitops.plan.delivery.rendering.pages.PlayersPage; -import com.djrapitops.plan.exceptions.GenerationException; /** * @author Rsl1122 */ public class PlayersPageResponse extends PageResponse { - public PlayersPageResponse(PlayersPage playersPage) throws GenerationException { + public PlayersPageResponse(PlayersPage playersPage) { setHeader("HTTP/1.1 200 OK"); setContent(playersPage.toHtml()); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/GenerationException.java b/Plan/common/src/main/java/com/djrapitops/plan/exceptions/GenerationException.java deleted file mode 100644 index 5d808ced4..000000000 --- a/Plan/common/src/main/java/com/djrapitops/plan/exceptions/GenerationException.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of Player Analytics (Plan). - * - * Plan is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License v3 as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Plan is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Plan. If not, see . - */ -package com.djrapitops.plan.exceptions; - -/** - * Exception thrown when Page encounters an Exception. - * - * @author Rsl1122 - */ -public class GenerationException extends Exception { - - public GenerationException(Throwable cause) { - super(cause); - } -} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java index df28f6aec..9ce3c4943 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/ExtensionSvc.java @@ -78,11 +78,13 @@ public class ExtensionSvc implements ExtensionService { this.errorHandler = errorHandler; extensionGatherers = new HashMap<>(); - - Holder.set(this); } public void register() { + Holder.set(this); + } + + public void registerExtensions() { try { extensionRegister.registerBuiltInExtensions(config.getExtensionSettings().getDisabled()); } catch (IllegalStateException failedToRegisterOne) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/settings/SettingsSvc.java b/Plan/common/src/main/java/com/djrapitops/plan/settings/SettingsSvc.java index e10581552..f233cf4a6 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/settings/SettingsSvc.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/settings/SettingsSvc.java @@ -49,7 +49,7 @@ public class SettingsSvc implements SettingsService { } public void register() { - SettingsService.SettingsServiceHolder.set(this); + Holder.set(this); } @Override diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java index 2f12a8e09..3484e76b2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/LargeStoreQueries.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.storage.database.queries; import com.djrapitops.plan.delivery.domain.Nickname; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.domain.keys.SessionKeys; import com.djrapitops.plan.gathering.domain.*; import com.djrapitops.plan.identification.Server; @@ -119,7 +119,7 @@ public class LargeStoreQueries { * @param users Collection of Plan WebUsers. * @return Executable, use inside a {@link com.djrapitops.plan.storage.database.transactions.Transaction} */ - public static Executable storeAllPlanWebUsers(Collection users) { + public static Executable storeAllPlanWebUsers(Collection users) { if (Verify.isEmpty(users)) { return Executable.empty(); } @@ -127,7 +127,7 @@ public class LargeStoreQueries { return new ExecBatchStatement(SecurityTable.INSERT_STATEMENT) { @Override public void prepare(PreparedStatement statement) throws SQLException { - for (WebUser user : users) { + for (WebUser_old user : users) { String userName = user.getName(); String pass = user.getSaltedPassHash(); int permLvl = user.getPermLevel(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/PingQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/PingQueries.java index 4a301fc60..5a0146017 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/PingQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/PingQueries.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.storage.database.queries.objects; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.gathering.domain.Ping; import com.djrapitops.plan.storage.database.queries.Query; import com.djrapitops.plan.storage.database.queries.QueryAllStatement; @@ -33,7 +33,7 @@ import java.util.*; import static com.djrapitops.plan.storage.database.sql.building.Sql.*; /** - * Queries for {@link WebUser} objects. + * Queries for {@link WebUser_old} objects. * * @author Rsl1122 */ diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/WebUserQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/WebUserQueries.java index 085b77caa..601750e5e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/WebUserQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/objects/WebUserQueries.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.storage.database.queries.objects; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.storage.database.queries.Query; import com.djrapitops.plan.storage.database.queries.QueryAllStatement; import com.djrapitops.plan.storage.database.queries.QueryStatement; @@ -32,7 +32,7 @@ import java.util.Optional; import static com.djrapitops.plan.storage.database.sql.building.Sql.*; /** - * Queries for {@link WebUser} objects. + * Queries for {@link WebUser_old} objects. * * @author Rsl1122 */ @@ -47,18 +47,18 @@ public class WebUserQueries { * * @return List of Plan WebUsers. */ - public static Query> fetchAllPlanWebUsers() { + public static Query> fetchAllPlanWebUsers() { String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + ORDER_BY + SecurityTable.PERMISSION_LEVEL + " ASC"; - return new QueryAllStatement>(sql, 5000) { + return new QueryAllStatement>(sql, 5000) { @Override - public List processResults(ResultSet set) throws SQLException { - List list = new ArrayList<>(); + public List processResults(ResultSet set) throws SQLException { + List list = new ArrayList<>(); while (set.next()) { String user = set.getString(SecurityTable.USERNAME); String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH); int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL); - WebUser info = new WebUser(user, saltedPassHash, permissionLevel); + WebUser_old info = new WebUser_old(user, saltedPassHash, permissionLevel); list.add(info); } return list; @@ -66,21 +66,21 @@ public class WebUserQueries { }; } - public static Query> fetchWebUser(String called) { + public static Query> fetchWebUser(String called) { String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + WHERE + SecurityTable.USERNAME + "=? LIMIT 1"; - return new QueryStatement>(sql) { + return new QueryStatement>(sql) { @Override public void prepare(PreparedStatement statement) throws SQLException { statement.setString(1, called); } @Override - public Optional processResults(ResultSet set) throws SQLException { + public Optional processResults(ResultSet set) throws SQLException { if (set.next()) { String saltedPassHash = set.getString(SecurityTable.SALT_PASSWORD_HASH); int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL); - return Optional.of(new WebUser(called, saltedPassHash, permissionLevel)); + return Optional.of(new WebUser_old(called, saltedPassHash, permissionLevel)); } return Optional.empty(); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RegisterWebUserTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RegisterWebUserTransaction.java index 4dd004a37..6a762818d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RegisterWebUserTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RegisterWebUserTransaction.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.storage.database.transactions.commands; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.storage.database.sql.tables.SecurityTable; import com.djrapitops.plan.storage.database.transactions.ExecStatement; import com.djrapitops.plan.storage.database.transactions.Transaction; @@ -25,15 +25,15 @@ import java.sql.PreparedStatement; import java.sql.SQLException; /** - * Transaction to save a new Plan {@link WebUser} to the database. + * Transaction to save a new Plan {@link WebUser_old} to the database. * * @author Rsl1122 */ public class RegisterWebUserTransaction extends Transaction { - private final WebUser webUser; + private final WebUser_old webUser; - public RegisterWebUserTransaction(WebUser webUser) { + public RegisterWebUserTransaction(WebUser_old webUser) { this.webUser = webUser; } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveWebUserTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveWebUserTransaction.java index d2ee58f72..e5c984b3f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveWebUserTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/commands/RemoveWebUserTransaction.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.storage.database.transactions.commands; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.storage.database.sql.tables.SecurityTable; import com.djrapitops.plan.storage.database.transactions.ExecStatement; import com.djrapitops.plan.storage.database.transactions.Transaction; @@ -28,7 +28,7 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.DELETE_FROM; import static com.djrapitops.plan.storage.database.sql.building.Sql.WHERE; /** - * Transaction to remove a Plan {@link WebUser} from the database. + * Transaction to remove a Plan {@link WebUser_old} from the database. * * @author Rsl1122 */ diff --git a/Plan/common/src/main/java/com/djrapitops/plan/utilities/comparators/WebUserComparator.java b/Plan/common/src/main/java/com/djrapitops/plan/utilities/comparators/WebUserComparator.java index 856274b15..8d6e009d8 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/utilities/comparators/WebUserComparator.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/utilities/comparators/WebUserComparator.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.utilities.comparators; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import java.util.Comparator; @@ -25,10 +25,10 @@ import java.util.Comparator; * * @author Rsl1122 */ -public class WebUserComparator implements Comparator { +public class WebUserComparator implements Comparator { @Override - public int compare(WebUser o1, WebUser o2) { + public int compare(WebUser_old o1, WebUser_old o2) { return Integer.compare(o2.getPermLevel(), o1.getPermLevel()); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JksHttpsServerTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JksHttpsServerTest.java index b32398329..fc2eb2993 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JksHttpsServerTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/JksHttpsServerTest.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.delivery.webserver; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.paths.WebserverSettings; import com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction; @@ -61,7 +61,7 @@ class JksHttpsServerTest implements HttpsServerTest { system.enable(); - WebUser webUser = new WebUser("test", PassEncryptUtil.createHash("testPass"), 0); + WebUser_old webUser = new WebUser_old("test", PassEncryptUtil.createHash("testPass"), 0); system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser)); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/Pkcs12HttpsServerTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/Pkcs12HttpsServerTest.java index 3ec52abdb..2f935a3ac 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/Pkcs12HttpsServerTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/webserver/Pkcs12HttpsServerTest.java @@ -17,7 +17,7 @@ package com.djrapitops.plan.delivery.webserver; import com.djrapitops.plan.PlanSystem; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.settings.config.changes.ConfigUpdater; import com.djrapitops.plan.settings.config.paths.WebserverSettings; @@ -66,7 +66,7 @@ class Pkcs12HttpsServerTest implements HttpsServerTest { system.enable(); - WebUser webUser = new WebUser("test", PassEncryptUtil.createHash("testPass"), 0); + WebUser_old webUser = new WebUser_old("test", PassEncryptUtil.createHash("testPass"), 0); system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(webUser)); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java index 900b0cb4b..0fbb29415 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/storage/database/DatabaseTest.java @@ -21,7 +21,7 @@ import com.djrapitops.plan.data.element.TableContainer; import com.djrapitops.plan.delivery.domain.DateObj; import com.djrapitops.plan.delivery.domain.Nickname; import com.djrapitops.plan.delivery.domain.TablePlayer; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.domain.container.PlayerContainer; import com.djrapitops.plan.delivery.domain.container.ServerContainer; import com.djrapitops.plan.delivery.domain.keys.Key; @@ -208,11 +208,11 @@ public interface DatabaseTest { @Test default void webUserIsRegistered() { - WebUser expected = new WebUser(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0); + WebUser_old expected = new WebUser_old(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0); db().executeTransaction(new RegisterWebUserTransaction(expected)); commitTest(); - Optional found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME)); + Optional found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME)); assertTrue(found.isPresent()); assertEquals(expected, found.get()); } @@ -500,7 +500,7 @@ public interface DatabaseTest { Collections.singletonList(new DateObj<>(System.currentTimeMillis(), r.nextInt()))) ); - WebUser webUser = new WebUser(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0); + WebUser_old webUser = new WebUser_old(TestConstants.PLAYER_ONE_NAME, "RandomGarbageBlah", 0); db().executeTransaction(new RegisterWebUserTransaction(webUser)); } diff --git a/Plan/common/src/test/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java b/Plan/common/src/test/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java index df7d8a6ef..4505f07b0 100644 --- a/Plan/common/src/test/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java +++ b/Plan/common/src/test/java/com/djrapitops/plan/utilities/comparators/ComparatorTest.java @@ -16,7 +16,7 @@ */ package com.djrapitops.plan.utilities.comparators; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.domain.keys.SessionKeys; import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point; import com.djrapitops.plan.gathering.domain.GeoInfo; @@ -83,14 +83,14 @@ class ComparatorTest { @Test void webUserComparator() throws PassEncryptUtil.CannotPerformOperationException { - List webUsers = RandomData.randomWebUsers(); + List webUsers = RandomData.randomWebUsers(); - List expected = webUsers.stream().map(WebUser::getPermLevel) + List expected = webUsers.stream().map(WebUser_old::getPermLevel) .sorted(Integer::compare).collect(Collectors.toList()); Collections.reverse(expected); webUsers.sort(new WebUserComparator()); - List result = Lists.map(webUsers, WebUser::getPermLevel); + List result = Lists.map(webUsers, WebUser_old::getPermLevel); assertEquals(expected, result); } diff --git a/Plan/common/src/test/java/utilities/RandomData.java b/Plan/common/src/test/java/utilities/RandomData.java index f2a5f077c..fa20db9af 100644 --- a/Plan/common/src/test/java/utilities/RandomData.java +++ b/Plan/common/src/test/java/utilities/RandomData.java @@ -16,7 +16,7 @@ */ package utilities; -import com.djrapitops.plan.delivery.domain.WebUser; +import com.djrapitops.plan.delivery.domain.WebUser_old; import com.djrapitops.plan.delivery.rendering.json.graphs.line.Point; import com.djrapitops.plan.gathering.domain.GeoInfo; import com.djrapitops.plan.gathering.domain.Session; @@ -51,10 +51,10 @@ public class RandomData { return RandomStringUtils.randomAlphanumeric(size); } - public static List randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException { - List test = new ArrayList<>(); + public static List randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException { + List test = new ArrayList<>(); for (int i = 0; i < 20; i++) { - test.add(new WebUser(randomString(5), PassEncryptUtil.createHash(randomString(7)), r.nextInt())); + test.add(new WebUser_old(randomString(5), PassEncryptUtil.createHash(randomString(7)), r.nextInt())); } return test; }