Secure iNet Factory

com.jscape.inet.popssl
Class PopSsl

java.lang.Object
  extended by com.jscape.inet.pop.Pop
      extended by com.jscape.inet.popssl.PopSsl
All Implemented Interfaces:
java.io.Serializable

public class PopSsl
extends Pop

Implements the basic functionality of a secure POP3 client using SSL/TLS. Client supports both implicit SSL/TLS on port 995 (default) and explicit SSL/TLS using STLS command on port 110.

Example Usage (implicit SSL/TLS):

 // connection parameters for SSL connection
 String hostname = "pop3.myserver.com";
 String username = "jsmith";
 String password = "secret";
 int port = 995;

 // new instance hostname, port, username and password
 PopSsl pop = new PopSsl(hostname,port,username,password);
 try
 {
   // connect to POP3 server
   pop.connect();
    // get messages
   Enumeration e = pop.getMessages();
   while(e.hasMoreElements()) {
     EmailMessage em = (EmailMessage)e.nextElement();
   }
    // disconnect
   pop.disconnect();
 }
 catch(Exception e)
 {
   System.out.println(e);
 }
 

Example Usage (explicit SSL/TLS using STLS command on port 110):

 // connection parameters for SSL connection
 String hostname = "pop3.myserver.com";
 String username = "jsmith";
 String password = "secret";
 int port = 110;

 // new instance hostname, port, username and password
 PopSsl pop = new PopSsl(hostname,port,username,password);
 pop.setConnectionType(PopSsl.STARTTLS);
 try
 {
   // connect to POP3 server
   pop.connect();
    // get messages
   Enumeration e = pop.getMessages();
   while(e.hasMoreElements()) {
     EmailMessage em = (EmailMessage)e.nextElement();
   }
    // disconnect
   pop.disconnect();
 }
 catch(Exception e)
 {
   System.out.println(e);
 }
 

See Also:
Serialized Form

Field Summary
static int DEFAULT_PORT
          The default port to connect to for secure POP3 over SSL connections (995).
static int IMPLICIT_SSL
          Connection type for implicit SSL/TLS connections on port 995.
static int STARTTLS
          Connection type for explicit SSL/TLS connections using STARTTLS command on port 110.
 
Fields inherited from class com.jscape.inet.pop.Pop
AUTH_APOP, AUTH_LOGIN, AUTH_PASS
 
Constructor Summary
PopSsl(java.lang.String hostname, int port, java.lang.String username, java.lang.String password)
          Constructs a new PopSsl instance.
PopSsl(java.lang.String hostname, java.lang.String username, java.lang.String password)
          Constructs a new PopSsl instance.
 
Method Summary
 void clearProxySettings()
          Clears proxy server values.
 void connect()
          Establishes secure SSL connection to POP3 server.
 void disconnect()
          Disconnects from POP3 server.
 int getConnectionType()
          Gets the connection type for this session.
 void setClientCertificates(java.lang.String filename, java.lang.String password)
          Sets optional client certificate to be used during authentication.
 void setClientCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional client certificate to be used during authentication.
 void setConnectionType(int mode)
          Sets the connection type for this session.
 void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
          Sets the username and password to use when for authentication with proxy server.
 void setProxyHost(java.lang.String proxyHostname, int proxyPort)
          Sets the proxy hostname and port for this connection.
 void setProxyType(java.lang.String proxyType)
          Sets the proxy type will be used for this connection.
 void setServerCertificates(java.lang.String filename, java.lang.String password)
          Sets optional server certificate to be used during authentication.
 void setServerCertificates(java.lang.String filename, java.lang.String password, java.lang.String storetype)
          Sets optional server certificate to be used during authentication.
 void setSSLContext(javax.net.ssl.SSLContext context)
          Sets SSL context for this connection.
 
Methods inherited from class com.jscape.inet.pop.Pop
addPopListener, deleteMessage, getAuthMode, getConnectTimeout, getDebugStream, getHostname, getMessage, getMessageCount, getMessageReader, getMessages, getMessageSize, getPort, getReadTimeout, getTimeout, getTop, getUid, getUsername, isConnected, isDebug, isDelete, issueCommand, issueCommand, issueCommandMultiLine, removePopListener, setAuthMode, setConnectTimeout, setDebug, setDebugStream, setDelete, setHostname, setPassword, setPort, setReadTimeout, setTimeout, setUsername
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPLICIT_SSL

