001: package org.esupportail.cas.server.handlers.nis.multiple;
002:
003: import org.dom4j.Element;
004: import org.esupportail.cas.server.util.MisconfiguredHandlerException;
005: import org.esupportail.cas.server.util.RedundantHandler;
006: import org.esupportail.cas.server.util.crypt.Crypt;
007:
008: // TODO Nis broadcast
009: // The NIS domain can not be bound by broadcast. The 'nis:///domain' should work according to
010: // http://rzm-hamy-wsx.rz.uni-karlsruhe.de/Training/JNDI/instances/common/nis-provider/doc/providers/jndi-nis.html,
011: // but it does not :-(
012:
013: /**
014: * This class implements a NIS (Network Information Service) handler
015: * class. It is used by GenericHandler.
016: *
017: * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
018: * @author Jean-Baptiste Daniel <danielj at sourceforge.net>
019: */
020: public final class NisHandler extends RedundantHandler {
021:
022: /**
023: * The NIS domain to bind to.
024: */
025: private String domain;
026: /**
027: * The map to search into.
028: */
029: private String map;
030: /**
031: * The encryption used to store the passwords.
032: */
033: private String encryption;
034:
035: /**
036: * Constructor.
037: *
038: * @param handlerElement the XML element that declares the handler
039: * in the configuration file
040: * @param configDebug debugging mode of the global configuration
041: * @throws Exception Exception
042: */
043: public NisHandler(final Element handlerElement,
044: final Boolean configDebug) throws Exception {
045: super (handlerElement, configDebug);
046: traceBegin();
047:
048: checkConfigElement(true);
049:
050: domain = getConfigSubElementContent("domain", true/*needed*/);
051: trace("domain = " + domain);
052:
053: map = getConfigSubElementContent("map", false/*not needed*/);
054: if (map.equals("")) {
055: map = "passwd.byname";
056: }
057: trace("map = " + map);
058:
059: encryption = getConfigSubElementContent("encryption", false/*not needed*/);
060: if (encryption.equals("")) {
061: encryption = "pammd5";
062: }
063: if (!Crypt.isEncryptionSupported(encryption)) {
064: traceThrow(new MisconfiguredHandlerException(
065: "Encryption \"" + encryption
066: + "\" is not supported."));
067: }
068: trace("encryption = " + encryption);
069: if (encryption.equals("plain")) {
070: traceThrow(new MisconfiguredHandlerException(
071: "Can not use plain passwords with NIS."));
072: }
073:
074: // add the NisServer instances
075: addServers(true/*serverElementNeeded*/, getClass()
076: .getPackage().getName()
077: + ".NisServer");
078:
079: // check that the JNDI class exists
080: checkClass("com.sun.jndi.nis.NISCtxFactory");
081:
082: traceEnd();
083: }
084:
085: /**
086: * Retrieve the map name.
087: *
088: * @return a String Object.
089: */
090: String getMap() {
091: return map;
092: }
093:
094: /**
095: * Retrieve the NIS domain name.
096: *
097: * @return a String Object.
098: */
099: String getDomain() {
100: return domain;
101: }
102:
103: /**
104: * Retrieve the encryption used to store passwords.
105: *
106: * @return a String Object.
107: */
108: String getEncryption() {
109: return encryption;
110: }
111:
112: }
|