01: package CustomDNS.ZoneAuthenticator;
02:
03: import java.sql.*;
04: import net.espeak.infra.cci.exception.*;
05: import net.espeak.jesi.*;
06:
07: import ZoneAuthenticatorIntf;
08:
09: /*************************************************************************
10: * Implements our zone authenticator service.
11: *************************************************************************
12: * @see CustomDNS.ZoneAuthenticator.Server
13: */
14:
15: public class Implementation implements ZoneAuthenticatorIntf {
16: // Our database connection.
17: Connection database;
18:
19: // Our query strings.
20: static final String authQuery = "select * from owner, host"
21: + " where owner.email = host.email and"
22: + " owner.email = ? and"
23: + " owner.password = ? and"
24: + " host.dnsname = ?";
25:
26: /*********************************************************************
27: * Create a new zone authenticator.
28: *********************************************************************
29: * @param database A JDBC connection to the database holding our
30: * user records.
31: */
32:
33: public Implementation(Connection database) {
34: this .database = database;
35: }
36:
37: /*********************************************************************
38: * Decide whether a given hostname belongs to a given user.
39: *********************************************************************
40: * This function is called remotely via e-speak.
41: * @param username The name of the user.
42: * @param passwd The password provided by the user.
43: * @param hostname The fully qualified domain name of the host.
44: * @return True if the user owns the hostname, false otherwise.
45: * @exception ESInvocationException Thrown when an error is detected
46: * during remote invocation.
47: */
48:
49: public boolean authenticateUser(String username, String passwd,
50: String hostname) throws ESInvocationException {
51: try {
52:
53: // Look up the user and the hostname.
54: PreparedStatement s = database.prepareStatement(authQuery);
55: s.setString(1, username);
56: s.setString(2, passwd);
57: s.setString(3, hostname);
58: s.executeQuery();
59:
60: // Return true if any records matched.
61: if (s.getResultSet().next())
62: return true;
63: else
64: return false;
65:
66: } catch (Exception e) {
67: // XXX - We should do something more intelligent here.
68: System.err.println(e.toString());
69: return false;
70: }
71: }
72: }
|