mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
IMAPS - initial implementation.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@33329 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -16,6 +16,12 @@
|
|||||||
<property name="port">
|
<property name="port">
|
||||||
<value>${imap.server.port}</value>
|
<value>${imap.server.port}</value>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="imapsEnabled">
|
||||||
|
<value>${imap.server.imaps.enabled}</value>
|
||||||
|
</property>
|
||||||
|
<property name="securePort">
|
||||||
|
<value>${imap.server.imaps.port}</value>
|
||||||
|
</property>
|
||||||
<property name="imapServerEnabled">
|
<property name="imapServerEnabled">
|
||||||
<value>${imap.server.enabled}</value>
|
<value>${imap.server.enabled}</value>
|
||||||
</property>
|
</property>
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
imap.server.enabled=false
|
imap.server.enabled=false
|
||||||
imap.server.port=143
|
|
||||||
imap.server.host=0.0.0.0
|
imap.server.host=0.0.0.0
|
||||||
imap.server.folder.cache.size=10000
|
imap.server.folder.cache.size=10000
|
||||||
|
|
||||||
@@ -9,3 +8,14 @@ imap.mail.to.default=alfresco@demo.alfresco.org
|
|||||||
imap.config.home.store=${protocols.storeName}
|
imap.config.home.store=${protocols.storeName}
|
||||||
imap.config.home.rootPath=${protocols.rootPath}
|
imap.config.home.rootPath=${protocols.rootPath}
|
||||||
imap.config.home.folderPath=Imap Home
|
imap.config.home.folderPath=Imap Home
|
||||||
|
|
||||||
|
# IMAP Port
|
||||||
|
imap.server.port=143
|
||||||
|
imap.server.imap.enabled=true
|
||||||
|
|
||||||
|
# IMAPS Port
|
||||||
|
# Keystore used for IMAPS is defined by the following Java system properties.
|
||||||
|
# javax.net.ssl.keyStore=mySrvKeystore
|
||||||
|
# javax.net.ssl.keyStorePassword=123456
|
||||||
|
imap.server.imaps.enabled=false
|
||||||
|
imap.server.imaps.port=993
|
||||||
|
@@ -332,6 +332,12 @@ public abstract class EmailServer extends AbstractLifecycleBean
|
|||||||
System.err.println("\t configLocation - spring xml configs with EmailServer related beans (emailServer, emailServerConfiguration, emailService)");
|
System.err.println("\t configLocation - spring xml configs with EmailServer related beans (emailServer, emailServerConfiguration, emailService)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* authenticate with a user/password
|
||||||
|
* @param userName
|
||||||
|
* @param password
|
||||||
|
* @return true - authenticated
|
||||||
|
*/
|
||||||
protected boolean authenticateUserNamePassword(String userName, char[] password)
|
protected boolean authenticateUserNamePassword(String userName, char[] password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@@ -18,8 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.imap;
|
package org.alfresco.repo.imap;
|
||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import java.io.IOException;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
import java.net.ServerSocket;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -28,21 +29,78 @@ import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
|||||||
import com.icegreen.greenmail.Managers;
|
import com.icegreen.greenmail.Managers;
|
||||||
import com.icegreen.greenmail.imap.ImapHostManager;
|
import com.icegreen.greenmail.imap.ImapHostManager;
|
||||||
import com.icegreen.greenmail.imap.ImapServer;
|
import com.icegreen.greenmail.imap.ImapServer;
|
||||||
import com.icegreen.greenmail.store.FolderException;
|
|
||||||
import com.icegreen.greenmail.user.UserManager;
|
import com.icegreen.greenmail.user.UserManager;
|
||||||
import com.icegreen.greenmail.util.ServerSetup;
|
import com.icegreen.greenmail.util.ServerSetup;
|
||||||
|
import javax.net.ssl.SSLServerSocketFactory;
|
||||||
|
import javax.net.ssl.SSLServerSocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mike Shavnev
|
* @author Mike Shavnev
|
||||||
*/
|
*/
|
||||||
public class AlfrescoImapServer extends AbstractLifecycleBean
|
public class AlfrescoImapServer extends AbstractLifecycleBean
|
||||||
{
|
{
|
||||||
|
private class SecureImapServer extends ImapServer
|
||||||
|
{
|
||||||
|
|
||||||
|
public SecureImapServer(ServerSetup setup, Managers managers)
|
||||||
|
{
|
||||||
|
super(setup, managers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* Use Java's default SSL Server SocketFactory
|
||||||
|
* controlled via System Properties
|
||||||
|
* -Djavax.net.ssl.keyStore=mySrvKeystore
|
||||||
|
* -Djavax.net.ssl.keyStorePassword=123456
|
||||||
|
*/
|
||||||
|
// MER - also consider using SSLContext
|
||||||
|
protected synchronized ServerSocket openServerSocket() throws IOException {
|
||||||
|
ServerSocket ret;
|
||||||
|
if (setup.isSecure())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket(
|
||||||
|
setup.getPort(), 0, bindTo);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
if(logger.isErrorEnabled())
|
||||||
|
{
|
||||||
|
logger.error("Unable to open socket bindTo:" + bindTo + "port " + setup.getPort(), e);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = new ServerSocket(setup.getPort(), 0, bindTo);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
if(logger.isErrorEnabled())
|
||||||
|
{
|
||||||
|
logger.error("Unable to open socket bindTo:" + bindTo + "port " + setup.getPort(), e);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Log logger = LogFactory.getLog(AlfrescoImapServer.class);
|
private static Log logger = LogFactory.getLog(AlfrescoImapServer.class);
|
||||||
|
|
||||||
private ImapServer serverImpl;
|
private ImapServer serverImpl;
|
||||||
|
private ImapServer secureServerImpl;
|
||||||
|
|
||||||
private int port = 143;
|
private int port = 143;
|
||||||
|
private int securePort = 993;
|
||||||
|
private boolean imapsEnabled = false;
|
||||||
|
|
||||||
private String host = "0.0.0.0";
|
private String host = "0.0.0.0";
|
||||||
|
|
||||||
private UserManager imapUserManager;
|
private UserManager imapUserManager;
|
||||||
@@ -76,6 +134,16 @@ public class AlfrescoImapServer extends AbstractLifecycleBean
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSecurePort(int securePort)
|
||||||
|
{
|
||||||
|
this.securePort = securePort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSecurePort()
|
||||||
|
{
|
||||||
|
return securePort;
|
||||||
|
}
|
||||||
|
|
||||||
public String getHost()
|
public String getHost()
|
||||||
{
|
{
|
||||||
return host;
|
return host;
|
||||||
@@ -135,8 +203,18 @@ public class AlfrescoImapServer extends AbstractLifecycleBean
|
|||||||
|
|
||||||
if (logger.isInfoEnabled())
|
if (logger.isInfoEnabled())
|
||||||
{
|
{
|
||||||
logger.info("IMAP service started on host:port " + host + ":" + this.port + ".");
|
logger.info("IMAP service started on host:port " + host + ":" + this.port);
|
||||||
}
|
}
|
||||||
|
if(isImapsEnabled())
|
||||||
|
{
|
||||||
|
secureServerImpl = new SecureImapServer(new ServerSetup(securePort, host, ServerSetup.PROTOCOL_IMAPS), imapManagers);
|
||||||
|
secureServerImpl.startService(null);
|
||||||
|
if (logger.isInfoEnabled())
|
||||||
|
{
|
||||||
|
logger.info("IMAPS service started on host:port " + host + ":" + this.securePort );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -157,6 +235,24 @@ public class AlfrescoImapServer extends AbstractLifecycleBean
|
|||||||
}
|
}
|
||||||
serverImpl.stopService(null);
|
serverImpl.stopService(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (secureServerImpl != null)
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("IMAPS service stopping.");
|
||||||
|
}
|
||||||
|
secureServerImpl.stopService(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setImapsEnabled(boolean imapsEnabled)
|
||||||
|
{
|
||||||
|
this.imapsEnabled = imapsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isImapsEnabled()
|
||||||
|
{
|
||||||
|
return imapsEnabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user