Мульти AuthProvider's

This commit is contained in:
Gravit 2018-09-23 18:42:10 +07:00
parent 46a470f0af
commit 363a3ed462
3 changed files with 22 additions and 4 deletions

View file

@ -75,7 +75,7 @@ public static final class Config extends ConfigObject {
@LauncherAPI @LauncherAPI
public final AuthHandler authHandler; public final AuthHandler authHandler;
@LauncherAPI @LauncherAPI
public final AuthProvider authProvider; public final AuthProvider[] authProvider;
@LauncherAPI @LauncherAPI
public final TextureProvider textureProvider; public final TextureProvider textureProvider;
@LauncherAPI @LauncherAPI
@ -125,7 +125,8 @@ private Config(BlockConfigEntry block, Path coredir) {
// Set handlers & providers // Set handlers & providers
authHandler = AuthHandler.newHandler(block.getEntryValue("authHandler", StringConfigEntry.class), authHandler = AuthHandler.newHandler(block.getEntryValue("authHandler", StringConfigEntry.class),
block.getEntry("authHandlerConfig", BlockConfigEntry.class)); block.getEntry("authHandlerConfig", BlockConfigEntry.class));
authProvider = AuthProvider.newProvider(block.getEntryValue("authProvider", StringConfigEntry.class), authProvider = new AuthProvider[1];
authProvider[0] = AuthProvider.newProvider(block.getEntryValue("authProvider", StringConfigEntry.class),
block.getEntry("authProviderConfig", BlockConfigEntry.class)); block.getEntry("authProviderConfig", BlockConfigEntry.class));
textureProvider = TextureProvider.newProvider(block.getEntryValue("textureProvider", StringConfigEntry.class), textureProvider = TextureProvider.newProvider(block.getEntryValue("textureProvider", StringConfigEntry.class),
block.getEntry("textureProviderConfig", BlockConfigEntry.class)); block.getEntry("textureProviderConfig", BlockConfigEntry.class));
@ -459,7 +460,7 @@ public void close() {
LogHelper.error(e); LogHelper.error(e);
} }
try { try {
config.authProvider.close(); for(AuthProvider p : config.authProvider) p.close();
} catch (IOException e) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);
} }

View file

@ -40,9 +40,11 @@ public AuthResponse(LaunchServer server, long session, HInput input, HOutput out
public void reply() throws Exception { public void reply() throws Exception {
String login = input.readString(SerializeLimits.MAX_LOGIN); String login = input.readString(SerializeLimits.MAX_LOGIN);
String client = input.readString(SerializeLimits.MAX_CLIENT); String client = input.readString(SerializeLimits.MAX_CLIENT);
int auth_id = input.readInt();
long hwid_hdd = input.readLong(); long hwid_hdd = input.readLong();
long hwid_cpu = input.readLong(); long hwid_cpu = input.readLong();
long hwid_bios = input.readLong(); long hwid_bios = input.readLong();
if(auth_id + 1 > server.config.authProvider.length || auth_id < 0) auth_id = 0;
byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH);
// Decrypt password // Decrypt password
String password; String password;
@ -62,7 +64,8 @@ public void reply() throws Exception {
AuthProvider.authError(server.config.authRejectString); AuthProvider.authError(server.config.authRejectString);
return; return;
} }
result = server.config.authProvider.auth(login, password, ip); AuthProvider provider = server.config.authProvider[auth_id];
result = provider.auth(login, password, ip);
if (!VerifyHelper.isValidUsername(result.username)) { if (!VerifyHelper.isValidUsername(result.username)) {
AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
return; return;

View file

@ -33,18 +33,31 @@ private Result(PlayerProfile pp, String accessToken) {
private final String login; private final String login;
private final byte[] encryptedPassword; private final byte[] encryptedPassword;
private final int auth_id;
@LauncherAPI @LauncherAPI
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword) { public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword) {
super(config); super(config);
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
this.encryptedPassword = encryptedPassword.clone(); this.encryptedPassword = encryptedPassword.clone();
auth_id = 0;
}
@LauncherAPI
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword,int auth_id) {
super(config);
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
this.encryptedPassword = encryptedPassword.clone();
this.auth_id = auth_id;
} }
@LauncherAPI @LauncherAPI
public AuthRequest(String login, byte[] encryptedPassword) { public AuthRequest(String login, byte[] encryptedPassword) {
this(null, login, encryptedPassword); this(null, login, encryptedPassword);
} }
@LauncherAPI
public AuthRequest(String login, byte[] encryptedPassword,int auth_id) {
this(null, login, encryptedPassword,auth_id);
}
@Override @Override
public Integer getType() { public Integer getType() {
@ -55,6 +68,7 @@ public Integer getType() {
protected Result requestDo(HInput input, HOutput output) throws IOException { protected Result requestDo(HInput input, HOutput output) throws IOException {
output.writeString(login, SerializeLimits.MAX_LOGIN); output.writeString(login, SerializeLimits.MAX_LOGIN);
output.writeString(ClientLauncher.title, SerializeLimits.MAX_CLIENT); output.writeString(ClientLauncher.title, SerializeLimits.MAX_CLIENT);
output.writeInt(auth_id);
output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetHddId() : 0); output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetHddId() : 0);
output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetCpuid() : 0); output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetCpuid() : 0);
output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetSmbiosId() : 0); output.writeLong(JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE ? GuardBind.avnGetSmbiosId() : 0);