001 package org.esupportail.cas.server.handlers.reject;
002
003 import org.dom4j.Element;
004 import org.esupportail.cas.server.util.BasicHandler;
005
006 /**
007 * This class implements an reject handler handler class. It is used by
008 * GenericHandler to exclude registred users.
009 *
010 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
011 */
012 public final class RejectHandler extends BasicHandler {
013
014 /**
015 * The id of the user that will be rejected.
016 */
017 private String userId;
018
019 /**
020 * Constructor.
021 *
022 * @param handlerElement the XML element that declares the handler
023 * in the configuration file
024 * @param configDebug debugging mode of the global configuration
025 * @throws Exception Exception
026 */
027 public RejectHandler(
028 final Element handlerElement,
029 final Boolean configDebug) throws Exception {
030 super(handlerElement, configDebug);
031 traceBegin();
032
033 checkConfigElement(true);
034
035 userId = getConfigSubElementContent("username", true/*needed*/);
036 trace("username = " + userId);
037
038 traceEnd();
039 }
040
041 /**
042 * Try to authenticate a user.
043 *
044 * @param username the user's name
045 * @param password the user's password
046 *
047 * @return BasicHandler.FAILED_STOP if username matches,
048 * BasicHandler.FAILED_CONTINUE otherwise.
049 */
050 public int authenticate(
051 final String username,
052 final String password) {
053 traceBegin();
054 if (userId.equals(username)) {
055 trace("Username matches");
056 traceEnd("FAILED_STOP");
057 return FAILED_STOP;
058 } else {
059 traceEnd("FAILED_CONTINUE");
060 return FAILED_CONTINUE;
061 }
062 }
063
064 }
065