diff options
author | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-03-31 23:01:41 +0200 |
---|---|---|
committer | Danny van Heumen <danny@dannyvanheumen.nl> | 2015-04-03 21:37:01 +0200 |
commit | de23be68dd771571a0bb8a116ddcd8f2bd799f4b (patch) | |
tree | ecc97cfbc9c86ecd5dd3a13deafc529ea2c28c9c /src/net/java/sip/communicator | |
parent | 89e35bf75c3420553ebbf6efbbff3c4d6f55ee05 (diff) | |
download | jitsi-de23be68dd771571a0bb8a116ddcd8f2bd799f4b.zip jitsi-de23be68dd771571a0bb8a116ddcd8f2bd799f4b.tar.gz jitsi-de23be68dd771571a0bb8a116ddcd8f2bd799f4b.tar.bz2 |
Created SASL entry in client configuration. Connected SASL configuration to IRC stack.
Diffstat (limited to 'src/net/java/sip/communicator')
5 files changed, 183 insertions, 40 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ClientConfig.java b/src/net/java/sip/communicator/impl/protocol/irc/ClientConfig.java index 3d77290..772ec4b 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ClientConfig.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ClientConfig.java @@ -63,4 +63,42 @@ public interface ClientConfig * proxy */ boolean isResolveByProxy(); + + /** + * Get the configured SASL authentication data. + * + * @return Returns the SASL authentication data if set, or null if no + * authentication data is set. If no authentication data is set, + * this would mean SASL authentication need not be used. + */ + SASL getSASL(); + + /** + * SASL authentication data. + * + * @author Danny van Heumen + */ + static interface SASL + { + /** + * Get user name. + * + * @return Returns the user name. + */ + String getUser(); + + /** + * Get password. + * + * @return Returns the password. + */ + String getPass(); + + /** + * Get authorization role. + * + * @return Returns the authorization role if set. (Optional) + */ + String getRole(); + } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ClientConfigImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ClientConfigImpl.java index 837c2cb..1c61a40 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ClientConfigImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ClientConfigImpl.java @@ -47,6 +47,11 @@ public class ClientConfigImpl private boolean resolveByProxy = true; /** + * Get SASL authentication data. + */ + private SASLImpl sasl = null; + + /** * Get version 3 allowed flag. * * @return returns <tt>true</tt> if allowed, or <tt>false</tt> if not. @@ -140,6 +145,7 @@ public class ClientConfigImpl * @return returns <tt>true</tt> to resolve by proxy, or <tt>false</tt> to * resolve via (local) DNS. */ + @Override public boolean isResolveByProxy() { return this.resolveByProxy; @@ -153,4 +159,115 @@ public class ClientConfigImpl { this.resolveByProxy = resolveByProxy; } + + /** + * Get the configured SASL authentication data. + * + * @return Returns the SASL authentication data if set, or null if no + * authentication data is set. If no authentication data is set, + * this would mean SASL authentication need not be used. + */ + @Override + public SASL getSASL() + { + return this.sasl; + } + + /** + * Set SASL authentication data. + * + * @param sasl the SASL authentication data + */ + public void setSASL(final SASLImpl sasl) + { + this.sasl = sasl; + } + + /** + * Type for storing SASL authentication data. + * + * @author Danny van Heumen + */ + public static class SASLImpl implements SASL + { + /** + * User name. + */ + private final String user; + + /** + * Password. + */ + private final String pass; + + /** + * Authorization role. + */ + private final String role; + + /** + * Constructor for authentication without an explicit authorization + * role. + * + * @param userName the user name + * @param password the password + */ + public SASLImpl(final String userName, final String password) + { + this(userName, password, null); + } + + /** + * Constructor for authentication with authorization role. + * + * @param userName the user name + * @param password the password + * @param role the authorization role + */ + public SASLImpl(final String userName, final String password, + final String role) + { + if (userName == null) + { + throw new NullPointerException("userName"); + } + this.user = userName; + if (password == null) + { + throw new NullPointerException("password"); + } + this.pass = password; + this.role = role; + } + + /** + * Get the user name. + * + * @return Returns the user name. + */ + public String getUser() + { + return this.user; + } + + /** + * Get the password. + * + * @return Returns the password. + */ + public String getPass() + { + return this.pass; + } + + /** + * Get the authorization role. + * + * @return Returns the authorization role. + */ + public String getRole() + { + return this.role; + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcConnection.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcConnection.java index 5c56e6e..94bd1d7 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcConnection.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcConnection.java @@ -9,6 +9,7 @@ package net.java.sip.communicator.impl.protocol.irc; import java.io.*; import java.util.*; +import net.java.sip.communicator.impl.protocol.irc.ClientConfig.SASL; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.util.*; @@ -150,8 +151,8 @@ public class IrcConnection final CapabilityNegotiator negotiator; if (config.isVersion3Allowed()) { - // TODO get SASL authentication data from config - negotiator = determineNegotiator(params.getNickname(), password); + negotiator = + determineNegotiator(params.getNickname(), password, config); } else { @@ -164,8 +165,8 @@ public class IrcConnection // Now actually connect to the IRC server. this.connectionState = - connectSynchronized(this.context.provider, params, password, - this.irc, negotiator); + connectSynchronized(this.context.provider, params, this.irc, + negotiator); // instantiate identity manager for the connection this.identity = @@ -202,47 +203,23 @@ public class IrcConnection * in the specification * (http://ircv3.atheme.org/specification/capability-negotiation-3.1). * - * The NoopNegotiator should be used to do IRCv3 negotiation but not set up - * anything at that moment. + * The NoopNegotiator should be used to do IRCv3 negotiation (enabling IRCv3 + * in the process) but not set up anything at that moment. * * @param user the user nick used for authentication * @param password the authentication password * @return returns capability negotiator */ private static CapabilityNegotiator determineNegotiator(final String user, - final String password) + final String password, final ClientConfig config) { - if (password == null) + final SASL sasl = config.getSASL(); + if (sasl == null) { return new NoopNegotiator(); } - else - { - // FIXME correctly determine capabilities and SASL authentication - // enabled - return new SaslNegotiator(user, password, null); - } - // FIXME DEBUG CODE remove -// final ArrayList<Capability> caps = new ArrayList<Capability>(); -// caps.add(new SimpleCapability("away-notify")); -// if (password != null) -// { -// caps.add(new SaslCapability(true, null, user, password)); -// } -// return new CompositeNegotiator(caps, new CompositeNegotiator.Host() -// { -// @Override -// public void reject(Capability cap) -// { -// LOGGER.warn("REJECTED: " + cap.getId()); -// } -// -// @Override -// public void acknowledge(Capability cap) -// { -// LOGGER.warn("ACKED: " + cap.getId()); -// } -// }); + return new SaslNegotiator(sasl.getUser(), sasl.getPass(), + sasl.getRole()); } /** @@ -255,9 +232,8 @@ public class IrcConnection */ private static IIRCState connectSynchronized( final ProtocolProviderServiceIrcImpl provider, - final IServerParameters params, final String password, - final IRCApi irc, final CapabilityNegotiator negotiator) - throws Exception + final IServerParameters params, final IRCApi irc, + final CapabilityNegotiator negotiator) throws Exception { final Result<IIRCState, Exception> result = new Result<IIRCState, Exception>(); diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index 7368749..03b8e9d 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -28,6 +28,8 @@ import com.ircclouds.irc.api.listeners.*; /** * An implementation of IRC using the irc-api library. * + * TODO Correctly disconnect IRC connection upon quitting. + * * @author Danny van Heumen */ public class IrcStack implements IrcConnectionListener @@ -112,17 +114,18 @@ public class IrcStack implements IrcConnectionListener Exception { final IRCServer server; + final String plainPass = config.getSASL() == null ? password : null; if (secureConnection) { server = - new SecureIRCServer(host, port, password, + new SecureIRCServer(host, port, plainPass, getCustomSSLContext(host), config.getProxy(), config.isResolveByProxy()); } else { server = - new IRCServer(host, port, password, false, config.getProxy(), + new IRCServer(host, port, plainPass, false, config.getProxy(), config.isResolveByProxy()); } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ProtocolProviderServiceIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ProtocolProviderServiceIrcImpl.java index 78eb485..fcc1763 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ProtocolProviderServiceIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ProtocolProviderServiceIrcImpl.java @@ -8,6 +8,7 @@ package net.java.sip.communicator.impl.protocol.irc; import java.net.*; +import net.java.sip.communicator.impl.protocol.irc.ClientConfigImpl.SASLImpl; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; import net.java.sip.communicator.util.*; @@ -268,6 +269,7 @@ public class ProtocolProviderServiceIrcImpl ProtocolProviderFactoryIrcImpl.SASL_ENABLED, false); String saslUser = accountID.getAccountPropertyString( ProtocolProviderFactoryIrcImpl.SASL_USERNAME); + // FIXME Retrieve SASL password from Jitsi secure storage! String saslPass = accountID.getAccountPropertyString( ProtocolProviderFactoryIrcImpl.SASL_PASSWORD); String saslRole = accountID.getAccountPropertyString( @@ -322,6 +324,13 @@ public class ProtocolProviderServiceIrcImpl config.setChannelPresenceTaskEnabled(channelPresenceTask); config.setProxy(loadProxy()); config.setResolveByProxy(loadDNSThroughProxySetting()); + if (saslEnabled) + { + final SASLImpl sasl = + new ClientConfigImpl.SASLImpl(saslUser, saslPass, saslRole); + config.setSASL(sasl); + } + // FIXME fix 'replacement' plugins which now (probably) don't use global // proxy configuration when contacting URLs on the internet |