original code

This commit is contained in:
GoXLR 2022-10-19 17:56:53 +02:00
parent 1fb257b573
commit 9f2ad2d73a
No known key found for this signature in database
GPG Key ID: 5B163CA341BAA2EA
11 changed files with 25 additions and 21 deletions

View File

@ -128,7 +128,7 @@ public final class APIv3 {
}
@Bean
public Router router(Vertx vertx, HttpServerOptions httpServerOptions, @Value("8080") int port) {
public Router router(Vertx vertx, HttpServerOptions httpServerOptions, @Value("${http.port}") int port) {
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
Router router = Router.router(vertx);

View File

@ -43,7 +43,7 @@ import fr.javatic.mongo.jacksonCodec.JacksonCodecProvider;
public class MongoConfig {
@Bean
public MongoDatabase mongoDatabase(@Value("mongodb://localhost:27017/HQAPI") String mongoUri) {
public MongoDatabase mongoDatabase(@Value("${mongoUri}") String mongoUri) {
ConnectionString connStr = new ConnectionString(mongoUri);
// all of these lines except for .codecRegistry are copied from MongoClients#create(ConnectionString)

View File

@ -19,7 +19,7 @@ public class RedisConfig {
}
@Bean
public RedisOptions redisOptions(@Value("redis://localhost:6379") URI redisUri) {
public RedisOptions redisOptions(@Value("${redisUri}") URI redisUri) {
return new RedisOptions()
.setAddress(redisUri.getHost())
.setPort(redisUri.getPort());

View File

@ -20,8 +20,8 @@ public class VertxConfig {
@Bean
public HttpServerOptions httpServerOptions(
@Value("") String keystorePassword,
@Value("") String keystoreFile
@Value("${http.keystorePassword}") String keystorePassword,
@Value("${http.keystoreFile}") String keystoreFile
) {
HttpServerOptions options = new HttpServerOptions();

View File

@ -16,7 +16,7 @@ import io.vertx.redis.RedisClient;
public final class RedisDisposableLoginTokenService implements DisposableLoginTokenService {
@Autowired private RedisClient redisClient;
@Value("300") private int tokenLifetimeSeconds;
@Value("${disposableLoginToken.tokenLifetimeSeconds}") private int tokenLifetimeSeconds;
@Override
public void attemptLogin(String token, String userIp, SingleResultCallback<User> callback) {

View File

@ -21,9 +21,9 @@ import io.vertx.core.json.JsonObject;
public final class MandrillEmailService implements EmailService {
@Autowired private HttpClient httpClient;
@Value("Py2b3eY5lHVpfN2hEyHwrA") String apiKey;
@Value("no-reply@minehq.com") String fromEmail;
@Value("MineHQ Network") String fromName;
@Value("${mandrill.apiKey}") String apiKey;
@Value("${mandrill.fromEmail}") String fromEmail;
@Value("${mandrill.fromName}") String fromName;
@Override
public void sendEmail(Notification notification, String target, SingleResultCallback<Void> callback) {

View File

@ -22,9 +22,9 @@ import io.vertx.core.json.JsonObject;
public final class ZangSmsService implements SmsService {
@Autowired private HttpClient httpsClient;
@Value("ACf18890845596403e330944d98886440c") private String accountSid;
@Value("dc70bbd1fbd8411ba133fa93813a461b") private String authToken;
@Value("339-337-5300") private String fromNumber;
@Value("${zang.accountSid}") private String accountSid;
@Value("${zang.authToken}") private String authToken;
@Value("${zang.fromNumber}") private String fromNumber;
@Override
public void sendText(Notification notification, String to, SingleResultCallback<Void> callback) {

View File

@ -21,9 +21,9 @@ import io.vertx.redis.RedisClient;
public final class RedisTotpService implements TotpService {
@Autowired private RedisClient redisClient;
@Value("10") int windowSize;
@Value("300") int recentlyUsedPeriodSeconds;
@Value("5") int ipAuthorizationDays;
@Value("${totp.windowSize}") int windowSize;
@Value("${totp.recentlyUsedPeriodSeconds}") int recentlyUsedPeriodSeconds;
@Value("${totp.ipAuthorizationDays}") int ipAuthorizationDays;
private GoogleAuthenticator googleAuthenticator;
// has to be ran after construction (or else windowSize won't be defined when we go to

View File

@ -16,7 +16,7 @@ import io.vertx.redis.RedisClient;
public final class RedisUserSessionService implements UserSessionService {
@Autowired private RedisClient redisClient;
@Value("30") private int sessionExpirationTimeDays;
@Value("${userSession.sessionExpirationTimeDays}") private int sessionExpirationTimeDays;
@Override
public void sessionExists(String userIp, String userSession, SingleResultCallback<Boolean> callback) {

View File

@ -28,7 +28,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
private void processMHQAuthorization(String accessTokenString, RoutingContext ctx) {
if (accessTokenString == null || accessTokenString.isEmpty()) {
ErrorUtils.respondOther(ctx, 403, "Failed to authorize. (accessTokenString is null)", "failedToAuthorizeNoKey", ImmutableMap.of());
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoKey", ImmutableMap.of());
return;
}
@ -39,7 +39,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
}
if (accessToken == null) {
ErrorUtils.respondOther(ctx, 403, "Failed to authorize. (accessToken is null)", "failedToAuthorizeUnknownKey", ImmutableMap.of());
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeUnknownKey", ImmutableMap.of());
return;
}
@ -47,7 +47,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
boolean allowed = accessToken.getLockedIps().contains(ctx.request().remoteAddress().host());
if (!allowed) {
ErrorUtils.respondOther(ctx, 403, "Failed to authorize. (not allowed)", "failedToAuthorizeNoIpWhitelist", ImmutableMap.of());
ErrorUtils.respondOther(ctx, 403, "Failed to authorize.", "failedToAuthorizeNoIpWhitelist", ImmutableMap.of());
return;
}
}

View File

@ -8,7 +8,11 @@ import net.frozenorb.apiv3.util.SyncUtils;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
@ -33,7 +37,7 @@ public final class GETStaff implements Handler<RoutingContext> {
});
List<Grant> staffGrants = SyncUtils.runBlocking(v -> Grant.findByRank(staffRanks.values(), v));
staffGrants.sort(Comparator.comparing(Grant::getAddedAt));
staffGrants.sort((a, b) -> a.getAddedAt().compareTo(b.getAddedAt()));
for (Grant staffGrant : staffGrants) {
if (staffGrant.isActive()) {