original code
This commit is contained in:
parent
1fb257b573
commit
9f2ad2d73a
@ -128,7 +128,7 @@ public final class APIv3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@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);
|
HttpServer webServer = vertx.createHttpServer(httpServerOptions);
|
||||||
Router router = Router.router(vertx);
|
Router router = Router.router(vertx);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ import fr.javatic.mongo.jacksonCodec.JacksonCodecProvider;
|
|||||||
public class MongoConfig {
|
public class MongoConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MongoDatabase mongoDatabase(@Value("mongodb://localhost:27017/HQAPI") String mongoUri) {
|
public MongoDatabase mongoDatabase(@Value("${mongoUri}") String mongoUri) {
|
||||||
ConnectionString connStr = new ConnectionString(mongoUri);
|
ConnectionString connStr = new ConnectionString(mongoUri);
|
||||||
|
|
||||||
// all of these lines except for .codecRegistry are copied from MongoClients#create(ConnectionString)
|
// all of these lines except for .codecRegistry are copied from MongoClients#create(ConnectionString)
|
||||||
|
@ -19,7 +19,7 @@ public class RedisConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedisOptions redisOptions(@Value("redis://localhost:6379") URI redisUri) {
|
public RedisOptions redisOptions(@Value("${redisUri}") URI redisUri) {
|
||||||
return new RedisOptions()
|
return new RedisOptions()
|
||||||
.setAddress(redisUri.getHost())
|
.setAddress(redisUri.getHost())
|
||||||
.setPort(redisUri.getPort());
|
.setPort(redisUri.getPort());
|
||||||
|
@ -20,8 +20,8 @@ public class VertxConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public HttpServerOptions httpServerOptions(
|
public HttpServerOptions httpServerOptions(
|
||||||
@Value("") String keystorePassword,
|
@Value("${http.keystorePassword}") String keystorePassword,
|
||||||
@Value("") String keystoreFile
|
@Value("${http.keystoreFile}") String keystoreFile
|
||||||
) {
|
) {
|
||||||
HttpServerOptions options = new HttpServerOptions();
|
HttpServerOptions options = new HttpServerOptions();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import io.vertx.redis.RedisClient;
|
|||||||
public final class RedisDisposableLoginTokenService implements DisposableLoginTokenService {
|
public final class RedisDisposableLoginTokenService implements DisposableLoginTokenService {
|
||||||
|
|
||||||
@Autowired private RedisClient redisClient;
|
@Autowired private RedisClient redisClient;
|
||||||
@Value("300") private int tokenLifetimeSeconds;
|
@Value("${disposableLoginToken.tokenLifetimeSeconds}") private int tokenLifetimeSeconds;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void attemptLogin(String token, String userIp, SingleResultCallback<User> callback) {
|
public void attemptLogin(String token, String userIp, SingleResultCallback<User> callback) {
|
||||||
|
@ -21,9 +21,9 @@ import io.vertx.core.json.JsonObject;
|
|||||||
public final class MandrillEmailService implements EmailService {
|
public final class MandrillEmailService implements EmailService {
|
||||||
|
|
||||||
@Autowired private HttpClient httpClient;
|
@Autowired private HttpClient httpClient;
|
||||||
@Value("Py2b3eY5lHVpfN2hEyHwrA") String apiKey;
|
@Value("${mandrill.apiKey}") String apiKey;
|
||||||
@Value("no-reply@minehq.com") String fromEmail;
|
@Value("${mandrill.fromEmail}") String fromEmail;
|
||||||
@Value("MineHQ Network") String fromName;
|
@Value("${mandrill.fromName}") String fromName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEmail(Notification notification, String target, SingleResultCallback<Void> callback) {
|
public void sendEmail(Notification notification, String target, SingleResultCallback<Void> callback) {
|
||||||
|
@ -22,9 +22,9 @@ import io.vertx.core.json.JsonObject;
|
|||||||
public final class ZangSmsService implements SmsService {
|
public final class ZangSmsService implements SmsService {
|
||||||
|
|
||||||
@Autowired private HttpClient httpsClient;
|
@Autowired private HttpClient httpsClient;
|
||||||
@Value("ACf18890845596403e330944d98886440c") private String accountSid;
|
@Value("${zang.accountSid}") private String accountSid;
|
||||||
@Value("dc70bbd1fbd8411ba133fa93813a461b") private String authToken;
|
@Value("${zang.authToken}") private String authToken;
|
||||||
@Value("339-337-5300") private String fromNumber;
|
@Value("${zang.fromNumber}") private String fromNumber;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendText(Notification notification, String to, SingleResultCallback<Void> callback) {
|
public void sendText(Notification notification, String to, SingleResultCallback<Void> callback) {
|
||||||
|
@ -21,9 +21,9 @@ import io.vertx.redis.RedisClient;
|
|||||||
public final class RedisTotpService implements TotpService {
|
public final class RedisTotpService implements TotpService {
|
||||||
|
|
||||||
@Autowired private RedisClient redisClient;
|
@Autowired private RedisClient redisClient;
|
||||||
@Value("10") int windowSize;
|
@Value("${totp.windowSize}") int windowSize;
|
||||||
@Value("300") int recentlyUsedPeriodSeconds;
|
@Value("${totp.recentlyUsedPeriodSeconds}") int recentlyUsedPeriodSeconds;
|
||||||
@Value("5") int ipAuthorizationDays;
|
@Value("${totp.ipAuthorizationDays}") int ipAuthorizationDays;
|
||||||
private GoogleAuthenticator googleAuthenticator;
|
private GoogleAuthenticator googleAuthenticator;
|
||||||
|
|
||||||
// has to be ran after construction (or else windowSize won't be defined when we go to
|
// has to be ran after construction (or else windowSize won't be defined when we go to
|
||||||
|
@ -16,7 +16,7 @@ import io.vertx.redis.RedisClient;
|
|||||||
public final class RedisUserSessionService implements UserSessionService {
|
public final class RedisUserSessionService implements UserSessionService {
|
||||||
|
|
||||||
@Autowired private RedisClient redisClient;
|
@Autowired private RedisClient redisClient;
|
||||||
@Value("30") private int sessionExpirationTimeDays;
|
@Value("${userSession.sessionExpirationTimeDays}") private int sessionExpirationTimeDays;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sessionExists(String userIp, String userSession, SingleResultCallback<Boolean> callback) {
|
public void sessionExists(String userIp, String userSession, SingleResultCallback<Boolean> callback) {
|
||||||
|
@ -28,7 +28,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
|
|||||||
|
|
||||||
private void processMHQAuthorization(String accessTokenString, RoutingContext ctx) {
|
private void processMHQAuthorization(String accessTokenString, RoutingContext ctx) {
|
||||||
if (accessTokenString == null || accessTokenString.isEmpty()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (accessToken == null) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public final class AuthenticationFilter implements Handler<RoutingContext> {
|
|||||||
boolean allowed = accessToken.getLockedIps().contains(ctx.request().remoteAddress().host());
|
boolean allowed = accessToken.getLockedIps().contains(ctx.request().remoteAddress().host());
|
||||||
|
|
||||||
if (!allowed) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,11 @@ import net.frozenorb.apiv3.util.SyncUtils;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
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.core.Handler;
|
||||||
import io.vertx.ext.web.RoutingContext;
|
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));
|
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) {
|
for (Grant staffGrant : staffGrants) {
|
||||||
if (staffGrant.isActive()) {
|
if (staffGrant.isActive()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user