01: package org.esupportail.cas.server.handlers.ldap;
02:
03: import org.dom4j.Element;
04: import org.esupportail.cas.server.util.RedundantHandler;
05:
06: /**
07: * This class implements an LDAP server class, which can
08: * authenticate users by directly binding to an LDAP directory
09: * (fastbind method). It is used by FastBindLdapHandler.
10: *
11: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
12: */
13: public final class FastBindLdapServer extends LdapServer {
14:
15: /**
16: * Constructor.
17: *
18: * @param handlerDebug debugging mode of the handler
19: * @param handler the handler the server will be used by
20: * @param serverElement the XML element that declares the server
21: * @throws Exception Exception
22: */
23: public FastBindLdapServer(final Boolean handlerDebug,
24: final RedundantHandler handler, final Element serverElement)
25: throws Exception {
26: super (handlerDebug, handler, serverElement);
27: traceBegin();
28: traceEnd();
29: }
30:
31: /**
32: * Try to authenticate a user (by binding to the LDAP directory).
33: *
34: * @param username the user's name
35: * @param password the user's password
36: *
37: * @return Server.AUTHENTICATE_SUCCESS, Server.AUTHENTICATE_NOAUTH
38: * or Server.AUTHENTICATE_FAILURE.
39: */
40: public int authenticate(final String username, final String password) {
41: traceBegin();
42:
43: FastBindLdapHandler handler = (FastBindLdapHandler) getHandler();
44:
45: connectAndClose(replaceTokens(handler.getFilter(), username),
46: 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: }
|