mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-30 13:08:00 +01:00
Refactored /debug page to use ResolverService
Some issues that were identified: - Going to /debug/ makes the style requests return the debug page content because the /debug resolver is used - In the future when / is to be resolved it might override a bunch of requests. - Use of RequestTarget as incompatible with URIPath for some reason which lead to infinite redirect, so the attempted change was reverted before this commit. - Some Responses are using PlanFiles to obtain a html file (SRP violation) Rest of the pages still use the old resolution that is now deprecated.
This commit is contained in:
parent
9c74c40f72
commit
2736ba042a
@ -23,7 +23,7 @@ import java.util.Optional;
|
||||
/**
|
||||
* Utility Resolver for organizing resolution in a tree-like structure.
|
||||
* <p>
|
||||
* 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<Resolver> getResolver(URLTarget target) {
|
||||
private Optional<Resolver> 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<Response> resolve(URLTarget target, Parameters parameters) {
|
||||
public Optional<Response> 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) {
|
||||
|
@ -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<Response> resolve(URLTarget target, Parameters parameters);
|
||||
Optional<Response> 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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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<String> 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.
|
||||
* <p>
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -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<String, String> byKey;
|
||||
|
||||
public Parameters(Map<String, String> byKey) {
|
||||
public URIQuery(Map<String, String> byKey) {
|
||||
this.byKey = byKey;
|
||||
}
|
||||
|
||||
public URIQuery(String fromURI) {
|
||||
this.byKey = parseParameters(fromURI);
|
||||
}
|
||||
|
||||
private Map<String, String> parseParameters(String fromURI) {
|
||||
if (fromURI == null || fromURI.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
Map<String, String> 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.
|
||||
*
|
@ -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<String> getStringList(String path, Supplier<List<String>> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> expected = Optional.of("");
|
||||
Optional<String> 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<String> expected = Optional.of("example");
|
||||
Optional<String> 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<String> expected = Optional.of("target");
|
||||
Optional<String> 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<String> expected = Optional.empty();
|
||||
Optional<String> 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<String> expected = Optional.of("");
|
||||
Optional<String> 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<String> expected = Optional.empty();
|
||||
Optional<String> 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<String> expected = Optional.of("target");
|
||||
Optional<String> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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<WebUser> found = db.query(WebUserQueries.fetchWebUser(user));
|
||||
Optional<WebUser_old> 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);
|
||||
|
@ -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<WebUser> found = db.query(WebUserQueries.fetchWebUser(user));
|
||||
Optional<WebUser_old> found = db.query(WebUserQueries.fetchWebUser(user));
|
||||
if (!found.isPresent()) {
|
||||
sender.sendMessage("§c[Plan] User Doesn't exist.");
|
||||
return;
|
||||
|
@ -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<WebUser> users = dbSystem.getDatabase().query(WebUserQueries.fetchAllPlanWebUsers());
|
||||
List<WebUser_old> 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(">");
|
||||
|
@ -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<String> 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])
|
||||
);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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<Long> 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");
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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("<br><br><pre>");
|
||||
paragraph.append(error).append(" | ").append(errorMsg);
|
||||
|
||||
for (StackTraceElement element : error.getStackTrace()) {
|
||||
paragraph.append("<br>");
|
||||
paragraph.append(" ").append(element);
|
||||
}
|
||||
if (error.getCause() != null) {
|
||||
appendCause(error.getCause(), paragraph);
|
||||
}
|
||||
|
||||
paragraph.append("</pre>");
|
||||
|
||||
return paragraph.toString();
|
||||
}
|
||||
|
||||
private void appendCause(Throwable cause, StringBuilder paragraph) {
|
||||
paragraph.append("<br>Caused by: ").append(cause);
|
||||
for (StackTraceElement element : cause.getStackTrace()) {
|
||||
paragraph.append("<br>");
|
||||
paragraph.append(" ").append(element);
|
||||
}
|
||||
if (cause.getCause() != null) {
|
||||
appendCause(cause.getCause(), paragraph);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
||||
List<ExtensionData> extensionData = dbSystem.getDatabase().query(new ExtensionServerDataQuery(serverUUID));
|
||||
return new ServerPluginTabs(extensionData, formatters);
|
||||
});
|
||||
CachingSupplier<ServerPluginTabs> pluginTabs = new CachingSupplier<>(() -> {
|
||||
List<ExtensionData> 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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -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> versionCheckSystem;
|
||||
private final Lazy<PlanFiles> fileSystem;
|
||||
private final Lazy<PlanFiles> files;
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final Lazy<Theme> theme;
|
||||
private final Lazy<DBSystem> dbSystem;
|
||||
@ -62,7 +63,7 @@ public class PageFactory {
|
||||
@Inject
|
||||
public PageFactory(
|
||||
Lazy<VersionCheckSystem> versionCheckSystem,
|
||||
Lazy<PlanFiles> fileSystem,
|
||||
Lazy<PlanFiles> files,
|
||||
Lazy<PlanConfig> config,
|
||||
Lazy<Theme> theme,
|
||||
Lazy<DBSystem> dbSystem,
|
||||
@ -73,7 +74,7 @@ public class PageFactory {
|
||||
Lazy<ErrorHandler> 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();
|
||||
}
|
||||
}
|
@ -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<Long> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Container> basicResolvers;
|
||||
private final Collection<Container> 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<Resolver> 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<String> 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<String> matcher;
|
||||
final Resolver resolver;
|
||||
|
||||
public Container(String plugin, Predicate<String> matcher, Resolver resolver) {
|
||||
this.plugin = plugin;
|
||||
this.matcher = matcher;
|
||||
this.resolver = resolver;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Response> forbid = handlePasswordBruteForceAttempts(request, response);
|
||||
Optional<Response_old> forbid = handlePasswordBruteForceAttempts(request, response);
|
||||
if (forbid.isPresent()) {
|
||||
response = forbid.get();
|
||||
}
|
||||
@ -124,7 +124,7 @@ public class RequestHandler implements HttpHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<Response> shouldPreventRequest(String accessor) {
|
||||
private Optional<Response_old> 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<Response> handlePasswordBruteForceAttempts(Request request, Response response) {
|
||||
private Optional<Response_old> 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<Response> createForbiddenResponse() {
|
||||
private Optional<Response_old> createForbiddenResponse() {
|
||||
return Optional.of(responseFactory.forbidden403("You have too many failed login attempts. Please wait 2 minutes until attempting again."));
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import java.util.stream.Collectors;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Deprecated
|
||||
public class RequestTarget {
|
||||
|
||||
private final String resourceString;
|
||||
|
@ -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> webServer;
|
||||
|
||||
@Inject
|
||||
public ResponseResolver(
|
||||
ResolverSvc resolverService,
|
||||
ResponseFactory responseFactory,
|
||||
Lazy<WebServer> 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> 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> authentication = request.getAuth();
|
||||
|
||||
URIPath target = request.getPath();
|
||||
URIQuery query = request.getQuery();
|
||||
|
||||
Optional<Resolver> 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> 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()) {
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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<JSONResponse> jsonResponseSupplier) {
|
||||
public static Response_old getOrCache(String identifier, Supplier<JSONResponse> 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<JSONResponse> jsonResponseSupplier) {
|
||||
public static Response_old getOrCache(DataID dataID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||
return getOrCache(dataID.name(), jsonResponseSupplier);
|
||||
}
|
||||
|
||||
public static Response getOrCache(DataID dataID, UUID serverUUID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||
public static Response_old getOrCache(DataID dataID, UUID serverUUID, Supplier<JSONResponse> jsonResponseSupplier) {
|
||||
return getOrCache(dataID.of(serverUUID), jsonResponseSupplier);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Response> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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) {
|
||||
|
@ -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<UUID> serverUUID = getServerUUID(target);
|
||||
boolean proxy = serverInfo.getServer().isProxy();
|
||||
if (serverUUID.isPresent()) {
|
||||
|
@ -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."));
|
||||
|
||||
|
@ -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<T> 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()));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
|
@ -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)))
|
||||
|
@ -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)));
|
||||
|
@ -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<T> 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)));
|
||||
}
|
||||
|
@ -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, () ->
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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<String, String> 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);
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -49,7 +49,7 @@ public class SettingsSvc implements SettingsService {
|
||||
}
|
||||
|
||||
public void register() {
|
||||
SettingsService.SettingsServiceHolder.set(this);
|
||||
Holder.set(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<WebUser> users) {
|
||||
public static Executable storeAllPlanWebUsers(Collection<WebUser_old> 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();
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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<List<WebUser>> fetchAllPlanWebUsers() {
|
||||
public static Query<List<WebUser_old>> fetchAllPlanWebUsers() {
|
||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + ORDER_BY + SecurityTable.PERMISSION_LEVEL + " ASC";
|
||||
|
||||
return new QueryAllStatement<List<WebUser>>(sql, 5000) {
|
||||
return new QueryAllStatement<List<WebUser_old>>(sql, 5000) {
|
||||
@Override
|
||||
public List<WebUser> processResults(ResultSet set) throws SQLException {
|
||||
List<WebUser> list = new ArrayList<>();
|
||||
public List<WebUser_old> processResults(ResultSet set) throws SQLException {
|
||||
List<WebUser_old> 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<Optional<WebUser>> fetchWebUser(String called) {
|
||||
public static Query<Optional<WebUser_old>> fetchWebUser(String called) {
|
||||
String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME +
|
||||
WHERE + SecurityTable.USERNAME + "=? LIMIT 1";
|
||||
return new QueryStatement<Optional<WebUser>>(sql) {
|
||||
return new QueryStatement<Optional<WebUser_old>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, called);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<WebUser> processResults(ResultSet set) throws SQLException {
|
||||
public Optional<WebUser_old> 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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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<WebUser> {
|
||||
public class WebUserComparator implements Comparator<WebUser_old> {
|
||||
|
||||
@Override
|
||||
public int compare(WebUser o1, WebUser o2) {
|
||||
public int compare(WebUser_old o1, WebUser_old o2) {
|
||||
return Integer.compare(o2.getPermLevel(), o1.getPermLevel());
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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<WebUser> found = db().query(WebUserQueries.fetchWebUser(TestConstants.PLAYER_ONE_NAME));
|
||||
Optional<WebUser_old> 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));
|
||||
}
|
||||
|
||||
|
@ -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<WebUser> webUsers = RandomData.randomWebUsers();
|
||||
List<WebUser_old> webUsers = RandomData.randomWebUsers();
|
||||
|
||||
List<Integer> expected = webUsers.stream().map(WebUser::getPermLevel)
|
||||
List<Integer> expected = webUsers.stream().map(WebUser_old::getPermLevel)
|
||||
.sorted(Integer::compare).collect(Collectors.toList());
|
||||
Collections.reverse(expected);
|
||||
|
||||
webUsers.sort(new WebUserComparator());
|
||||
List<Integer> result = Lists.map(webUsers, WebUser::getPermLevel);
|
||||
List<Integer> result = Lists.map(webUsers, WebUser_old::getPermLevel);
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
@ -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<WebUser> randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
List<WebUser> test = new ArrayList<>();
|
||||
public static List<WebUser_old> randomWebUsers() throws PassEncryptUtil.CannotPerformOperationException {
|
||||
List<WebUser_old> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user