public static final int IMPLICIT_SSL
Connection type for implicit SSL/TLS connections on port 995. Value of 0.

See Also:
setConnectionType(int), STARTTLS, Constant Field Values

STARTTLS

public static final int STARTTLS
Connection type for explicit SSL/TLS connections using STARTTLS command on port 110. Value of 1.

See Also:
setConnectionType(int), IMPLICIT_SSL, Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port to connect to for secure POP3 over SSL connections (995).

See Also:
Constant Field Values
Constructor Detail

PopSsl

public PopSsl(java.lang.String hostname,
              java.lang.String username,
              java.lang.String password)
Constructs a new PopSsl instance. Sets hostname, username and password for POP3 connection.

Parameters:
hostname - the hostname of POP3 server
username - the username of POP3 user
password - the password of POP3 user

PopSsl

public PopSsl(java.lang.String hostname,
              int port,
              java.lang.String username,
              java.lang.String password)
Constructs a new PopSsl instance. Sets hostname, username and password for POP3 connection.

Parameters:
hostname - the hostname of POP3 server
port - the port of secure POP3 server
username - the username of POP3 user
password - the password of POP3 user
Method Detail

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password

setClientCertificates

public void setClientCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional client certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the client certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setConnectionType

public void setConnectionType(int mode)
Sets the connection type for this session.

Parameters:
mode - a valid connection type
See Also:
IMPLICIT_SSL, STARTTLS

getConnectionType

public int getConnectionType()
Gets the connection type for this session. Default is IMPLICIT_SSL

Returns:
the connection type
See Also:
IMPLICIT_SSL, STARTTLS

setSSLContext

public void setSSLContext(javax.net.ssl.SSLContext context)
Sets SSL context for this connection.

Parameters:
context - an SSLContext instance
See Also:
SSLContext

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password

setServerCertificates

public void setServerCertificates(java.lang.String filename,
                                  java.lang.String password,
                                  java.lang.String storetype)
Sets optional server certificate to be used during authentication. Default expected keystore format is JKS format. Existing certificate may be imported into keystore using the keytool utility provided in the Sun JDK.

Example:

 keytool.exe -import -file x509.cer -keystore your_store_name
 

The example above imports the certificate x509.cer into a keystore named your_store_name

Parameters:
filename - the keystore file containing the server certificate
password - the keystore password
storetype - the keystore type valid values include jks and pkcs12

setProxyAuthentication

public void setProxyAuthentication(java.lang.String proxyUsername,
                                   java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyAuthentication in class Pop
Parameters:
proxyUsername - the proxy username
proxyPassword - the proxy password
See Also:
clearProxySettings()

setProxyHost

public void setProxyHost(java.lang.String proxyHostname,
                         int proxyPort)
Sets the proxy hostname and port for this connection. To clear these settings invoke the #clearProxySettings method.

Overrides:
setProxyHost in class Pop
Parameters:
proxyHostname - the hostname or ip address of the proxy server
proxyPort - the port of the proxy server
See Also:
clearProxySettings()

setProxyType

public void setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection.

Overrides:
setProxyType in class Pop
Parameters:
proxyType - The proxy type. Valid values: HTTP, SOCKS5

clearProxySettings

public void clearProxySettings()
Clears proxy server values.

Overrides:
clearProxySettings in class Pop

connect

public void connect()
             throws PopException
Establishes secure SSL connection to POP3 server.

Overrides:
connect in class Pop
Throws:
PopException - if I/O or POP3 related error occurs

disconnect

public void disconnect()
                throws PopException
Disconnects from POP3 server. Issues QUIT command to POP3 server and closes connection.

Overrides:
disconnect in class Pop
Throws:
PopException - if I/O or POP3 related error occurs

Secure iNet Factory

Copyright © JSCAPE LLC. 1999-2011. All Rights Reserved