1 /***
2 * Copyright 2007 The JA-SIG Collaborative. All rights reserved.
3 * See license distributed with this file and
4 * available online at http://www.uportal.org/license.html
5 */
6 package org.jasig.irclog.events.handlers;
7
8 import java.util.HashMap;
9 import java.util.Map;
10
11 import org.apache.commons.lang.Validate;
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.jasig.irclog.events.ConnectEvent;
15 import org.jasig.irclog.events.IrcEvent;
16 import org.jibble.pircbot.PircBot;
17
18 /***
19 * @author Eric Dalquist
20 * @version $Revision$
21 */
22 public class NickAuthHandler implements IrcEventHandler {
23 protected final Log logger = LogFactory.getLog(this.getClass());
24
25 private Map<String, String> passwords = new HashMap<String, String>(0);
26
27 /***
28 * @return the passwords
29 */
30 public Map<String, String> getPasswords() {
31 return this.passwords;
32 }
33 /***
34 * @param passwords Map of Nicks to Passwords to be used for identifications.
35 */
36 public void setPasswords(Map<String, String> passwords) {
37 Validate.notNull(passwords, "Passwords Map can not be null");
38 this.passwords = passwords;
39 }
40 public void addPassword(String nick, String password) {
41 this.passwords.put(nick, password);
42 }
43
44
45
46
47
48 public void handleEvent(IrcEvent event) {
49 if (event instanceof ConnectEvent) {
50 final PircBot bot = event.getSource();
51 final String nick = bot.getNick();
52 final String password = this.passwords.get(nick);
53
54 if (password != null) {
55 if (this.logger.isInfoEnabled()) {
56 this.logger.info("Authenticating '" + nick + "'.");
57 }
58
59 bot.identify(password);
60 }
61 else if (this.logger.isInfoEnabled()) {
62 this.logger.info("No password set for '" + nick + "', not authenticating.");
63 }
64 }
65 }
66
67 }