001 package org.esupportail.cas.server.handlers.nis;
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(
044 final Element handlerElement,
045 final Boolean configDebug) throws Exception {
046 super(handlerElement, configDebug);
047 traceBegin();
048
049 checkConfigElement(true);
050
051 domain = getConfigSubElementContent("domain", true/*needed*/);
052 trace("domain = " + domain);
053
054 map = getConfigSubElementContent("map", false/*not needed*/);
055 if (map.equals("")) {
056 map = "passwd.byname";
057 }
058 trace("map = " + map);
059
060 encryption = getConfigSubElementContent("encryption", false/*not needed*/);
061 if (encryption.equals("")) {
062 encryption = "pammd5";
063 }
064 if (!Crypt.isEncryptionSupported(encryption)) {
065 traceThrow(new MisconfiguredHandlerException(
066 "Encryption \""
067 + encryption
068 + "\" is not supported."));
069 }
070 trace("encryption = " + encryption);
071 if (encryption.equals("plain")) {
072 traceThrow(new MisconfiguredHandlerException("Can not use plain passwords with NIS."));
073 }
074
075 // add the NisServer instances
076 addServers(true/*serverElementNeeded*/, getClass().getPackage().getName() + ".NisServer");
077
078 // check that the JNDI class exists
079 checkClass("com.sun.jndi.nis.NISCtxFactory");
080
081 traceEnd();
082 }
083
084 /**
085 * Retrieve the map name.
086 *
087 * @return a String Object.
088 */
089 String getMap() {
090 return map;
091 }
092
093 /**
094 * Retrieve the NIS domain name.
095 *
096 * @return a String Object.
097 */
098 String getDomain() {
099 return domain;
100 }
101
102 /**
103 * Retrieve the encryption used to store passwords.
104 *
105 * @return a String Object.
106 */
107 String getEncryption() {
108 return encryption;
109 }
110
111 }
112