Skip to content

Commit d302b17

Browse files
committed
Progress
1 parent afd54c1 commit d302b17

File tree

5 files changed

+60
-21
lines changed

5 files changed

+60
-21
lines changed

example-plugin/src/main/java/space/itoncek/trailcompass/ExamplePackage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void onLoad(Config cfg) {
2222
@Override
2323
public void onEnable() {
2424
c.logger().info("Loading Geodesk database");
25-
flib = new FeatureLibrary(new File(c.dataFolder() + "/praha.gol").getPath());
25+
flib = c.featureLibrary();
2626
}
2727

2828
@Override

example-plugin/src/test/java/space/itoncek/trailcompass/measuring/PoiMeasurementRequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class PoiMeasurementRequestTest {
2424

2525
@BeforeEach
2626
void setUp() {
27+
new File("./praha.gol").deleteOnExit();
2728
flib = new FeatureLibrary(new File("./praha.gol").getPath(),"https://cdn.itoncek.space/praha");
2829
ls = new LocationSupplier(() -> new Location(50.0544700, 14.2905664, 0),
2930
() -> new Location(50.1089592, 14.5773658, 0));
30-
new File("./praha.gol").deleteOnExit();
3131
}
3232

3333
@Test

server/src/main/java/space/itoncek/trailcompass/TrailServer.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
import io.javalin.Javalin;
44
import static io.javalin.apibuilder.ApiBuilder.*;
5+
import io.javalin.http.Context;
6+
import io.javalin.http.HttpStatus;
7+
import io.javalin.openapi.HttpMethod;
8+
import io.javalin.openapi.OpenApi;
9+
import io.javalin.openapi.OpenApiContent;
10+
import io.javalin.openapi.OpenApiResponse;
511
import io.javalin.openapi.plugin.OpenApiPlugin;
612
import io.javalin.openapi.plugin.OpenApiPluginConfiguration;
713
import io.javalin.openapi.plugin.swagger.SwaggerPlugin;
14+
import org.jetbrains.annotations.NotNull;
815
import org.slf4j.Logger;
916
import org.slf4j.LoggerFactory;
1017
import space.itoncek.trailcompass.database.DatabaseInterface;
@@ -91,9 +98,38 @@ public TrailServer() {
9198
post("addRequest", setup::addRequest);
9299
});
93100
get("health", healthMonitor::check);
101+
get("/", this::getVersion);
102+
get("time", this::getTime);
94103
});
95104
});
96105
}
106+
@OpenApi(
107+
summary = "Get server time, useful for determining ping and synchronising clocks",
108+
operationId = "time",
109+
path = "/time",
110+
methods = HttpMethod.GET,
111+
tags = {"SYSTEM"},
112+
responses = {
113+
@OpenApiResponse(status = "200", content = {@OpenApiContent(mimeType = "text/plain", example = "1739379173617")})
114+
}
115+
)
116+
private void getTime(@NotNull Context context) {
117+
context.status(HttpStatus.OK).result(System.currentTimeMillis() + "");
118+
}
119+
120+
@OpenApi(
121+
summary = "Get server version",
122+
operationId = "ver",
123+
path = "/",
124+
methods = HttpMethod.GET,
125+
tags = {"SYSTEM"},
126+
responses = {
127+
@OpenApiResponse(status = "200", content = {@OpenApiContent(mimeType = "text/plain", example = "vDEVELOPMENT")})
128+
}
129+
)
130+
private void getVersion(@NotNull Context context) {
131+
context.status(HttpStatus.OK).result(TrailServer.class.getPackage().getImplementationVersion() == null? "vDEVELOPMENT":TrailServer.class.getPackage().getImplementationVersion());
132+
}
97133

98134
public static void main(String[] args) {
99135
TrailServer ts = new TrailServer();
@@ -116,9 +152,6 @@ public static void main(String[] args) {
116152

117153
private static void setupOpenApi(OpenApiPluginConfiguration pluginConfig) {
118154
pluginConfig.withDefinitionConfiguration((version, definition) -> definition.withInfo(info -> info.setTitle("Trailserver Backend API Specification"))
119-
.withServer(server -> server.description("Backend server for TrailCompass")
120-
.url("{url}")
121-
.variable("url", "URL of the server", "http://localhost:8080/"))
122155
.withSecurity(security -> security.withBearerAuth("JWT")));
123156
}
124157

server/src/main/java/space/itoncek/trailcompass/modules/LoginSystem.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public void login(Context ctx) {
7878
try {
7979
JSONObject body = new JSONObject(ctx.body());
8080

81+
log.info("{}, {}",body.getString("username"), body.getString("passwordhash"));
8182
UserMeta user = server.db.getUserMeta(body.getString("username"), body.getString("passwordhash"));
8283

8384
if (user == null) {
@@ -176,23 +177,27 @@ public void verifyLogin(Context ctx) {
176177
}
177178

178179
public void checkTokenValidity(Context h) {
179-
if ((h.method() == HandlerType.POST) && !(h.path().startsWith("/uac/login") || h.path().equals("/uac/verifyLogin"))) {
180-
try {
181-
String header = h.header(Header.AUTHORIZATION);
182-
if (header == null) {
183-
throw new MissingClaimException(h.ip());
184-
}
185-
186-
DecodedJWT verify = verifier.verify(header.substring(7));
187-
188-
log.info(verify.getClaim("validuntil").asLong() + " x " + System.currentTimeMillis());
189-
if (verify.getClaim("validuntil").asLong() < System.currentTimeMillis()) {
190-
h.status(HttpStatus.IM_A_TEAPOT).result("expired");
191-
}
192-
} catch (JSONException | AlgorithmMismatchException | SignatureVerificationException |
193-
TokenExpiredException | MissingClaimException | IncorrectClaimException e) {
194-
h.status(HttpStatus.UNAUTHORIZED).result("Neplatný token!");
180+
if (h.path().startsWith("/uac/login")) return;
181+
else if (h.path().equals("/uac/verifyLogin")) return;
182+
else if (h.path().equals("/")) return;
183+
else if (h.method().equals(HandlerType.GET)) return;
184+
185+
186+
try {
187+
String header = h.header(Header.AUTHORIZATION);
188+
if (header == null) {
189+
throw new MissingClaimException(h.ip());
190+
}
191+
192+
DecodedJWT verify = verifier.verify(header.substring(7));
193+
194+
log.info(verify.getClaim("validuntil").asLong() + " x " + System.currentTimeMillis());
195+
if (verify.getClaim("validuntil").asLong() < System.currentTimeMillis()) {
196+
h.status(HttpStatus.IM_A_TEAPOT).result("expired");
195197
}
198+
} catch (JSONException | AlgorithmMismatchException | SignatureVerificationException |
199+
TokenExpiredException | MissingClaimException | IncorrectClaimException e) {
200+
h.status(HttpStatus.UNAUTHORIZED).result("Neplatný token!");
196201
}
197202
}
198203

server/src/main/java/space/itoncek/trailcompass/packages/PackageLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void loadPlugins(File dir) throws Exception {
3131
if (jars == null) return;
3232

3333
for (File jar : jars) {
34+
if(jar.isDirectory()) continue;
3435
URLClassLoader classLoader = new URLClassLoader(
3536
new URL[]{jar.toURI().toURL()},
3637
this.getClass().getClassLoader()

0 commit comments

Comments
 (0)