01: package org.esupportail.cas.server.handlers.database;
02:
03: import java.sql.Connection;
04:
05: import org.dom4j.Element;
06: import org.esupportail.cas.server.util.RedundantHandler;
07:
08: /**
09: * This class implements a database server class, which can
10: * authenticate users by binding to a database. It is used by
11: * BindDatabaseHandler.
12: *
13: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
14: * @author Jean-Baptiste Daniel <danielj at users.sourceforge.net>
15: */
16: public final class BindDatabaseServer extends DatabaseServer {
17:
18: /**
19: * Constructor.
20: *
21: * @param handlerDebug debugging mode of the handler
22: * @param handler the handler the server will be used by
23: * @param serverElement the XML element that declares the server
24: * @throws Exception Exception
25: */
26: public BindDatabaseServer(final Boolean handlerDebug,
27: final RedundantHandler handler, final Element serverElement)
28: throws Exception {
29: super (handlerDebug, handler, serverElement);
30: traceBegin();
31: traceEnd();
32: }
33:
34: /**
35: * Try to authenticate a user (by binding to the database).
36: *
37: * @param username the user's name
38: * @param password the user's password
39: *
40: * @return Server.AUTHENTICATE_SUCCESS, Server.AUTHENTICATE_NOAUTH
41: * or Server.AUTHENTICATE_FAILURE.
42: */
43: public int authenticate(final String username, final String password) {
44: traceBegin();
45:
46: Connection connection = connect(username, password);
47:
48: switch (getConnectError()) {
49: case CONNECT_SUCCESS:
50: trace("Connection succeeded.");
51: traceEnd("AUTHENTICATE_SUCCESS");
52: return AUTHENTICATE_SUCCESS;
53: case CONNECT_NOAUTH:
54: trace("Connection refused.");
55: traceEnd("AUTHENTICATE_NOAUTH");
56: return AUTHENTICATE_NOAUTH;
57: default:
58: trace("Connection failure.");
59: traceEnd("AUTHENTICATE_FAILURE");
60: return AUTHENTICATE_FAILURE;
61: }
62: }
63:
64: }
|