mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-12-21 23:18:52 -05:00
Updated Auth interface. Updated StorageMedium interface to allow
retrieval of passwords. Implemented PersistenceAuth.
This commit is contained in:
parent
d4e040611f
commit
23d75a88e0
@ -2,7 +2,6 @@ package org.moparscape.msc.ls.auth;
|
|||||||
|
|
||||||
public interface Auth {
|
public interface Auth {
|
||||||
|
|
||||||
public boolean validate(String hashToUsername, String pass,
|
boolean validate(long hash, String pass, StringBuilder stringBuilder);
|
||||||
StringBuilder stringBuilder);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,7 @@ import org.moparscape.msc.ls.auth.Auth;
|
|||||||
class DummyAuth implements Auth {
|
class DummyAuth implements Auth {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validate(String hashToUsername, String pass,
|
public boolean validate(long hash, String pass, StringBuilder stringBuilder) {
|
||||||
StringBuilder stringBuilder) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.moparscape.msc.ls.auth.impl;
|
||||||
|
|
||||||
|
import org.moparscape.msc.ls.Server;
|
||||||
|
import org.moparscape.msc.ls.auth.Auth;
|
||||||
|
|
||||||
|
public class PersistenceAuth implements Auth {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate(long hash, String pass,
|
||||||
|
StringBuilder stringBuilder) {
|
||||||
|
return Server.storage.getPass(hash).equals(pass);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,6 +7,7 @@ import java.net.HttpURLConnection;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import org.moparscape.msc.gs.tools.DataConversions;
|
||||||
import org.moparscape.msc.ls.auth.Auth;
|
import org.moparscape.msc.ls.auth.Auth;
|
||||||
import org.moparscape.msc.ls.util.Config;
|
import org.moparscape.msc.ls.util.Config;
|
||||||
|
|
||||||
@ -14,7 +15,8 @@ class WebsiteAuth implements Auth {
|
|||||||
|
|
||||||
private final double version = 1.0;
|
private final double version = 1.0;
|
||||||
|
|
||||||
public boolean validate(String user, String pass, StringBuilder response) {
|
public boolean validate(long hash, String pass, StringBuilder response) {
|
||||||
|
String user = DataConversions.hashToUsername(hash);
|
||||||
// if authURL is null, then we are just running the server for test purposes
|
// if authURL is null, then we are just running the server for test purposes
|
||||||
// this will never be so in production
|
// this will never be so in production
|
||||||
if(Config.AUTH_META_DATA == null){
|
if(Config.AUTH_META_DATA == null){
|
||||||
|
@ -67,7 +67,8 @@ public class PlayerLoginHandler implements PacketHandler {
|
|||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
auth = AuthFactory.create(Config.AUTH_CLASS);
|
auth = AuthFactory.create(Config.AUTH_CLASS);
|
||||||
System.out.println("Authentication Scheme: " + auth.getClass().getSimpleName());
|
System.out.println("Authentication Scheme: "
|
||||||
|
+ auth.getClass().getSimpleName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -79,8 +80,7 @@ public class PlayerLoginHandler implements PacketHandler {
|
|||||||
|
|
||||||
if (!Server.storage.playerExists(user))
|
if (!Server.storage.playerExists(user))
|
||||||
return 2;
|
return 2;
|
||||||
if (!auth.validate(DataConversions.hashToUsername(user), pass,
|
if (!auth.validate(user, pass, new StringBuilder())) {
|
||||||
new StringBuilder())) {
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,4 +37,5 @@ public interface StorageMedium {
|
|||||||
public PlayerSave loadPlayer(long user);
|
public PlayerSave loadPlayer(long user);
|
||||||
public void logLogin(long user, String ip);
|
public void logLogin(long user, String ip);
|
||||||
public void logIn(String ip, long user);
|
public void logIn(String ip, long user);
|
||||||
|
public String getPass(long user);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,11 @@ class DummyStorageMedium implements StorageMedium {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPass(long user) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
|
||||||
|
@ -714,4 +714,20 @@ class MySQL implements StorageMedium {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPass(long user) {
|
||||||
|
ResultSet result = resultSetFromLongs(Statements.playerData, user);
|
||||||
|
try {
|
||||||
|
if (!result.next()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return result.getString("pass");
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user