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 boolean validate(String hashToUsername, String pass,
|
||||
StringBuilder stringBuilder);
|
||||
boolean validate(long hash, String pass, StringBuilder stringBuilder);
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,7 @@ import org.moparscape.msc.ls.auth.Auth;
|
||||
class DummyAuth implements Auth {
|
||||
|
||||
@Override
|
||||
public boolean validate(String hashToUsername, String pass,
|
||||
StringBuilder stringBuilder) {
|
||||
public boolean validate(long hash, String pass, StringBuilder stringBuilder) {
|
||||
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.URLEncoder;
|
||||
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
import org.moparscape.msc.ls.auth.Auth;
|
||||
import org.moparscape.msc.ls.util.Config;
|
||||
|
||||
@ -14,7 +15,8 @@ class WebsiteAuth implements Auth {
|
||||
|
||||
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
|
||||
// this will never be so in production
|
||||
if(Config.AUTH_META_DATA == null){
|
||||
|
@ -67,7 +67,8 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
static {
|
||||
try {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -79,8 +80,7 @@ public class PlayerLoginHandler implements PacketHandler {
|
||||
|
||||
if (!Server.storage.playerExists(user))
|
||||
return 2;
|
||||
if (!auth.validate(DataConversions.hashToUsername(user), pass,
|
||||
new StringBuilder())) {
|
||||
if (!auth.validate(user, pass, new StringBuilder())) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
@ -37,4 +37,5 @@ public interface StorageMedium {
|
||||
public PlayerSave loadPlayer(long user);
|
||||
public void logLogin(long user, String ip);
|
||||
public void logIn(String ip, long user);
|
||||
public String getPass(long user);
|
||||
}
|
||||
|
@ -15,6 +15,11 @@ class DummyStorageMedium implements StorageMedium {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPass(long user) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
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