001: package org.esupportail.cas.server.handlers.ldap;
002:
003: import org.dom4j.Element;
004: import org.esupportail.cas.server.util.MisconfiguredHandlerException;
005:
006: /**
007: * This class implements a bind LDAP handler class. It is used by
008: * GenericHandler.
009: *
010: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
011: */
012: public final class BindLdapHandler extends LdapHandler {
013:
014: /**
015: * the base for LDAP searches.
016: */
017: private String searchBase;
018:
019: /**
020: * the scope for LDAP searches.
021: */
022: private String scope;
023:
024: /**
025: * the DN to bind to the LDAP directory.
026: */
027: private String bindDn;
028:
029: /**
030: * the password to bind to the LDAP directory.
031: */
032: private String bindPassword;
033:
034: /**
035: * A flag set to true if multiple accounts in the LDAP directory are allowed.
036: */
037: private boolean multipleAccountsEnabled;
038:
039: /**
040: * Constructor.
041: *
042: * @param handlerElement the XML element that declares the handler
043: * in the configuration file
044: * @param configDebug debugging mode of the global configuration
045: * @throws Exception Exception
046: */
047: public BindLdapHandler(final Element handlerElement,
048: final Boolean configDebug) throws Exception {
049: super (handlerElement, configDebug);
050: traceBegin();
051:
052: searchBase = getConfigSubElementContent("search_base", true/*needed*/);
053: trace("search_base = " + searchBase);
054:
055: scope = getConfigSubElementContent("scope", true/*needed*/);
056: trace("scope = " + scope);
057:
058: bindDn = getConfigSubElementContent("bind_dn", false/*not needed*/);
059: if (bindDn.equals("")) {
060: trace("An anonymous connection to the LDAP directory will be used.");
061: bindPassword = "";
062: } else {
063: bindPassword = getConfigSubElementContent("bind_password",
064: false/*not needed*/);
065: }
066: trace("bind_dn = " + bindDn);
067: trace("bind_password = " + bindPassword);
068:
069: boolean enableMultipleAccounts = hasConfigSubElement("enable_multiple_accounts");
070: boolean disableMultipleAccounts = hasConfigSubElement("disable_multiple_accounts");
071:
072: if (enableMultipleAccounts && disableMultipleAccounts) {
073: traceThrow(new MisconfiguredHandlerException(
074: "enable_multiple_accounts and disable_multiple_accounts "
075: + "tags can not be used simultaneously"));
076: }
077: multipleAccountsEnabled = false;
078: if (enableMultipleAccounts) {
079: multipleAccountsEnabled = true;
080: }
081: trace("enable_multiple_accounts = " + multipleAccountsEnabled);
082:
083: // add the LDAP servers
084: addServers(true/*serverElementNeeded*/, getClass()
085: .getPackage().getName()
086: + ".BindLdapServer");
087:
088: traceEnd();
089: }
090:
091: /**
092: * Retrieve the base for LDAP searches.
093: *
094: * @return a string.
095: */
096: String getSearchBase() {
097: return searchBase;
098: }
099:
100: /**
101: * Retrieve the scope for LDAP searches.
102: *
103: * @return a string.
104: */
105: String getScope() {
106: return scope;
107: }
108:
109: /**
110: * Retrieve the DN to bind to the LDAP directory.
111: *
112: * @return a string.
113: */
114: String getBindDn() {
115: return bindDn;
116: }
117:
118: /**
119: * Retrieve the password to bind to the LDAP directory.
120: *
121: * @return a string.
122: */
123: String getBindPassword() {
124: return bindPassword;
125: }
126:
127: /**
128: * Tell if multiple accounts in the LDAP directory are allowed.
129: *
130: * @return a boolean.
131: */
132: protected boolean areMultipleAccountsEnabled() {
133: return multipleAccountsEnabled;
134: }
135: }
|