01: package org.esupportail.cas.server.handlers.reject;
02:
03: import org.dom4j.Element;
04: import org.esupportail.cas.server.util.BasicHandler;
05:
06: /**
07: * This class implements an reject handler handler class. It is used by
08: * GenericHandler to exclude registred users.
09: *
10: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
11: */
12: public final class RejectHandler extends BasicHandler {
13:
14: /**
15: * The id of the user that will be rejected.
16: */
17: private String userId;
18:
19: /**
20: * Constructor.
21: *
22: * @param handlerElement the XML element that declares the handler
23: * in the configuration file
24: * @param configDebug debugging mode of the global configuration
25: * @throws Exception Exception
26: */
27: public RejectHandler(final Element handlerElement,
28: final Boolean configDebug) throws Exception {
29: super (handlerElement, configDebug);
30: traceBegin();
31:
32: checkConfigElement(true);
33:
34: userId = getConfigSubElementContent("username", true/*needed*/);
35: trace("username = " + userId);
36:
37: traceEnd();
38: }
39:
40: /**
41: * Try to authenticate a user.
42: *
43: * @param username the user's name
44: * @param password the user's password
45: *
46: * @return BasicHandler.FAILED_STOP if username matches,
47: * BasicHandler.FAILED_CONTINUE otherwise.
48: */
49: public int authenticate(final String username, final String password) {
50: traceBegin();
51: if (userId.equals(username)) {
52: trace("Username matches");
53: traceEnd("FAILED_STOP");
54: return FAILED_STOP;
55: } else {
56: traceEnd("FAILED_CONTINUE");
57: return FAILED_CONTINUE;
58: }
59: }
60:
61: }
|