Skip to content

Commit

Permalink
Add support for SASL authentication
Browse files Browse the repository at this point in the history
[FIXED JENKINS-33667]
  • Loading branch information
ddeva-vistar committed Jul 19, 2017
1 parent 929ee39 commit ceb74d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/main/java/hudson/plugins/ircbot/IrcPublisher.java
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.SortedMap;
import java.util.logging.Logger;
import java.util.logging.Level;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -172,6 +173,8 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>

String password = null;

private boolean sasl;

String nick = "jenkins-bot";

String nickServPassword = null;
Expand Down Expand Up @@ -267,6 +270,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
this.login = req.getParameter("irc_publisher.login");
this.password = Scrambler.scramble(
req.getParameter("irc_publisher.password"));
this.sasl = "on".equals(req.getParameter("irc_publisher.sasl"));
this.nick = req.getParameter("irc_publisher.nick");
this.nickServPassword = Scrambler.scramble(
req.getParameter(PARAMETERNAME_NICKSERV_PASSWORD));
Expand Down Expand Up @@ -471,6 +475,10 @@ public String getPassword() {
return Scrambler.descramble(password);
}

public boolean isSasl() {
return this.sasl;
}

//@Override
public int getPort() {
return port;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/ircbot/v2/IRCConnection.java
Expand Up @@ -41,6 +41,7 @@
import org.pircbotx.PircBotX;
import org.pircbotx.ProxySocketFactory;
import org.pircbotx.UtilSSLSocketFactory;
import org.pircbotx.cap.SASLCapHandler;
import org.pircbotx.hooks.ListenerAdapter;
import org.pircbotx.hooks.events.ConnectEvent;

Expand Down Expand Up @@ -91,8 +92,12 @@ public IRCConnection(DescriptorImpl descriptor, AuthenticationHolder authenticat

config.setServerHostname(descriptor.getHost());
config.setServerPort(descriptor.getPort());
String password = Util.fixEmpty(this.descriptor.getPassword());
config.setServerPassword(password);
if (this.descriptor.isSasl()) {
config.addCapHandler(new SASLCapHandler(this.descriptor.getLogin(), this.descriptor.getPassword()));
} else {
String password = Util.fixEmpty(this.descriptor.getPassword());
config.setServerPassword(password);
}
final String nickServPassword = Util.fixEmpty(this.descriptor.getNickServPassword());
config.setNickservPassword(nickServPassword);

Expand Down
Expand Up @@ -55,6 +55,10 @@
description="Password for the IRC server">
<f:password name="irc_publisher.password" value="${descriptor.getPassword()}" />
</f:entry>
<f:entry title="SASL"
description="Enable SASL for authentication">
<f:checkbox name="irc_publisher.sasl" checked="${descriptor.isSasl()}" />
</f:entry>
<f:entry title="NickServ Password" description="On connection, try to identify with NickServ with this password" help="/plugin/ircbot/help-globalConfigNickServ.html">
<f:password name="irc_publisher.nickServPassword" value="${descriptor.nickServPassword}"/>
</f:entry>
Expand Down Expand Up @@ -94,4 +98,4 @@
</f:advanced>
</f:optionalBlock>
</f:section>
</j:jelly>
</j:jelly>

0 comments on commit ceb74d7

Please sign in to comment.