ProxyAccounts based on userDB

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@841 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 20 years ago
parent 0cb9566546
commit a4b747fe97

@ -62,6 +62,7 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.lang.StringIndexOutOfBoundsException;
import de.anomic.server.serverByteBuffer; import de.anomic.server.serverByteBuffer;
import de.anomic.server.serverCodings; import de.anomic.server.serverCodings;
@ -72,6 +73,8 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.data.userDB;
/** /**
@ -101,7 +104,7 @@ public final class httpd implements serverHandler {
private httpdHandler proxyHandler = null; // a servlet that holds the proxy functions private httpdHandler proxyHandler = null; // a servlet that holds the proxy functions
private httpdHandler fileHandler = null; // a servlet that holds the file serving functions private httpdHandler fileHandler = null; // a servlet that holds the file serving functions
private httpdHandler soapHandler = null; private httpdHandler soapHandler = null;
private static serverSwitch switchboard = null; private static plasmaSwitchboard switchboard = null;
private static String virtualHost = null; private static String virtualHost = null;
public static boolean keepAliveSupport = false; public static boolean keepAliveSupport = false;
@ -126,10 +129,12 @@ public final class httpd implements serverHandler {
// needed for logging // needed for logging
private final serverLog log = new serverLog("HTTPD"); private final serverLog log = new serverLog("HTTPD");
private final serverCodings codings = new serverCodings(true);
// class methods // class methods
public httpd(serverSwitch s, httpdHandler fileHandler, httpdHandler proxyHandler) { public httpd(serverSwitch s, httpdHandler fileHandler, httpdHandler proxyHandler) {
// handler info // handler info
httpd.switchboard = s; httpd.switchboard = (plasmaSwitchboard)s;
this.fileHandler = fileHandler; this.fileHandler = fileHandler;
this.proxyHandler = proxyHandler; this.proxyHandler = proxyHandler;
httpd.virtualHost = switchboard.getConfig("fileHost","localhost"); httpd.virtualHost = switchboard.getConfig("fileHost","localhost");
@ -305,19 +310,39 @@ public final class httpd implements serverHandler {
if (this.proxyAccountBase64MD5 == null) if (this.proxyAccountBase64MD5 == null)
this.proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", ""); this.proxyAccountBase64MD5 = switchboard.getConfig("proxyAccountBase64MD5", "");
if (this.proxyAccountBase64MD5.length() > 0) { if (this.proxyAccountBase64MD5.length() > 0) { //TODO replace with a simple switch
String auth = (String) header.get(httpHeader.PROXY_AUTHORIZATION,"xxxxxx"); String auth = (String) header.get(httpHeader.PROXY_AUTHORIZATION,"xxxxxx");
if (!this.proxyAccountBase64MD5.equals(serverCodings.encodeMD5Hex(auth.trim().substring(6)))) { auth=auth.trim().substring(6);
try{
auth=codings.decodeBase64String(auth);
}catch(StringIndexOutOfBoundsException e){} //no valid Base64
String[] tmp=auth.split(":");
if(tmp.length == 2){
userDB.Entry entry=switchboard.userDB.getEntry(tmp[0]);
if( entry != null && entry.getMD5EncodedUserPwd().equals(serverCodings.encodeMD5Hex(auth)) ){
//TODO: Check Timelimits
return true;
}
}
// ask for authenticate // ask for authenticate
this.session.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString + this.session.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +
httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString).getBytes()); httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString).getBytes());
this.session.out.write((httpHeader.CONTENT_LENGTH + ": 0\r\n").getBytes()); this.session.out.write((httpHeader.CONTENT_LENGTH + ": 0\r\n").getBytes());
this.session.out.write("\r\n".getBytes()); this.session.out.write("\r\n".getBytes());
return false; return false;
} // if (!this.proxyAccountBase64MD5.equals(serverCodings.encodeMD5Hex(auth.trim().substring(6)))) {
} // // ask for authenticate
// this.session.out.write((httpVersion + " 407 Proxy Authentication Required" + serverCore.crlfString +
// httpHeader.PROXY_AUTHENTICATE + ": Basic realm=\"log-in\"" + serverCore.crlfString).getBytes());
// this.session.out.write((httpHeader.CONTENT_LENGTH + ": 0\r\n").getBytes());
// this.session.out.write("\r\n".getBytes());
// return false;
// }
}else{
return true; return true;
} }
//return false; //UNREACHABLE
}
public Boolean UNKNOWN(String requestLine) throws IOException { public Boolean UNKNOWN(String requestLine) throws IOException {

Loading…
Cancel
Save