Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

* add copyright info * implement basic authentication * update jetty to 7.3.0

Florian Richter68ca0fbb2e7d
diff --git a/.classpath b/.classpath
index c54c6c76d..c648c2c63 100644
--- a/.classpath
+++ b/.classpath
@@ -43,10 +43,11 @@
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="lib/icu4j-core.jar"/>
- <classpathentry kind="lib" path="lib/jetty-http-7.0.2.v20100331.jar"/>
- <classpathentry kind="lib" path="lib/jetty-server-7.0.2.v20100331.jar"/>
- <classpathentry kind="lib" path="lib/jetty-util-7.0.2.v20100331.jar"/>
- <classpathentry kind="lib" path="lib/jetty-io-7.0.2.v20100331.jar"/>
- <classpathentry kind="lib" path="lib/jetty-continuation-7.0.2.v20100331.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-http-7.3.0.v20110203.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-server-7.3.0.v20110203.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-util-7.3.0.v20110203.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-io-7.3.0.v20110203.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-continuation-7.3.0.v20110203.jar"/>
+ <classpathentry kind="lib" path="lib/jetty-security-7.3.0.v20110203.jar"/>
<classpathentry kind="output" path="gen"/>
</classpath>
diff --git a/build.xml b/build.xml
index e879ac737..9ce16801a 100644
--- a/build.xml
+++ b/build.xml
@@ -196,11 +196,12 @@
<pathelement location="${lib}/icu4j-core.jar" />
<pathelement location="${lib}/J7Zip-modified.jar" />
<pathelement location="${lib}/jakarta-oro-2.0.8.jar" />
- <pathelement location="${lib}/jetty-continuation-7.0.2.v20100331.jar" />
- <pathelement location="${lib}/jetty-server-7.0.2.v20100331.jar" />
- <pathelement location="${lib}/jetty-http-7.0.2.v20100331.jar" />
- <pathelement location="${lib}/jetty-util-7.0.2.v20100331.jar" />
- <pathelement location="${lib}/jetty-io-7.0.2.v20100331.jar" />
+ <pathelement location="${lib}/jetty-continuation-7.3.0.v20110203.jar" />
+ <pathelement location="${lib}/jetty-server-7.3.0.v20110203.jar" />
+ <pathelement location="${lib}/jetty-http-7.3.0.v20110203.jar" />
+ <pathelement location="${lib}/jetty-util-7.3.0.v20110203.jar" />
+ <pathelement location="${lib}/jetty-io-7.3.0.v20110203.jar" />
+ <pathelement location="${lib}/jetty-security-7.3.0.v20110203.jar" />
<pathelement location="${lib}/jcifs-1.3.14.jar" />
<pathelement location="${lib}/jsch-0.1.42.jar" />
<pathelement location="${lib}/log4j-1.2.16.jar" />
diff --git a/lib/jetty-continuation-7.0.2.v20100331.jar b/lib/jetty-continuation-7.3.0.v20110203.jar
similarity index 56%
rename from lib/jetty-continuation-7.0.2.v20100331.jar
rename to lib/jetty-continuation-7.3.0.v20110203.jar
index 91764bb2d..ca5011295 100644
Binary files a/lib/jetty-continuation-7.0.2.v20100331.jar and b/lib/jetty-continuation-7.3.0.v20110203.jar differ
diff --git a/lib/jetty-http-7.0.2.v20100331.jar b/lib/jetty-http-7.0.2.v20100331.jar
deleted file mode 100644
index a872f816a..000000000
Binary files a/lib/jetty-http-7.0.2.v20100331.jar and /dev/null differ
diff --git a/lib/jetty-http-7.3.0.v20110203.jar b/lib/jetty-http-7.3.0.v20110203.jar
new file mode 100644
index 000000000..7008d1794
Binary files /dev/null and b/lib/jetty-http-7.3.0.v20110203.jar differ
diff --git a/lib/jetty-io-7.0.2.v20100331.jar b/lib/jetty-io-7.0.2.v20100331.jar
deleted file mode 100644
index 52e620068..000000000
Binary files a/lib/jetty-io-7.0.2.v20100331.jar and /dev/null differ
diff --git a/lib/jetty-io-7.3.0.v20110203.jar b/lib/jetty-io-7.3.0.v20110203.jar
new file mode 100644
index 000000000..ed08c1f4d
Binary files /dev/null and b/lib/jetty-io-7.3.0.v20110203.jar differ
diff --git a/lib/jetty-security-7.3.0.v20110203.jar b/lib/jetty-security-7.3.0.v20110203.jar
new file mode 100644
index 000000000..e978607dc
Binary files /dev/null and b/lib/jetty-security-7.3.0.v20110203.jar differ
diff --git a/lib/jetty-server-7.0.2.v20100331.jar b/lib/jetty-server-7.0.2.v20100331.jar
deleted file mode 100644
index 6f56841cc..000000000
Binary files a/lib/jetty-server-7.0.2.v20100331.jar and /dev/null differ
diff --git a/lib/jetty-server-7.3.0.v20110203.jar b/lib/jetty-server-7.3.0.v20110203.jar
new file mode 100644
index 000000000..c6c9eea39
Binary files /dev/null and b/lib/jetty-server-7.3.0.v20110203.jar differ
diff --git a/lib/jetty-util-7.0.2.v20100331.jar b/lib/jetty-util-7.0.2.v20100331.jar
deleted file mode 100644
index fe5981d21..000000000
Binary files a/lib/jetty-util-7.0.2.v20100331.jar and /dev/null differ
diff --git a/lib/jetty-util-7.3.0.v20110203.jar b/lib/jetty-util-7.3.0.v20110203.jar
new file mode 100644
index 000000000..719113881
Binary files /dev/null and b/lib/jetty-util-7.3.0.v20110203.jar differ
diff --git a/source/net/yacy/http/AuthenticationHandler.java b/source/net/yacy/http/AuthenticationHandler.java
deleted file mode 100644
index fc356ea5c..000000000
--- a/source/net/yacy/http/AuthenticationHandler.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package net.yacy.http;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-
-public class AuthenticationHandler extends AbstractHandler {
-
- @Override
- public void handle(String target, Request baseRequest, HttpServletRequest request,
- HttpServletResponse response) throws IOException, ServletException {
- // TODO Auto-generated method stub
-
- }
-
-}
diff --git a/source/net/yacy/http/ContentModHandler.java b/source/net/yacy/http/ContentModHandler.java
index f67206212..aa3052b62 100644
--- a/source/net/yacy/http/ContentModHandler.java
+++ b/source/net/yacy/http/ContentModHandler.java
@@ -1,3 +1,27 @@
+//
+// ContentModHandler
+// Copyright 2011 by Florian Richter
+// First released 13.04.2011 at http://yacy.net
+//
+// $LastChangedDate$
+// $LastChangedRevision$
+// $LastChangedBy$
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program in the file lgpl21.txt
+// If not, see <http://www.gnu.org/licenses/>.
+//
+
package net.yacy.http;
import java.io.ByteArrayOutputStream;
@@ -16,8 +40,8 @@ import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
/**
- * jetty http handler:
- * Handles Server-side Includes, used for trickling display of search results
+ * abstract jetty http handler:
+ * used to change answer, provided by other handler
*/
public abstract class ContentModHandler extends HandlerWrapper implements Handler, HandlerContainer {
@@ -36,19 +60,28 @@ public abstract class ContentModHandler extends HandlerWrapper implements Handle
// wrap response
ContentModResponseWrapper wrapped_response = new ContentModResponseWrapper(response);
super.handle(target, baseRequest, request, wrapped_response);
- wrapped_response.commit(this, request, response);
+ this.doContentMod(wrapped_response.getBuffer(), request, response);
}
+ /**
+ * method doing editing of answer, overwrite this!
+ * @param in output of nested handler, to be processed
+ * @param request original request
+ * @param response original response object with outputstream to fill
+ * @throws IOException
+ * @throws ServletException
+ */
protected abstract void doContentMod(byte[] in, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException ;
+ /**
+ * response object, which holds outputstream in bytearray back
+ */
private class ContentModResponseWrapper extends HttpServletResponseWrapper {
- private HttpServletResponse wrappedResponse;
private ByteArrayServletOutputStream wrappedOutputStream = new ByteArrayServletOutputStream();
public ContentModResponseWrapper(HttpServletResponse response) {
super(response);
- wrappedResponse = response;
}
@Override
@@ -56,11 +89,18 @@ public abstract class ContentModHandler extends HandlerWrapper implements Handle
return wrappedOutputStream;
}
- public void commit(ContentModHandler cmh, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- cmh.doContentMod(wrappedOutputStream.getBuffer(), request, response);
+ /**
+ * get bytearray hold back from outputstream
+ * @return
+ */
+ public byte[] getBuffer() {
+ return wrappedOutputStream.getBuffer();
}
}
+ /**
+ * ByteArrayOutputStream wrapped into a ServletOutputStream
+ */
private class ByteArrayServletOutputStream extends ServletOutputStream {
private ByteArrayOutputStream buffer = new ByteArrayOutputStream();
diff --git a/source/net/yacy/http/HttpServer.java b/source/net/yacy/http/HttpServer.java
index 51401ee10..3b4bf3c27 100644
--- a/source/net/yacy/http/HttpServer.java
+++ b/source/net/yacy/http/HttpServer.java
@@ -1,5 +1,33 @@
+//
+// HttpServer
+// Copyright 2011 by Florian Richter
+// First released 13.04.2011 at http://yacy.net
+//
+// $LastChangedDate$
+// $LastChangedRevision$
+// $LastChangedBy$
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program in the file lgpl21.txt
+// If not, see <http://www.gnu.org/licenses/>.
+//
+
package net.yacy.http;
+import org.eclipse.jetty.http.security.Constraint;
+import org.eclipse.jetty.security.ConstraintMapping;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
@@ -9,7 +37,7 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
/**
- * interface to embedded jetty http server
+ * class to embedded jetty http server into YaCy
*/
public class HttpServer {
@@ -30,25 +58,42 @@ public class HttpServer {
resource_handler.setWelcomeFiles(new String[]{ "index.html" });
resource_handler.setResourceBase("htroot/");
+
+ Constraint constraint = new Constraint();
+ constraint.setName(Constraint.__BASIC_AUTH);;
+ constraint.setRoles(new String[]{"admin"});
+ constraint.setAuthenticate(true);
+
+ ConstraintMapping cm = new ConstraintMapping();
+ cm.setConstraint(constraint);
+ cm.setPathSpec("/*");
+ ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
+ securityHandler.setLoginService(new YaCyLoginService());
+ securityHandler.setRealmName("YaCy Admin Interface");
+ securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
+ securityHandler.setHandler(new SSIHandler(new TemplateHandler()));
+
+ // context handler for dispatcher and security
ContextHandler context = new ContextHandler();
context.setContextPath("/");
- context.setHandler(new SSIHandler(new TemplateHandler()));
+ context.setHandler(securityHandler);
HandlerList handlers = new HandlerList();
- handlers.setHandlers(new Handler[] { context, resource_handler, new DefaultHandler() });
+ handlers.setHandlers(new Handler[] {context, resource_handler, new DefaultHandler() });
server.setHandler(handlers);
}
+ /**
+ * start http server
+ */
public void start() throws Exception {
server.start();
}
-
- public void initYaCyServer() {
- // TODO: delete?
- // create directories
- }
+ /**
+ * stop http server and wait for it
+ */
public void stop() throws Exception {
server.stop();
server.join();
diff --git a/source/net/yacy/http/SSIHandler.java b/source/net/yacy/http/SSIHandler.java
index c695aaa03..5d74f97e0 100644
--- a/source/net/yacy/http/SSIHandler.java
+++ b/source/net/yacy/http/SSIHandler.java
@@ -1,26 +1,26 @@
-/**
- * SSIHandler
- * Copyright 2011 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
- * First released 13.04.2011 at http://yacy.net
- *
- * $LastChangedDate$
- * $LastChangedRevision$
- * $LastChangedBy$
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program in the file lgpl21.txt
- * If not, see <http://www.gnu.org/licenses/>.
- */
+//
+// SSIHandler
+// Copyright 2011 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+// First released 13.04.2011 at http://yacy.net
+//
+// $LastChangedDate$
+// $LastChangedRevision$
+// $LastChangedBy$
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program in the file lgpl21.txt
+// If not, see <http://www.gnu.org/licenses/>.
+//
package net.yacy.http;
@@ -37,8 +37,16 @@ import org.eclipse.jetty.server.HandlerContainer;
import net.yacy.kelondro.util.ByteBuffer;
+/**
+ * Jetty Http HandlerWrapper applying server-side includes,
+ * used for trickling display of search results
+ */
public class SSIHandler extends ContentModHandler implements Handler, HandlerContainer {
+ /**
+ * constructor
+ * @param h Handler to wrap (it's output is scanned for SSI-marks)
+ */
public SSIHandler(Handler h) {
super(h);
}
@@ -71,6 +79,7 @@ public class SSIHandler extends ContentModHandler implements Handler, HandlerCon
RequestDispatcher dispatcher = request.getRequestDispatcher("/"+path);
dispatcher.include(request, response);
} catch (Exception e) {
+ // for debugging TODO: remove?
e.printStackTrace();
throw new ServletException();
}
diff --git a/source/net/yacy/http/TemplateHandler.java b/source/net/yacy/http/TemplateHandler.java
index 6ceb65e28..2f9467cf5 100644
--- a/source/net/yacy/http/TemplateHandler.java
+++ b/source/net/yacy/http/TemplateHandler.java
@@ -1,3 +1,28 @@
+//
+// TemplateHandler
+// Copyright 2005 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany
+// Copyright 2011 by Florian Richter
+// First released 13.04.2011 at http://yacy.net
+//
+// $LastChangedDate$
+// $LastChangedRevision$
+// $LastChangedBy$
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this program in the file lgpl21.txt
+// If not, see <http://www.gnu.org/licenses/>.
+//
+
package net.yacy.http;
import java.awt.Image;
diff --git a/source/net/yacy/http/YaCyLoginService.java b/source/net/yacy/http/YaCyLoginService.java
new file mode 100644
index 000000000..66484914c
--- /dev/null
+++ b/source/net/yacy/http/YaCyLoginService.java
@@ -0,0 +1,35 @@
+package net.yacy.http;
+
+import java.io.IOException;
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.eclipse.jetty.http.security.Credential;
+import org.eclipse.jetty.security.IdentityService;
+import org.eclipse.jetty.security.MappedLoginService;
+import org.eclipse.jetty.server.UserIdentity;
+
+public class YaCyLoginService extends MappedLoginService {
+
+ @Override
+ protected UserIdentity loadUser(String username) {
+ if(username.equals("admin")) {
+ Credential credential = Credential.getCredential("admin");
+ Principal userPrincipal = new MappedLoginService.KnownUser("admin", credential);
+ Subject subject = new Subject();
+ subject.getPrincipals().add(userPrincipal);
+ subject.getPrivateCredentials().add(credential);
+ subject.setReadOnly();
+ IdentityService is = getIdentityService();
+ return is.newUserIdentity(subject, userPrincipal, new String[]{"admin"});
+ }
+ return null;
+ }
+
+ @Override
+ protected void loadUsers() throws IOException {
+ // don't load any users into MappedLoginService on boot
+ }
+
+}