Updated Auth interface. Updated StorageMedium interface to allow

retrieval of passwords. Implemented PersistenceAuth.
This commit is contained in:
Joe0 2011-12-16 15:59:00 -06:00
parent d4e040611f
commit 23d75a88e0
8 changed files with 47 additions and 11 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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){

View File

@ -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;
}

View File

@ -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);
}

View File

@ -15,6 +15,11 @@ class DummyStorageMedium implements StorageMedium {
return true;
}
@Override
public String getPass(long user) {
return "";
}
@Override
public void shutdown() {

View File

@ -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;
}
}