01: package org.esupportail.cas.server.handlers.example;
02:
03: import org.dom4j.Element;
04: import org.esupportail.cas.server.util.BasicHandler;
05:
06: /**
07: * This class implements a very simple handler accepting one
08: * particular login/password.
09: *
10: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
11: */
12: public final class ExampleHandler extends BasicHandler {
13:
14: /** the only netId that the handler will accept */
15: private String login;
16:
17: /** the associated password */
18: private String password;
19:
20: /**
21: * Analyse the XML configuration to set netId and password attributes (constructor).
22: *
23: * @param handlerElement the XML element that declares the handler in the configuration file
24: * @param configDebug debugging mode of the global configuration (set by default to the handler)
25: *
26: * @throws Exception when the handler not configured correctly
27: */
28: public ExampleHandler(final Element handlerElement,
29: final Boolean configDebug) throws Exception {
30: super (handlerElement, configDebug);
31: traceBegin();
32:
33: // check that a config element is present
34: checkConfigElement(true);
35:
36: // get the configuration parameters
37: login = getConfigSubElementContent("login", true/*needed*/);
38: trace("login = " + login);
39: password = getConfigSubElementContent("password", true/*needed*/);
40: trace("password = " + password);
41:
42: traceEnd();
43: }
44:
45: /**
46: * Try to authenticate a user (compare with the local credentials).
47: *
48: * @param userLogin the user's login
49: * @param userPassword the user's password
50: *
51: * @return BasicHandler.SUCCEDED on success,
52: * BasicHandler.FAILED_CONTINUE or BasicHandler.FAILED_STOP otherwise.
53: */
54: public int authenticate(final String userLogin,
55: final String userPassword) {
56: traceBegin();
57:
58: trace("Checking user's login...");
59: if (userLogin.equals(login) && userPassword.equals(password)) {
60: trace("Users's login matches, checking user's password...");
61: if (userPassword.equals(password)) {
62: trace("User's password matches.");
63: traceEnd("SUCCEEDED");
64: return SUCCEEDED;
65: } else {
66: trace("User's password does not match (no more handler should be tried).");
67: traceEnd("FAILED_STOP");
68: return FAILED_STOP;
69: }
70: } else {
71: trace("User's login does not match (another handler can be tried).");
72: traceEnd("FAILED_CONTINUE");
73: return FAILED_CONTINUE;
74: }
75: }
76: }
|