mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Support sudo in mysql/psotgresql/filesystem AuthCoreProvider
This commit is contained in:
parent
4e50cea93a
commit
a4bf033aa8
1 changed files with 19 additions and 9 deletions
|
@ -12,6 +12,7 @@
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
import pro.gravit.launchserver.auth.SQLSourceConfig;
|
import pro.gravit.launchserver.auth.SQLSourceConfig;
|
||||||
|
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportSudo;
|
||||||
import pro.gravit.launchserver.auth.password.PasswordVerifier;
|
import pro.gravit.launchserver.auth.password.PasswordVerifier;
|
||||||
import pro.gravit.launchserver.helper.LegacySessionHelper;
|
import pro.gravit.launchserver.helper.LegacySessionHelper;
|
||||||
import pro.gravit.launchserver.manangers.AuthManager;
|
import pro.gravit.launchserver.manangers.AuthManager;
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
import static java.util.concurrent.TimeUnit.HOURS;
|
import static java.util.concurrent.TimeUnit.HOURS;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
public abstract class AbstractSQLCoreProvider extends AuthCoreProvider {
|
public abstract class AbstractSQLCoreProvider extends AuthCoreProvider implements AuthSupportSudo {
|
||||||
public final transient Logger logger = LogManager.getLogger();
|
public final transient Logger logger = LogManager.getLogger();
|
||||||
public long expireSeconds = HOURS.toSeconds(1);
|
public long expireSeconds = HOURS.toSeconds(1);
|
||||||
public String uuidColumn;
|
public String uuidColumn;
|
||||||
|
@ -142,14 +143,12 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw AuthException.userNotFound();
|
throw AuthException.userNotFound();
|
||||||
}
|
}
|
||||||
if (context != null) {
|
AuthPlainPassword plainPassword = (AuthPlainPassword) password;
|
||||||
AuthPlainPassword plainPassword = (AuthPlainPassword) password;
|
if (plainPassword == null) {
|
||||||
if (plainPassword == null) {
|
throw AuthException.wrongPassword();
|
||||||
throw AuthException.wrongPassword();
|
}
|
||||||
}
|
if (!passwordVerifier.check(user.password, plainPassword.password)) {
|
||||||
if (!passwordVerifier.check(user.password, plainPassword.password)) {
|
throw AuthException.wrongPassword();
|
||||||
throw AuthException.wrongPassword();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SQLUserSession session = createSession(user);
|
SQLUserSession session = createSession(user);
|
||||||
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);
|
||||||
|
@ -163,6 +162,17 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthManager.AuthReport sudo(User user, boolean shadow) throws IOException {
|
||||||
|
SQLUser sqlUser = (SQLUser) user;
|
||||||
|
SQLUserSession session = createSession(sqlUser);
|
||||||
|
var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(sqlUser, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey);
|
||||||
|
var refreshToken = sqlUser.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(sqlUser.username, sqlUser.password, server.keyAgreementManager.legacySalt));
|
||||||
|
String minecraftAccessToken = SecurityHelper.randomStringToken();
|
||||||
|
updateAuth(user, minecraftAccessToken);
|
||||||
|
return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User checkServer(Client client, String username, String serverID) throws IOException {
|
public User checkServer(Client client, String username, String serverID) throws IOException {
|
||||||
SQLUser user = (SQLUser) getUserByUsername(username);
|
SQLUser user = (SQLUser) getUserByUsername(username);
|
||||||
|
|
Loading…
Reference in a new issue