Permalink
Browse files

Some initial work on getting SSL working.

  • Loading branch information...
1 parent a342707 commit ab414243a7480d1dc27754ac7d4bba715f77a948 @jakewins jakewins committed Sep 13, 2011
@@ -0,0 +1,21 @@
+package org.neo4j.server.rest.web.security;
+
+public class SslConfiguration {
+
+ private final String keyStorePath;
+ private final String keyStorePassword;
+
+ public SslConfiguration(String keyStorePath, String keyStorePassword) {
+ this.keyStorePassword = keyStorePassword;
+ this.keyStorePath = keyStorePath;
+ }
+
+ public String getKeyStorePath() {
+ return keyStorePath;
+ }
+
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+}
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2002-2011 "Neo Technology,"
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
+ *
+ * This file is part of Neo4j.
+ *
+ * Neo4j is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.neo4j.server.rest.web.security;
+
+import org.mortbay.jetty.security.SslSocketConnector;
+
+public class SslSocketConnectorFactory {
+
+ public SslSocketConnector createConnector() {
+ SslSocketConnector connector = new SslSocketConnector();
+ connector.setPort( 8443 );
+ connector.setHost( "" );
+ connector.setKeyPassword("blahblah");
+ connector.setPassword("blahblah");
+ return connector;
+ }
+
+}
@@ -78,74 +78,6 @@
private NeoServer server;
private int jettyMaxThreads = tenThreadsPerProcessor();
- private int tenThreadsPerProcessor()
- {
- return 10 * Runtime.getRuntime()
- .availableProcessors();
- }
-
- @Override
- public void setNeoServer( NeoServer server )
- {
- this.server = server;
- }
-
- @Override
- public void start()
- {
- if ( jetty == null )
- {
- throw new IllegalStateException( "Jetty not initialized." );
- }
- MovedContextHandler redirector = new MovedContextHandler();
-
- jetty.addHandler( redirector );
-
- loadAllMounts();
-
- startJetty();
- }
-
- private void loadAllMounts()
- {
- SessionManager sm = new HashSessionManager();
-
- final SortedSet<String> mountpoints = new TreeSet<String>( new Comparator<String>()
- {
- @Override
- public int compare( final String o1, final String o2 )
- {
- return o2.compareTo( o1 );
- }
- } );
-
- mountpoints.addAll( staticContent.keySet() );
- mountpoints.addAll( jaxRSPackages.keySet() );
-
- for ( String contentKey : mountpoints )
- {
- final boolean isStatic = staticContent.containsKey( contentKey );
- final boolean isJaxrs = jaxRSPackages.containsKey( contentKey );
-
- if ( isStatic && isJaxrs )
- {
- throw new RuntimeException( format( "content-key '%s' is mapped twice (static and jaxrs)", contentKey ) );
- }
- else if ( isStatic )
- {
- loadStaticContent( sm, contentKey );
- }
- else if ( isJaxrs )
- {
- loadJAXRSPackage( sm, contentKey );
- }
- else
- {
- throw new RuntimeException( format( "content-key '%s' is not mapped", contentKey ) );
- }
- }
- }
-
@Override
public void init()
{
@@ -156,24 +88,14 @@ public void init()
connector.setPort( jettyPort );
connector.setHost( jettyAddr );
+
jetty.addConnector( connector );
+ //jetty.addConnector( sslConnector );
jetty.setThreadPool( new QueuedThreadPool( jettyMaxThreads ) );
}
}
- protected void startJetty()
- {
- try
- {
- jetty.start();
- }
- catch ( Exception e )
- {
- throw new RuntimeException( e );
- }
- }
-
@Override
public void stop()
{
@@ -225,6 +147,106 @@ public void addJAXRSPackages( List<String> packageNames, String mountPoint )
jaxRSPackages.put( mountPoint, servletHolder );
}
+ @Override
+ public void setNeoServer( NeoServer server )
+ {
+ this.server = server;
+ }
+
+ @Override
+ public void start()
+ {
+ if ( jetty == null )
+ {
+ throw new IllegalStateException( "Jetty not initialized." );
+ }
+ MovedContextHandler redirector = new MovedContextHandler();
+
+ jetty.addHandler( redirector );
+
+ loadAllMounts();
+
+ startJetty();
+ }
+
+ @Override
+ public void addStaticContent( String contentLocation, String serverMountPoint )
+ {
+ staticContent.put( serverMountPoint, contentLocation );
+ }
+
+ @Override
+ public void invokeDirectly( String targetPath, HttpServletRequest request, HttpServletResponse response )
+ throws IOException, ServletException
+ {
+ jetty.handle( targetPath, request, response, Handler.REQUEST );
+ }
+
+
+ @Override
+ public Server getJetty()
+ {
+ return jetty;
+ }
+
+ protected void startJetty()
+ {
+ try
+ {
+ jetty.start();
+ }
+ catch ( Exception e )
+ {
+ throw new RuntimeException( e );
+ }
+ }
+
+ private int tenThreadsPerProcessor()
+ {
+ return 10 * Runtime.getRuntime()
+ .availableProcessors();
+ }
+
+ private void loadAllMounts()
+ {
+ SessionManager sm = new HashSessionManager();
+
+ final SortedSet<String> mountpoints = new TreeSet<String>( new Comparator<String>()
+ {
+ @Override
+ public int compare( final String o1, final String o2 )
+ {
+ return o2.compareTo( o1 );
+ }
+ } );
+
+ mountpoints.addAll( staticContent.keySet() );
+ mountpoints.addAll( jaxRSPackages.keySet() );
+
+ for ( String contentKey : mountpoints )
+ {
+ final boolean isStatic = staticContent.containsKey( contentKey );
+ final boolean isJaxrs = jaxRSPackages.containsKey( contentKey );
+
+ if ( isStatic && isJaxrs )
+ {
+ throw new RuntimeException( format( "content-key '%s' is mapped twice (static and jaxrs)", contentKey ) );
+ }
+ else if ( isStatic )
+ {
+ loadStaticContent( sm, contentKey );
+ }
+ else if ( isJaxrs )
+ {
+ loadJAXRSPackage( sm, contentKey );
+ }
+ else
+ {
+ throw new RuntimeException( format( "content-key '%s' is not mapped", contentKey ) );
+ }
+ }
+ }
+
private String trimTrailingSlashToKeepJettyHappy( String mountPoint )
{
if ( mountPoint.equals( "/" ) )
@@ -260,19 +282,6 @@ private String ensureRelativeUri( String mountPoint )
}
}
- @Override
- public void addStaticContent( String contentLocation, String serverMountPoint )
- {
- staticContent.put( serverMountPoint, contentLocation );
- }
-
- @Override
- public void invokeDirectly( String targetPath, HttpServletRequest request, HttpServletResponse response )
- throws IOException, ServletException
- {
- jetty.handle( targetPath, request, response, Handler.REQUEST );
- }
-
private void loadStaticContent( SessionManager sm, String mountPoint )
{
String contentLocation = staticContent.get( mountPoint );
@@ -334,12 +343,6 @@ private String toCommaSeparatedList( List<String> packageNames )
}
@Override
- public Server getJetty()
- {
- return jetty;
- }
-
- @Override
public void addSecurityRules( final SecurityRule... rules )
{
jetty.addLifeCycleListener( new JettyLifeCycleListenerAdapter()
@@ -389,5 +392,4 @@ public void lifeCycleStarted( LifeCycle arg0 )
}
} );
}
-
}
@@ -30,6 +30,7 @@
import org.neo4j.server.NeoServer;
import org.neo4j.server.guard.Guard;
import org.neo4j.server.rest.security.SecurityRule;
+import org.neo4j.server.rest.web.security.SslConfiguration;
public interface WebServer
{
@@ -40,6 +41,12 @@
void setPort( int portNo );
void setAddress( String addr );
+
+ void setEnableSsl( boolean enable );
+
+ void setSslPort( int portNo );
+
+ void setSslConfiguration( SslConfiguration config );
void start();
@@ -60,4 +67,5 @@ void invokeDirectly( String targetUri, HttpServletRequest request, HttpServletRe
@Deprecated
Server getJetty();
+
}

0 comments on commit ab41424

Please sign in to comment.