You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/04/17 19:18:42 UTC
svn commit: r935211 - in /james/server/trunk:
imapserver/src/main/java/org/apache/james/imapserver/netty/
netty-socket/src/main/java/org/apache/james/socket/netty/
pop3server/src/main/java/org/apache/james/pop3server/netty/
remotemanager/src/main/java/...
Author: norman
Date: Sat Apr 17 17:18:41 2010
New Revision: 935211
URL: http://svn.apache.org/viewvc?rev=935211&view=rev
Log:
Add support for TLS/SSL and STARTTLS when using Netty
Adding javadocs
Added:
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractSSLAwareChannelPipelineFactory.java
Modified:
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NioImapServer.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java
james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java
james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NettyRemoteManagerSession.java
james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NioRemoteManager.java
james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerChannelUpstreamHandler.java
james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerResponseEncoder.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java
james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java
Modified: james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NioImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NioImapServer.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NioImapServer.java (original)
+++ james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/NioImapServer.java Sat Apr 17 17:18:41 2010
@@ -32,7 +32,12 @@ import org.apache.james.imap.main.ImapRe
import org.apache.james.socket.netty.AbstractAsyncServer;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.handler.ssl.SslHandler;
+/**
+ * NIO IMAP Server which use Netty
+ *
+ */
public class NioImapServer extends AbstractAsyncServer implements ImapConstants{
private static final String softwaretype = "JAMES "+VERSION+" Server "; //+ Constants.SOFTWARE_VERSION;
@@ -88,7 +93,11 @@ public class NioImapServer extends Abstr
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
+ if (isSSLSocket()) {
+ pipeline.addFirst("sslHandler", new SslHandler(getSSLContext().createSSLEngine()));
+ }
final ImapRequestHandler handler = new ImapRequestHandler(decoder, processor, encoder);
+
pipeline.addLast("coreHandler", new ImapChannelUpstreamHandler(hello, handler, getLogger(), NioImapServer.this.getTimeout()));
return pipeline;
}
Modified: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java (original)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java Sat Apr 17 17:18:41 2010
@@ -18,14 +18,18 @@
****************************************************************/
package org.apache.james.socket.netty;
+import java.io.FileInputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
+import java.security.KeyStore;
import java.util.concurrent.Executors;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
@@ -105,7 +109,7 @@ public abstract class AbstractAsyncServe
private int timeout;
- //private SslContextFactory contextFactory;
+ private SSLContext context;
private ServerBootstrap bootstrap;
@@ -262,17 +266,8 @@ public abstract class AbstractAsyncServe
public final void init() throws Exception {
if (isEnabled()) {
preInit();
- //buildSSLContextFactory();
- /*
- // add connectionfilter in the first of the chain
- DefaultIoFilterChainBuilder builder = createIoFilterChainBuilder();
- builder.addFirst("connectionFilter", new ConnectionFilter(getLogger(), connectionLimit, connPerIP));
- builder.addLast("streamFilter", new StreamWriteFilter());
- // add the sslfilter if needed
- if (isSSLSocket()) {
- builder.addFirst( "sslFilter", new SslFilter(contextFactory.newInstance()));
- }
- */
+ buildSSLContext();
+
bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
@@ -431,25 +426,29 @@ public abstract class AbstractAsyncServe
}
/**
- * Build the SslContextFactory
+ * Build the SSLEngine
*
* @throws Exception
*/
- /*
- private void buildSSLContextFactory() throws Exception{
+
+ private void buildSSLContext() throws Exception {
if (useStartTLS) {
- KeyStoreFactory kfactory = new KeyStoreFactory();
- kfactory.setDataFile(fileSystem.getFile(keystore));
- kfactory.setPassword(secret);
+ String algorithm = "SunX509";
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(new FileInputStream(fileSystem.getFile(keystore)), secret.toCharArray());
+
+ // Set up key manager factory to use our key store
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
+ kmf.init(ks, secret.toCharArray());
+
+ // Initialize the SSLContext to work with our key managers.
+ context = SSLContext.getInstance("TLS");
+ context.init(kmf.getKeyManagers(), null, null);
- contextFactory = new SslContextFactory();
- contextFactory.setKeyManagerFactoryKeyStore(kfactory.newInstance());
- contextFactory.setKeyManagerFactoryAlgorithm("SunX509");
- contextFactory.setTrustManagerFactory(new BogusTrustManagerFactory());
- contextFactory.setKeyManagerFactoryKeyStorePassword(secret);
+
}
}
- */
+
/**
@@ -464,30 +463,6 @@ public abstract class AbstractAsyncServe
*
* @return contextFactory
*/
- /*
- protected SslContextFactory getSslContextFactory() {
- return contextFactory;
- }
- */
-
- /**
- * Create IoFilterChainBuilder which will get used for the Acceptor.
- * The builder will contain a ProtocalCodecFilter which handles Line based Protocols and
- * a ConnectionFilter which limit the connection count / connection count per ip.
- *
- * Developers should override this to add more filters to the chain.
- *
- * @return ioFilterChainBuilder
- */
- /*
- protected DefaultIoFilterChainBuilder createIoFilterChainBuilder() {
-
- DefaultIoFilterChainBuilder builder = new DefaultIoFilterChainBuilder();
- builder.addLast("protocolCodecFactory", new ProtocolCodecFilter(new JamesProtocolCodecFactory()));
- return builder;
- }
- */
-
/**
* Return the default port which will get used for this server if non is specify in the configuration
@@ -506,4 +481,8 @@ public abstract class AbstractAsyncServe
protected int getTimeout() {
return timeout;
}
+
+ protected SSLContext getSSLContext() {
+ return context;
+ }
}
Modified: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java (original)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractChannelPipelineFactory.java Sat Apr 17 17:18:41 2010
@@ -84,4 +84,6 @@ public abstract class AbstractChannelPip
*/
protected abstract int getTimeout();
+
+
}
Modified: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java (original)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractNettySession.java Sat Apr 17 17:18:41 2010
@@ -23,13 +23,14 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
-import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
import org.apache.commons.logging.Log;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.TLSSupportedSession;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.ssl.SslHandler;
import org.jboss.netty.handler.stream.ChunkedStream;
/**
@@ -42,14 +43,14 @@ public abstract class AbstractNettySessi
protected ChannelHandlerContext handlerContext;
protected InetSocketAddress socketAddress;
protected Log logger;
- protected SSLContext context;
+ protected SSLEngine engine;
protected String user;
- public AbstractNettySession(Log logger, ChannelHandlerContext handlerContext, SSLContext context) {
+ public AbstractNettySession(Log logger, ChannelHandlerContext handlerContext, SSLEngine engine) {
this.handlerContext = handlerContext;
this.socketAddress = (InetSocketAddress) handlerContext.getChannel().getRemoteAddress();
this.logger = logger;
- this.context = context;
+ this.engine = engine;
}
public AbstractNettySession(Log logger, ChannelHandlerContext handlerContext) {
@@ -97,18 +98,18 @@ public abstract class AbstractNettySessi
* @see org.apache.james.api.protocol.TLSSupportedSession#isStartTLSSupported()
*/
public boolean isStartTLSSupported() {
- return context != null;
+ return engine != null;
}
/**
* @see org.apache.james.api.protocol.TLSSupportedSession#isTLSStarted()
*/
public boolean isTLSStarted() {
- /*
+
if (isStartTLSSupported()) {
- return session.getFilterChain().contains("sslFilter");
+ return getChannelHandlerContext().getPipeline().get("sslHandler") != null;
}
- */
+
return false;
}
@@ -116,15 +117,15 @@ public abstract class AbstractNettySessi
* @see org.apache.james.api.protocol.TLSSupportedSession#startTLS()
*/
public void startTLS() throws IOException {
- /*
- if (isStartTLSSupported()) {
- session.suspendRead();
- SslFilter filter = new SslFilter(context);
+ if (isStartTLSSupported() && isTLSStarted() == false) {
+ getChannelHandlerContext().getChannel().setReadable(false);
+ SslHandler filter = new SslHandler(engine);
+ filter.getEngine().setUseClientMode(false);
resetState();
- session.getFilterChain().addFirst("sslFilter", filter);
- session.resumeRead();
+ getChannelHandlerContext().getPipeline().addFirst("sslHandler", filter);
+ getChannelHandlerContext().getChannel().setReadable(true);
}
- */
+
}
/**
Added: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractSSLAwareChannelPipelineFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractSSLAwareChannelPipelineFactory.java?rev=935211&view=auto
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractSSLAwareChannelPipelineFactory.java (added)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractSSLAwareChannelPipelineFactory.java Sat Apr 17 17:18:41 2010
@@ -0,0 +1,58 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+package org.apache.james.socket.netty;
+
+import javax.net.ssl.SSLContext;
+
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.handler.ssl.SslHandler;
+
+/**
+ * Abstract base class for {@link ChannelPipeline} implementations which use TLS
+ *
+ *
+ */
+public abstract class AbstractSSLAwareChannelPipelineFactory extends AbstractChannelPipelineFactory{
+
+
+
+ @Override
+ public ChannelPipeline getPipeline() throws Exception {
+ ChannelPipeline pipeline = super.getPipeline();
+
+ if (isSSLSocket()) {
+ pipeline.addFirst("sslHandler", new SslHandler(getSSLContext().createSSLEngine()));
+ }
+ return pipeline;
+ }
+
+ /**
+ * Return if the socket is using SSL/TLS
+ *
+ * @return isSSL
+ */
+ protected abstract boolean isSSLSocket();
+
+ /**
+ * Return the SSL context
+ *
+ * @return context
+ */
+ protected abstract SSLContext getSSLContext();
+}
Modified: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java (original)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/NioPOP3Server.java Sat Apr 17 17:18:41 2010
@@ -18,17 +18,24 @@
****************************************************************/
package org.apache.james.pop3server.netty;
+import javax.net.ssl.SSLContext;
+
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.pop3server.POP3HandlerConfigurationData;
import org.apache.james.pop3server.POP3ServerMBean;
import org.apache.james.protocols.api.ProtocolHandlerChain;
import org.apache.james.socket.netty.AbstractAsyncServer;
-import org.apache.james.socket.netty.AbstractChannelPipelineFactory;
+import org.apache.james.socket.netty.AbstractSSLAwareChannelPipelineFactory;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+/**
+ * NIO POP3 Server which use Netty
+ *
+ *
+ */
public class NioPOP3Server extends AbstractAsyncServer implements POP3ServerMBean{
/**
* The number of bytes to read before resetting the connection timeout
@@ -124,11 +131,11 @@ public class NioPOP3Server extends Abstr
@Override
protected ChannelPipelineFactory createPipelineFactory() {
- return new AbstractChannelPipelineFactory() {
+ return new AbstractSSLAwareChannelPipelineFactory() {
@Override
protected ChannelUpstreamHandler createHandler() {
- return new POP3ChannelUpstreamHandler(NioPOP3Server.this.getProtocolHandlerChain(), getPOP3HandlerConfiguration(), getLogger());
+ return new POP3ChannelUpstreamHandler(NioPOP3Server.this.getProtocolHandlerChain(), getPOP3HandlerConfiguration(), getLogger(), getSSLContext());
}
@Override
@@ -140,6 +147,16 @@ public class NioPOP3Server extends Abstr
protected int getTimeout() {
return NioPOP3Server.this.getTimeout();
}
+
+ @Override
+ protected SSLContext getSSLContext() {
+ return NioPOP3Server.this.getSSLContext();
+ }
+
+ @Override
+ protected boolean isSSLSocket() {
+ return NioPOP3Server.this.isSSLSocket();
+ }
};
}
Modified: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java (original)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ChannelUpstreamHandler.java Sat Apr 17 17:18:41 2010
@@ -18,27 +18,46 @@
****************************************************************/
package org.apache.james.pop3server.netty;
+import javax.net.ssl.SSLContext;
+
import org.apache.commons.logging.Log;
import org.apache.james.pop3server.POP3HandlerConfigurationData;
import org.apache.james.protocols.api.ProtocolHandlerChain;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.socket.netty.AbstractChannelUpstreamHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+/**
+ * {@link ChannelUpstreamHandler} which is used for the POP3 Server
+ *
+ *
+ */
public class POP3ChannelUpstreamHandler extends AbstractChannelUpstreamHandler{
- private Log logger;
- private POP3HandlerConfigurationData conf;
+ private final Log logger;
+ private final POP3HandlerConfigurationData conf;
+ private final SSLContext context;
- public POP3ChannelUpstreamHandler(ProtocolHandlerChain chain, POP3HandlerConfigurationData conf, Log logger) {
+ public POP3ChannelUpstreamHandler(ProtocolHandlerChain chain, POP3HandlerConfigurationData conf, Log logger, SSLContext context) {
super(chain);
this.logger = logger;
this.conf = conf;
+ this.context = context;
+ }
+
+ public POP3ChannelUpstreamHandler(ProtocolHandlerChain chain, POP3HandlerConfigurationData conf, Log logger) {
+ this(chain, conf, logger, null);
}
+
@Override
protected ProtocolSession createSession(ChannelHandlerContext ctx) throws Exception {
- return new POP3NettySession(conf, logger, ctx);
+ if (context != null) {
+ return new POP3NettySession(conf, logger, ctx, context.createSSLEngine());
+ } else {
+ return new POP3NettySession(conf, logger, ctx);
+ }
}
}
Modified: james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java (original)
+++ james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3NettySession.java Sat Apr 17 17:18:41 2010
@@ -21,6 +21,8 @@ package org.apache.james.pop3server.nett
import java.util.HashMap;
import java.util.Map;
+import javax.net.ssl.SSLEngine;
+
import org.apache.commons.logging.Log;
import org.apache.james.imap.mailbox.Mailbox;
import org.apache.james.pop3server.POP3HandlerConfigurationData;
@@ -47,6 +49,12 @@ public class POP3NettySession extends Ab
}
+ public POP3NettySession(POP3HandlerConfigurationData configData, Log logger, ChannelHandlerContext handlerContext, SSLEngine engine) {
+ super(logger, handlerContext, engine);
+ this.configData = configData;
+ }
+
+
/*
* (non-Javadoc)
*
Modified: james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NettyRemoteManagerSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NettyRemoteManagerSession.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NettyRemoteManagerSession.java (original)
+++ james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NettyRemoteManagerSession.java Sat Apr 17 17:18:41 2010
@@ -33,6 +33,10 @@ import org.apache.james.socket.netty.Lin
import org.jboss.netty.channel.Channel;
import org.jboss.netty.handler.stream.ChunkedStream;
+/**
+ * {@link RemoteManagerSession} implementation for Netty
+ *
+ */
public class NettyRemoteManagerSession implements RemoteManagerSession {
private Log logger;
private Channel channel;
Modified: james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NioRemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NioRemoteManager.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NioRemoteManager.java (original)
+++ james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/NioRemoteManager.java Sat Apr 17 17:18:41 2010
@@ -35,6 +35,10 @@ import org.jboss.netty.channel.ChannelUp
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+/**
+ * NIO RemoteManager which use Netty
+ *
+ */
public class NioRemoteManager extends AbstractAsyncServer implements RemoteManagerMBean{
Modified: james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerChannelUpstreamHandler.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerChannelUpstreamHandler.java (original)
+++ james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerChannelUpstreamHandler.java Sat Apr 17 17:18:41 2010
@@ -26,7 +26,12 @@ import org.apache.james.remotemanager.Re
import org.apache.james.remotemanager.RemoteManagerSession;
import org.apache.james.socket.netty.AbstractChannelUpstreamHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+/**
+ * {@link ChannelUpstreamHandler} which is used by RemoteManager
+ *
+ */
public class RemoteManagerChannelUpstreamHandler extends AbstractChannelUpstreamHandler{
private Log logger;
Modified: james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerResponseEncoder.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerResponseEncoder.java (original)
+++ james/server/trunk/remotemanager/src/main/java/org/apache/james/remotemanager/netty/RemoteManagerResponseEncoder.java Sat Apr 17 17:18:41 2010
@@ -25,6 +25,10 @@ import java.util.List;
import org.apache.james.remotemanager.RemoteManagerResponse;
import org.apache.james.socket.netty.AbstractResponseEncoder;
+/**
+ * {@link AbstractResponseEncoder} implementation which encode {@link RemoteManagerResponse} objects
+ *
+ */
public class RemoteManagerResponseEncoder extends AbstractResponseEncoder<RemoteManagerResponse>{
public RemoteManagerResponseEncoder() {
Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/NioSMTPServer.java Sat Apr 17 17:18:41 2010
@@ -1,5 +1,25 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
package org.apache.james.smtpserver.netty;
+import javax.net.ssl.SSLContext;
+
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.api.dnsservice.util.NetMatcher;
@@ -7,11 +27,16 @@ import org.apache.james.protocols.api.Pr
import org.apache.james.protocols.smtp.SMTPConfiguration;
import org.apache.james.protocols.smtp.SMTPServerMBean;
import org.apache.james.socket.netty.AbstractAsyncServer;
-import org.apache.james.socket.netty.AbstractChannelPipelineFactory;
+import org.apache.james.socket.netty.AbstractSSLAwareChannelPipelineFactory;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+/**
+ * NIO SMTPServer which use Netty
+ *
+ *
+ */
public class NioSMTPServer extends AbstractAsyncServer implements SMTPServerMBean{
@@ -267,11 +292,11 @@ public class NioSMTPServer extends Abstr
@Override
protected ChannelPipelineFactory createPipelineFactory() {
- return new AbstractChannelPipelineFactory() {
+ return new AbstractSSLAwareChannelPipelineFactory() {
@Override
protected ChannelUpstreamHandler createHandler() {
- return new SMTPChannelUpstreamHandler(NioSMTPServer.this.getProtocolHandlerChain(), getSMTPConfiguration(),getLogger());
+ return new SMTPChannelUpstreamHandler(NioSMTPServer.this.getProtocolHandlerChain(), getSMTPConfiguration(),getLogger(), getSSLContext());
}
@Override
@@ -283,6 +308,16 @@ public class NioSMTPServer extends Abstr
protected int getTimeout() {
return NioSMTPServer.this.getTimeout();
}
+
+ @Override
+ protected SSLContext getSSLContext() {
+ return NioSMTPServer.this.getSSLContext();
+ }
+
+ @Override
+ protected boolean isSSLSocket() {
+ return NioSMTPServer.this.isSSLSocket();
+ }
};
}
Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPChannelUpstreamHandler.java Sat Apr 17 17:18:41 2010
@@ -1,5 +1,25 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
package org.apache.james.smtpserver.netty;
+import javax.net.ssl.SSLContext;
+
import org.apache.commons.logging.Log;
import org.apache.james.lifecycle.LifecycleUtil;
import org.apache.james.protocols.api.ProtocolHandlerChain;
@@ -13,24 +33,38 @@ import org.apache.james.socket.netty.Abs
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.ExceptionEvent;
+/**
+ * {@link ChannelUpstreamHandler} which is used by the SMTPServer
+ *
+ */
public class SMTPChannelUpstreamHandler extends AbstractChannelUpstreamHandler{
- private Log logger;
- private SMTPConfiguration conf;
+ private final Log logger;
+ private final SMTPConfiguration conf;
+ private final SSLContext context;
public SMTPChannelUpstreamHandler(ProtocolHandlerChain chain,
SMTPConfiguration conf, Log logger) {
+ this(chain, conf, logger, null);
+ }
+
+ public SMTPChannelUpstreamHandler(ProtocolHandlerChain chain,
+ SMTPConfiguration conf, Log logger, SSLContext context) {
super(chain);
this.conf = conf;
this.logger = logger;
+ this.context = context;
}
@Override
protected ProtocolSession createSession(ChannelHandlerContext ctx) throws Exception {
- SMTPSession smtpSession= new SMTPNettySession(conf, logger, ctx);
-
- return smtpSession;
+ if (context != null) {
+ return new SMTPNettySession(conf, logger, ctx, context.createSSLEngine());
+ } else {
+ return new SMTPNettySession(conf, logger, ctx);
+ }
}
@Override
@@ -52,6 +86,11 @@ public class SMTPChannelUpstreamHandler
super.exceptionCaught(ctx, e);
}
+ /**
+ * Cleanup temporary files
+ *
+ * @param channel
+ */
private void cleanup(Channel channel) {
// Make sure we dispose everything on exit on session close
SMTPSession smtpSession = (SMTPSession) attributes.get(channel);
Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPNettySession.java Sat Apr 17 17:18:41 2010
@@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Random;
+import javax.net.ssl.SSLEngine;
+
import org.apache.commons.logging.Log;
import org.apache.james.protocols.api.LineHandler;
import org.apache.james.protocols.smtp.SMTPConfiguration;
@@ -31,6 +33,10 @@ import org.apache.james.socket.netty.Abs
import org.apache.james.socket.netty.LineHandlerUpstreamHandler;
import org.jboss.netty.channel.ChannelHandlerContext;
+/**
+ * {@link SMTPSession} implementation for use with Netty
+ *
+ */
public class SMTPNettySession extends AbstractNettySession implements SMTPSession{
public final static String SMTP_SESSION = "SMTP_SESSION";
@@ -46,15 +52,18 @@ public class SMTPNettySession extends Ab
private int lineHandlerCount = 0;
- public SMTPNettySession(SMTPConfiguration theConfigData, Log logger, ChannelHandlerContext handlerContext) {
- super(logger, handlerContext);
+ public SMTPNettySession(SMTPConfiguration theConfigData, Log logger, ChannelHandlerContext handlerContext, SSLEngine engine) {
+ super(logger, handlerContext, engine);
this.theConfigData = theConfigData;
connectionState = new HashMap<String, Object>();
smtpID = random.nextInt(1024) + "";
relayingAllowed = theConfigData.isRelayingAllowed(getRemoteIPAddress());
}
-
+
+ public SMTPNettySession(SMTPConfiguration theConfigData, Log logger, ChannelHandlerContext handlerContext) {
+ this(theConfigData, logger, handlerContext, null);
+ }
/**
* @see org.apache.james.protocols.smtp.SMTPSession#getConnectionState()
Modified: james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java (original)
+++ james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPResponseEncoder.java Sat Apr 17 17:18:41 2010
@@ -1,3 +1,21 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
package org.apache.james.smtpserver.netty;
import java.util.ArrayList;
@@ -6,6 +24,10 @@ import java.util.List;
import org.apache.james.protocols.smtp.SMTPResponse;
import org.apache.james.socket.netty.AbstractResponseEncoder;
+/**
+ * {@link AbstractResponseEncoder} which encode {@link SMTPResponse} objects
+ *
+ */
public class SMTPResponseEncoder extends AbstractResponseEncoder<SMTPResponse>{
public SMTPResponseEncoder() {
Modified: james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java?rev=935211&r1=935210&r2=935211&view=diff
==============================================================================
--- james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java (original)
+++ james/server/trunk/smtpserver/src/test/java/org/apache/james/smtpserver/NioSMTPServerTest.java Sat Apr 17 17:18:41 2010
@@ -52,9 +52,4 @@ public class NioSMTPServerTest extends A
// TODO: Add support
}
- @Override
- public void testStartTLSInEHLO() throws Exception {
- // TODO: Add support
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org