|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread org.schwering.irc.lib.IRCConnection org.schwering.irc.lib.ssl.SSLIRCConnection
The SSL extension of the IRCConnection
class.
The IRC server you want to connect to must accept SSL connections.
Otherwise you cannot connect to it with an instance of
SSLIRCConnection
. IRC servers which accept SSL connections are
really very rare, because SSL means a high load for the server.
The following sample code tries to establish an IRC connection to an
IRC server which must support SSL. Differences to the code which
demonstrates the use of of the IRCConnection
class are printed in bold font:
/* * The following code of a class which imports org.schwering.irc.lib.* * prepares an SSL IRC connection and then tries to establish the * connection. The server is "irc.somenetwork.com", the ports are * the default SSL port (443) and the port used on most SSL IRC servers * (994). No password is used (null). The nickname is "Foo" and * the realname is "Mr. Foobar". The username "foobar". * Because of setDaemon(true), the JVM exits even if this thread is * running. * By setting an instance of SSLDefaultTrustManager as TrustManager * (which is also done implicitely by the SSLIRCConnection class if no * TrustManager is set until the connect method is invoked), the * X509Certificate is accepted automatically. Of course, you can write * your own TrustManager. For example, you could write a class which * extends SSLDefaultTrustManager and overrides its checkServerTrusted * method. In the new checkServerTrusted method, you could ask the user * to accept or reject the certificate. * An instance of the class MyListener which must implement * IRCActionListener is set as event-listener for the connection. * The connection is told to parse out mIRC color codes and to enable * automatic PING? PONG! replies. */ SSLIRCConnection conn = new SSLIRCConnection( "irc.somenetwork.com", new int[] { 443, 994 }, null, "Foo", "Mr. Foobar", "foo@bar.com" ); conn.addIRCEventListener(new MyListener()); conn.addTrustManager(new SSLDefaultTrustManager()); conn.setDaemon(true); conn.setColors(false); conn.setPong(true); try { conn.connect(); // Try to connect!!! Don't forget this!!! } catch (IOException ioexc) { ioexc.printStackTrace(); }
The serverpassword isn't needed in most cases. You can give
null
or ""
instead as done in this example.
SSLTrustManager
s can be added and removed until the
connect
method is invoked. If no SSLTrustManager
s
are set until then, an
SSLDefaultTrustManager
is set
automatically. It accepts all X509 certificates.
IRCConnection
,
SSLTrustManager
Field Summary | |
static java.lang.String |
protocol
The SSL protocol of choice. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
SSLIRCConnection(java.lang.String host,
int[] ports,
java.lang.String pass,
java.lang.String nick,
java.lang.String username,
java.lang.String realname)
Creates a new IRC connection with secure sockets (SSL). |
|
SSLIRCConnection(java.lang.String host,
int portMin,
int portMax,
java.lang.String pass,
java.lang.String nick,
java.lang.String username,
java.lang.String realname)
Creates a new IRC connection with secure sockets (SSL). |
Method Summary | |
void |
addTrustManager(SSLTrustManager trustManager)
Adds a new SSLTrustManager . |
void |
connect()
Establish a connection to the server. |
SSLTrustManager[] |
getTrustManagers()
Returns the set SSLTrustManager s. |
boolean |
removeTrustManager(SSLTrustManager trustManager)
Removes one SSLTrustManager . |
Methods inherited from class org.schwering.irc.lib.IRCConnection |
addIRCEventListener, close, doAway, doAway, doInvite, doIson, doJoin, doJoin, doKick, doKick, doList, doList, doMode, doMode, doNames, doNames, doNick, doNotice, doPart, doPart, doPong, doPrivmsg, doQuit, doQuit, doTopic, doTopic, doUserhost, doWho, doWhois, doWhowas, getColors, getEncoding, getHost, getNick, getPassword, getPong, getPort, getPorts, getRealname, getTimeout, getUsername, isConnected, removeIRCEventListener, run, send, setColors, setEncoding, setPong, setTimeout, toString |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static java.lang.String protocol
Constructor Detail |
public SSLIRCConnection(java.lang.String host, int[] ports, java.lang.String pass, java.lang.String nick, java.lang.String username, java.lang.String realname)
int[]
. Thus, also ports like 994, 6000 and 6697 can be
selected.connect
method. Before
invoking it, you should set the IRCEventListener
, optionally
the SSLTrustManager
, if you don't want to use the
SSLDefaultTrustManager
which accepts the X509 certificate
automatically, and other settings.""
or null
for the password
argument in the constructor.
host
- The hostname of the server we want to connect to.ports
- The portrange to which we want to connect.pass
- The password of the IRC server. If your server isn't
secured by a password (that's normal), use
null
or ""
.nick
- The nickname for the connection. Is used to register the
connection.username
- The username. Is used to register the connection.realname
- The realname. Is used to register the connection.
java.lang.IllegalArgumentException
- If the host
or
ports
is null
or
ports
' length is
0
.connect()
public SSLIRCConnection(java.lang.String host, int portMin, int portMax, java.lang.String pass, java.lang.String nick, java.lang.String username, java.lang.String realname)
int
s. Thus, only a portrange from port x
to
port y
like from port 6000 to 6010 can be selected.connect
method. Before
invoking it, you should set the IRCEventListener
, optionally
the SSLTrustManager
, if you don't want to use the
SSLDefaultTrustManager
which accepts the X509 certificate
automatically, and other settings.""
or null
for the password
argument in the constructor.
host
- The hostname of the server we want to connect to.portMin
- The beginning of the port range we are going to connect
to.portMax
- The ending of the port range we are going to connect to.pass
- The password of the IRC server. If your server isn't
secured by a password (that's normal), use
null
or ""
.nick
- The nickname for the connection. Is used to register the
connection.username
- The username. Is used to register the connection.realname
- The realname. Is used to register the connection.
java.lang.IllegalArgumentException
- If the host
is
null
.connect()
Method Detail |
public void connect() throws java.io.IOException
IOException
. If anything SSL related fails (for example
conflicts with the algorithms or during the handshaking), a
SSLException
is thrown. connect
only one time.
connect
in class IRCConnection
java.lang.NoClassDefFoundError
- If SSL is not supported. This is the case
if neither JSSE nor J2SE 1.4 or later is
installed.
SSLNotSupportedException
- If SSL is not supported. This is the
case if neither JSSE nor J2SE 1.4 or
later is installed. This exception is
thrown if no NoClassDefFoundError is
thrown.
java.io.IOException
- If an I/O error occurs.
javax.net.ssl.SSLException
- If anything with the secure sockets fails.
java.net.SocketException
- If the connect
method was already
invoked.IRCConnection.isConnected()
,
IRCConnection.doQuit()
,
IRCConnection.doQuit(String)
,
IRCConnection.close()
public void addTrustManager(SSLTrustManager trustManager)
SSLTrustManager
.
trustManager
- The SSLTrustManager
object which is to
add.removeTrustManager(SSLTrustManager)
,
getTrustManagers()
public boolean removeTrustManager(SSLTrustManager trustManager)
SSLTrustManager
.
trustManager
- The SSLTrustManager
object which is to
remove.
true
if a SSLTrustManager
was removed.addTrustManager(SSLTrustManager)
,
getTrustManagers()
public SSLTrustManager[] getTrustManagers()
SSLTrustManager
s. The default
SSLTrustManager
is an instance of
SSLDefaultTrustManager
, which is set when you invoke the
connect
method without having set another
SSLTrustManager
.
SSLTrustManager
s.addTrustManager(SSLTrustManager)
,
removeTrustManager(SSLTrustManager)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |