mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Replaced with use TimeUnit (#666)
This commit is contained in:
parent
b12c43676b
commit
55c0cdfa0d
6 changed files with 28 additions and 16 deletions
|
@ -11,6 +11,8 @@
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
|
|
||||||
public final class MySQLSourceConfig implements AutoCloseable, SQLSourceConfig {
|
public final class MySQLSourceConfig implements AutoCloseable, SQLSourceConfig {
|
||||||
|
|
||||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||||
|
@ -33,7 +35,7 @@ public final class MySQLSourceConfig implements AutoCloseable, SQLSourceConfig {
|
||||||
private String password;
|
private String password;
|
||||||
private String database;
|
private String database;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
private long hikariMaxLifetime = 30*60*1000; // 30 minutes
|
private long hikariMaxLifetime = MINUTES.toMillis(30);
|
||||||
private boolean useHikari;
|
private boolean useHikari;
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
|
@ -109,7 +111,6 @@ public synchronized Connection getConnection() throws SQLException {
|
||||||
hikariConfig.setMaximumPoolSize(MAX_POOL_SIZE);
|
hikariConfig.setMaximumPoolSize(MAX_POOL_SIZE);
|
||||||
hikariConfig.setConnectionTestQuery("SELECT 1");
|
hikariConfig.setConnectionTestQuery("SELECT 1");
|
||||||
hikariConfig.setConnectionTimeout(1000);
|
hikariConfig.setConnectionTimeout(1000);
|
||||||
hikariConfig.setAutoCommit(true);
|
|
||||||
hikariConfig.setLeakDetectionThreshold(2000);
|
hikariConfig.setLeakDetectionThreshold(2000);
|
||||||
hikariConfig.setMaxLifetime(hikariMaxLifetime);
|
hikariConfig.setMaxLifetime(hikariMaxLifetime);
|
||||||
// Set HikariCP pool
|
// Set HikariCP pool
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
public final class PostgreSQLSourceConfig implements AutoCloseable, SQLSourceConfig {
|
public final class PostgreSQLSourceConfig implements AutoCloseable, SQLSourceConfig {
|
||||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||||
Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.idleTimeout", Integer.toString(5000))),
|
Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.idleTimeout", Integer.toString(5000))),
|
||||||
|
@ -27,7 +30,7 @@ public final class PostgreSQLSourceConfig implements AutoCloseable, SQLSourceCon
|
||||||
private String password;
|
private String password;
|
||||||
private String database;
|
private String database;
|
||||||
|
|
||||||
private long hikariMaxLifetime = 30*60*1000; // 30 minutes
|
private long hikariMaxLifetime = MINUTES.toMillis(30); // 30 minutes
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
private transient DataSource source;
|
private transient DataSource source;
|
||||||
|
@ -67,7 +70,7 @@ public synchronized Connection getConnection() throws SQLException {
|
||||||
hikariSource.setPoolName(poolName);
|
hikariSource.setPoolName(poolName);
|
||||||
hikariSource.setMinimumIdle(0);
|
hikariSource.setMinimumIdle(0);
|
||||||
hikariSource.setMaximumPoolSize(MAX_POOL_SIZE);
|
hikariSource.setMaximumPoolSize(MAX_POOL_SIZE);
|
||||||
hikariSource.setIdleTimeout(TIMEOUT * 1000L);
|
hikariSource.setIdleTimeout(SECONDS.toMillis(TIMEOUT));
|
||||||
hikariSource.setMaxLifetime(hikariMaxLifetime);
|
hikariSource.setMaxLifetime(hikariMaxLifetime);
|
||||||
|
|
||||||
// Replace source with hds
|
// Replace source with hds
|
||||||
|
|
|
@ -28,9 +28,12 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.HOURS;
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
public abstract class AbstractSQLCoreProvider extends AuthCoreProvider {
|
public abstract class AbstractSQLCoreProvider extends AuthCoreProvider {
|
||||||
public final transient Logger logger = LogManager.getLogger();
|
public final transient Logger logger = LogManager.getLogger();
|
||||||
public int expireSeconds = 3600;
|
public long expireSeconds = HOURS.toSeconds(1);
|
||||||
public String uuidColumn;
|
public String uuidColumn;
|
||||||
public String usernameColumn;
|
public String usernameColumn;
|
||||||
public String accessTokenColumn;
|
public String accessTokenColumn;
|
||||||
|
@ -129,7 +132,7 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
|
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
|
||||||
return new AuthManager.AuthReport(null, accessToken, refreshToken, expireSeconds * 1000L, new SQLUserSession(user));
|
return new AuthManager.AuthReport(null, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), new SQLUserSession(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -153,9 +156,9 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c
|
||||||
if (minecraftAccess) {
|
if (minecraftAccess) {
|
||||||
String minecraftAccessToken = SecurityHelper.randomStringToken();
|
String minecraftAccessToken = SecurityHelper.randomStringToken();
|
||||||
updateAuth(SQLUser, minecraftAccessToken);
|
updateAuth(SQLUser, minecraftAccessToken);
|
||||||
return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, expireSeconds * 1000L, session);
|
return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session);
|
||||||
} else {
|
} else {
|
||||||
return AuthManager.AuthReport.ofOAuth(accessToken, refreshToken, expireSeconds * 1000L, session);
|
return AuthManager.AuthReport.ofOAuth(accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
public class AdvancedProtectHandler extends StdProtectHandler implements SecureProtectHandler, HardwareProtectHandler, JoinServerProtectHandler {
|
public class AdvancedProtectHandler extends StdProtectHandler implements SecureProtectHandler, HardwareProtectHandler, JoinServerProtectHandler {
|
||||||
private transient final Logger logger = LogManager.getLogger();
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
public boolean enableHardwareFeature;
|
public boolean enableHardwareFeature;
|
||||||
|
@ -104,7 +106,7 @@ public String createHardwareToken(String username, UserHardware hardware) {
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setIssuer("LaunchServer")
|
.setIssuer("LaunchServer")
|
||||||
.setSubject(username)
|
.setSubject(username)
|
||||||
.setExpiration(new Date(System.currentTimeMillis() + 1000 * server.config.netty.security.hardwareTokenExpire))
|
.setExpiration(new Date(System.currentTimeMillis() + SECONDS.toMillis(server.config.netty.security.hardwareTokenExpire)))
|
||||||
.claim("hardware", hardware.getId())
|
.claim("hardware", hardware.getId())
|
||||||
.signWith(server.keyAgreementManager.ecdsaPrivateKey)
|
.signWith(server.keyAgreementManager.ecdsaPrivateKey)
|
||||||
.compact();
|
.compact();
|
||||||
|
@ -114,7 +116,7 @@ public String createPublicKeyToken(String username, byte[] publicKey) {
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.setIssuer("LaunchServer")
|
.setIssuer("LaunchServer")
|
||||||
.setSubject(username)
|
.setSubject(username)
|
||||||
.setExpiration(new Date(System.currentTimeMillis() + 1000 * server.config.netty.security.publicKeyTokenExpire))
|
.setExpiration(new Date(System.currentTimeMillis() + SECONDS.toMillis(server.config.netty.security.publicKeyTokenExpire)))
|
||||||
.claim("publicKey", Base64.getEncoder().encodeToString(publicKey))
|
.claim("publicKey", Base64.getEncoder().encodeToString(publicKey))
|
||||||
.signWith(server.keyAgreementManager.ecdsaPrivateKey)
|
.signWith(server.keyAgreementManager.ecdsaPrivateKey)
|
||||||
.compact();
|
.compact();
|
||||||
|
|
|
@ -16,7 +16,7 @@ public abstract class AbstractLimiter<T> extends Component implements Reconfigur
|
||||||
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
||||||
private transient final Logger logger = LogManager.getLogger();
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
public int rateLimit;
|
public int rateLimit;
|
||||||
public int rateLimitMillis;
|
public long rateLimitMillis;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Command> getCommands() {
|
public Map<String, Command> getCommands() {
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.HOURS;
|
||||||
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
public final class LaunchServerConfig {
|
public final class LaunchServerConfig {
|
||||||
private final static List<String> oldMirrorList = List.of("https://mirror.gravit.pro/5.2.x/", "https://mirror.gravit.pro/5.3.x/", "https://mirror.gravitlauncher.com/5.2.x/", "https://mirror.gravitlauncher.com/5.3.x/");
|
private final static List<String> oldMirrorList = List.of("https://mirror.gravit.pro/5.2.x/", "https://mirror.gravit.pro/5.3.x/", "https://mirror.gravitlauncher.com/5.2.x/", "https://mirror.gravitlauncher.com/5.3.x/");
|
||||||
private transient final Logger logger = LogManager.getLogger();
|
private transient final Logger logger = LogManager.getLogger();
|
||||||
|
@ -94,12 +97,12 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
||||||
newConfig.components = new HashMap<>();
|
newConfig.components = new HashMap<>();
|
||||||
AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent();
|
AuthLimiterComponent authLimiterComponent = new AuthLimiterComponent();
|
||||||
authLimiterComponent.rateLimit = 3;
|
authLimiterComponent.rateLimit = 3;
|
||||||
authLimiterComponent.rateLimitMillis = 8000;
|
authLimiterComponent.rateLimitMillis = SECONDS.toMillis(8);
|
||||||
authLimiterComponent.message = "Превышен лимит авторизаций";
|
authLimiterComponent.message = "Превышен лимит авторизаций";
|
||||||
newConfig.components.put("authLimiter", authLimiterComponent);
|
newConfig.components.put("authLimiter", authLimiterComponent);
|
||||||
RegLimiterComponent regLimiterComponent = new RegLimiterComponent();
|
RegLimiterComponent regLimiterComponent = new RegLimiterComponent();
|
||||||
regLimiterComponent.rateLimit = 3;
|
regLimiterComponent.rateLimit = 3;
|
||||||
regLimiterComponent.rateLimitMillis = 1000 * 60 * 60 * 10; //Блок на 10 часов
|
regLimiterComponent.rateLimitMillis = HOURS.toMillis(10);
|
||||||
regLimiterComponent.message = "Превышен лимит регистраций";
|
regLimiterComponent.message = "Превышен лимит регистраций";
|
||||||
newConfig.components.put("regLimiter", regLimiterComponent);
|
newConfig.components.put("regLimiter", regLimiterComponent);
|
||||||
ProGuardComponent proGuardComponent = new ProGuardComponent();
|
ProGuardComponent proGuardComponent = new ProGuardComponent();
|
||||||
|
@ -310,9 +313,9 @@ public NettyBindAddress(String address, int port) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NettySecurityConfig {
|
public static class NettySecurityConfig {
|
||||||
public long hardwareTokenExpire = 60 * 60 * 8;
|
public long hardwareTokenExpire = HOURS.toSeconds(8);
|
||||||
public long publicKeyTokenExpire = 60 * 60 * 8;
|
public long publicKeyTokenExpire = HOURS.toSeconds(8);
|
||||||
|
|
||||||
public long launcherTokenExpire = 60 * 60 * 8;
|
public long launcherTokenExpire = HOURS.toSeconds(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue