mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] AuthCoreProvider features
This commit is contained in:
parent
201b6826ed
commit
9fe1fc4f23
13 changed files with 88 additions and 71 deletions
|
@ -12,8 +12,8 @@
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class AuthProviderPair {
|
public final class AuthProviderPair {
|
||||||
public final boolean isDefault = true;
|
public boolean isDefault = true;
|
||||||
public AuthProvider provider;
|
public AuthProvider provider;
|
||||||
public AuthHandler handler;
|
public AuthHandler handler;
|
||||||
public TextureProvider textureProvider;
|
public TextureProvider textureProvider;
|
||||||
|
@ -30,7 +30,12 @@ public AuthProviderPair(AuthProvider provider, AuthHandler handler, TextureProvi
|
||||||
this.textureProvider = textureProvider;
|
this.textureProvider = textureProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(LaunchServer srv, String name) {
|
public final <T> T isSupport(Class<T> clazz) {
|
||||||
|
if (core == null) return null;
|
||||||
|
return core.isSupport(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void init(LaunchServer srv, String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
if (links != null) link(srv);
|
if (links != null) link(srv);
|
||||||
if (core == null) {
|
if (core == null) {
|
||||||
|
@ -53,7 +58,7 @@ public void init(LaunchServer srv, String name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void link(LaunchServer srv) {
|
public final void link(LaunchServer srv) {
|
||||||
links.forEach((k, v) -> {
|
links.forEach((k, v) -> {
|
||||||
AuthProviderPair pair = srv.config.getAuthProviderPair(v);
|
AuthProviderPair pair = srv.config.getAuthProviderPair(v);
|
||||||
if (pair == null) {
|
if (pair == null) {
|
||||||
|
@ -79,7 +84,7 @@ public void link(LaunchServer srv) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public final void close() throws IOException {
|
||||||
if (social != null) {
|
if (social != null) {
|
||||||
social.close();
|
social.close();
|
||||||
}
|
}
|
||||||
|
@ -117,15 +122,15 @@ public static void getFeatures(Class<?> clazz, Set<String> list) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseCore() {
|
public final boolean isUseCore() {
|
||||||
return core != null;
|
return core != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseSocial() {
|
public final boolean isUseSocial() {
|
||||||
return core != null && social != null;
|
return core != null && social != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUseProviderAndHandler() {
|
public final boolean isUseProviderAndHandler() {
|
||||||
return !isUseCore();
|
return !isUseCore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,26 +155,28 @@ public void invoke(String... args) throws Exception {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (this instanceof AuthSupportGetAllUsers) {
|
{
|
||||||
AuthSupportGetAllUsers instance = (AuthSupportGetAllUsers) this;
|
var instance = isSupport(AuthSupportGetAllUsers.class);
|
||||||
map.put("getallusers", new SubCommand("(limit)", "print all users information") {
|
if (instance != null) {
|
||||||
@Override
|
map.put("getallusers", new SubCommand("(limit)", "print all users information") {
|
||||||
public void invoke(String... args) throws Exception {
|
@Override
|
||||||
int max = Integer.MAX_VALUE;
|
public void invoke(String... args) throws Exception {
|
||||||
if (args.length > 0) max = Integer.parseInt(args[0]);
|
int max = Integer.MAX_VALUE;
|
||||||
Iterable<User> users = instance.getAllUsers();
|
if (args.length > 0) max = Integer.parseInt(args[0]);
|
||||||
int counter = 0;
|
Iterable<User> users = instance.getAllUsers();
|
||||||
for (User u : users) {
|
int counter = 0;
|
||||||
logger.info("User {}", u.toString());
|
for (User u : users) {
|
||||||
counter++;
|
logger.info("User {}", u.toString());
|
||||||
if (counter == max) break;
|
counter++;
|
||||||
|
if (counter == max) break;
|
||||||
|
}
|
||||||
|
logger.info("Found {} users", counter);
|
||||||
}
|
}
|
||||||
logger.info("Found {} users", counter);
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (this instanceof AuthSupportHardware) {
|
{
|
||||||
AuthSupportHardware instance = (AuthSupportHardware) this;
|
var instance = isSupport(AuthSupportHardware.class);
|
||||||
map.put("gethardwarebyid", new SubCommand("[id]", "get hardware by id") {
|
map.put("gethardwarebyid", new SubCommand("[id]", "get hardware by id") {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
|
@ -294,6 +296,12 @@ public boolean joinServer(Client client, String username, String accessToken, St
|
||||||
return user.getUsername().equals(username) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID);
|
return user.getUsername().equals(username) && user.getAccessToken().equals(accessToken) && updateServerID(user, serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> T isSupport(Class<T> clazz) {
|
||||||
|
if (clazz.isAssignableFrom(getClass())) return (T) this;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void close() throws IOException;
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package pro.gravit.launchserver.auth.core.interfaces.provider;
|
||||||
|
|
||||||
|
public interface AuthSupport {
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
import pro.gravit.launchserver.auth.core.User;
|
import pro.gravit.launchserver.auth.core.User;
|
||||||
import pro.gravit.launchserver.auth.core.UserSession;
|
import pro.gravit.launchserver.auth.core.UserSession;
|
||||||
|
|
||||||
public interface AuthSupportExit {
|
public interface AuthSupportExit extends AuthSupport {
|
||||||
boolean deleteSession(UserSession session);
|
boolean deleteSession(UserSession session);
|
||||||
|
|
||||||
boolean exitUser(User user);
|
boolean exitUser(User user);
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
import pro.gravit.launchserver.auth.core.User;
|
import pro.gravit.launchserver.auth.core.User;
|
||||||
|
|
||||||
@Feature("users")
|
@Feature("users")
|
||||||
public interface AuthSupportGetAllUsers {
|
public interface AuthSupportGetAllUsers extends AuthSupport {
|
||||||
Iterable<User> getAllUsers();
|
Iterable<User> getAllUsers();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Feature("sessions")
|
@Feature("sessions")
|
||||||
public interface AuthSupportGetSessionsFromUser {
|
public interface AuthSupportGetSessionsFromUser extends AuthSupport {
|
||||||
List<UserSession> getSessionsByUser(User user);
|
List<UserSession> getSessionsByUser(User user);
|
||||||
|
|
||||||
void clearSessionsByUser(User user);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public interface AuthSupportHardware {
|
public interface AuthSupportHardware extends AuthSupport {
|
||||||
UserHardware getHardwareInfoByPublicKey(byte[] publicKey);
|
UserHardware getHardwareInfoByPublicKey(byte[] publicKey);
|
||||||
|
|
||||||
UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo info);
|
UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo info);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportMoney;
|
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportMoney;
|
||||||
|
|
||||||
@Feature("money")
|
@Feature("money")
|
||||||
public interface AuthSupportMoney {
|
public interface AuthSupportMoney extends AuthSupport {
|
||||||
default UserSupportMoney fetchUserMoney(User user) {
|
default UserSupportMoney fetchUserMoney(User user) {
|
||||||
return (UserSupportMoney) user;
|
return (UserSupportMoney) user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Feature("registration")
|
@Feature("registration")
|
||||||
public interface AuthSupportRegistration {
|
public interface AuthSupportRegistration extends AuthSupport {
|
||||||
User registration(String login, String email, AuthRequest.AuthPasswordInterface password, Map<String, String> properties);
|
User registration(String login, String email, AuthRequest.AuthPasswordInterface password, Map<String, String> properties);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public interface AuthSupportUserBan {
|
public interface AuthSupportUserBan extends AuthSupport {
|
||||||
UserSupportBanInfo.UserBanInfo banUser(User user, String reason, String moderator, LocalDateTime startTime, LocalDateTime endTime);
|
UserSupportBanInfo.UserBanInfo banUser(User user, String reason, String moderator, LocalDateTime startTime, LocalDateTime endTime);
|
||||||
|
|
||||||
default UserSupportBanInfo.UserBanInfo banUser(User user) {
|
default UserSupportBanInfo.UserBanInfo banUser(User user) {
|
||||||
|
|
|
@ -67,26 +67,28 @@ public void onHardwareReport(HardwareReportResponse response, Client client) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("HardwareInfo received");
|
logger.debug("HardwareInfo received");
|
||||||
if (client.auth.core instanceof AuthSupportHardware) {
|
{
|
||||||
AuthSupportHardware authSupportHardware = (AuthSupportHardware) client.auth;
|
var authSupportHardware = client.auth.isSupport(AuthSupportHardware.class);
|
||||||
UserHardware hardware = authSupportHardware.getHardwareInfoByData(response.hardware);
|
if (authSupportHardware != null) {
|
||||||
if (hardware == null) {
|
UserHardware hardware = authSupportHardware.getHardwareInfoByData(response.hardware);
|
||||||
hardware = authSupportHardware.createHardwareInfo(response.hardware, client.trustLevel.publicKey);
|
if (hardware == null) {
|
||||||
|
hardware = authSupportHardware.createHardwareInfo(response.hardware, client.trustLevel.publicKey);
|
||||||
|
} else {
|
||||||
|
authSupportHardware.addPublicKeyToHardwareInfo(hardware, client.trustLevel.publicKey);
|
||||||
|
}
|
||||||
|
authSupportHardware.connectUserAndHardware(client.getUser(), hardware);
|
||||||
|
if (hardware.isBanned()) {
|
||||||
|
throw new SecurityException("Your hardware banned");
|
||||||
|
}
|
||||||
|
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
||||||
} else {
|
} else {
|
||||||
authSupportHardware.addPublicKeyToHardwareInfo(hardware, client.trustLevel.publicKey);
|
provider.normalizeHardwareInfo(response.hardware);
|
||||||
|
boolean needCreate = !provider.addPublicKeyToHardwareInfo(response.hardware, client.trustLevel.publicKey, client);
|
||||||
|
logger.debug("HardwareInfo needCreate: {}", needCreate ? "true" : "false");
|
||||||
|
if (needCreate)
|
||||||
|
provider.createHardwareInfo(response.hardware, client.trustLevel.publicKey, client);
|
||||||
|
client.trustLevel.hardwareInfo = response.hardware;
|
||||||
}
|
}
|
||||||
authSupportHardware.connectUserAndHardware(client.getUser(), hardware);
|
|
||||||
if (hardware.isBanned()) {
|
|
||||||
throw new SecurityException("Your hardware banned");
|
|
||||||
}
|
|
||||||
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
|
||||||
} else {
|
|
||||||
provider.normalizeHardwareInfo(response.hardware);
|
|
||||||
boolean needCreate = !provider.addPublicKeyToHardwareInfo(response.hardware, client.trustLevel.publicKey, client);
|
|
||||||
logger.debug("HardwareInfo needCreate: {}", needCreate ? "true" : "false");
|
|
||||||
if (needCreate)
|
|
||||||
provider.createHardwareInfo(response.hardware, client.trustLevel.publicKey, client);
|
|
||||||
client.trustLevel.hardwareInfo = response.hardware;
|
|
||||||
}
|
}
|
||||||
} catch (HWIDException e) {
|
} catch (HWIDException e) {
|
||||||
throw new SecurityException(e.getMessage());
|
throw new SecurityException(e.getMessage());
|
||||||
|
@ -97,28 +99,21 @@ public void onHardwareReport(HardwareReportResponse response, Client client) {
|
||||||
@Override
|
@Override
|
||||||
public VerifySecureLevelKeyRequestEvent onSuccessVerify(Client client) {
|
public VerifySecureLevelKeyRequestEvent onSuccessVerify(Client client) {
|
||||||
if (enableHardwareFeature) {
|
if (enableHardwareFeature) {
|
||||||
if (client.isAuth && client.auth.core instanceof AuthSupportHardware) {
|
var authSupportHardware = client.auth.isSupport(AuthSupportHardware.class);
|
||||||
UserHardware hardware = ((AuthSupportHardware) client.auth.core).getHardwareInfoByPublicKey(client.trustLevel.publicKey);
|
if (authSupportHardware != null) {
|
||||||
|
UserHardware hardware = authSupportHardware.getHardwareInfoByPublicKey(client.trustLevel.publicKey);
|
||||||
if (hardware == null) //HWID not found?
|
if (hardware == null) //HWID not found?
|
||||||
return new VerifySecureLevelKeyRequestEvent(true, false, createPublicKeyToken(client.username, client.trustLevel.publicKey));
|
return new VerifySecureLevelKeyRequestEvent(true, false, createPublicKeyToken(client.username, client.trustLevel.publicKey));
|
||||||
if (hardware.isBanned()) {
|
if (hardware.isBanned()) {
|
||||||
throw new SecurityException("Your hardware banned");
|
throw new SecurityException("Your hardware banned");
|
||||||
}
|
}
|
||||||
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
||||||
|
authSupportHardware.connectUserAndHardware(client.getUser(), hardware);
|
||||||
} else if (provider == null) {
|
} else if (provider == null) {
|
||||||
logger.warn("HWIDProvider null. HardwareInfo not checked!");
|
logger.warn("HWIDProvider null. HardwareInfo not checked!");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (client.auth.core instanceof AuthSupportHardware) {
|
client.trustLevel.hardwareInfo = provider.findHardwareInfoByPublicKey(client.trustLevel.publicKey, client);
|
||||||
AuthSupportHardware authSupportHardware = (AuthSupportHardware) client.auth;
|
|
||||||
UserHardware hardware = authSupportHardware.getHardwareInfoByPublicKey(client.trustLevel.publicKey);
|
|
||||||
if (hardware != null) {
|
|
||||||
client.trustLevel.hardwareInfo = hardware.getHardwareInfo();
|
|
||||||
authSupportHardware.connectUserAndHardware(client.getUser(), hardware);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
client.trustLevel.hardwareInfo = provider.findHardwareInfoByPublicKey(client.trustLevel.publicKey, client);
|
|
||||||
}
|
|
||||||
if (client.trustLevel.hardwareInfo == null) //HWID not found?
|
if (client.trustLevel.hardwareInfo == null) //HWID not found?
|
||||||
return new VerifySecureLevelKeyRequestEvent(true, false, createPublicKeyToken(client.username, client.trustLevel.publicKey));
|
return new VerifySecureLevelKeyRequestEvent(true, false, createPublicKeyToken(client.username, client.trustLevel.publicKey));
|
||||||
} catch (HWIDException e) {
|
} catch (HWIDException e) {
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
import pro.gravit.launcher.events.RequestEvent;
|
import pro.gravit.launcher.events.RequestEvent;
|
||||||
import pro.gravit.launcher.events.request.ExitRequestEvent;
|
import pro.gravit.launcher.events.request.ExitRequestEvent;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportGetSessionsFromUser;
|
import pro.gravit.launchserver.auth.core.UserSession;
|
||||||
|
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportExit;
|
||||||
import pro.gravit.launchserver.socket.Client;
|
import pro.gravit.launchserver.socket.Client;
|
||||||
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
|
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
|
||||||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||||
|
@ -48,12 +49,18 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
Client newClient = new Client(null);
|
Client newClient = new Client(null);
|
||||||
newClient.checkSign = client.checkSign;
|
newClient.checkSign = client.checkSign;
|
||||||
handler.setClient(newClient);
|
handler.setClient(newClient);
|
||||||
if (exitAll) {
|
AuthSupportExit supportExit = client.auth.core.isSupport(AuthSupportExit.class);
|
||||||
if (client.auth instanceof AuthSupportGetSessionsFromUser) {
|
if (supportExit != null) {
|
||||||
AuthSupportGetSessionsFromUser support = (AuthSupportGetSessionsFromUser) client.auth;
|
if (exitAll) {
|
||||||
support.clearSessionsByUser(client.getUser());
|
supportExit.exitUser(client.getUser());
|
||||||
|
} else {
|
||||||
|
UserSession session = client.sessionObject;
|
||||||
|
if (session != null) {
|
||||||
|
supportExit.deleteSession(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.CLIENT));
|
||||||
} else {
|
} else {
|
||||||
if (client.session == null && exitAll) {
|
if (client.session == null && exitAll) {
|
||||||
sendError("Session invalid");
|
sendError("Session invalid");
|
||||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
||||||
Subproject commit 566a42d1a09a2504ab4f9f6fb8c9a95d99c7fdca
|
Subproject commit ca22fda40f690015edf7650f4365b8efa8e96ec8
|
Loading…
Reference in a new issue