001 package org.esupportail.cas.server.handlers.nt;
002
003 import org.dom4j.Element;
004 import org.esupportail.cas.server.util.RedundantHandler;
005 import org.esupportail.cas.server.util.Server;
006 import org.esupportail.cas.server.util.log.Log;
007
008 /**
009 * This class implements a NIS (Network Information Service) server.
010 *
011 * @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
012 */
013 public final class NtServer extends Server {
014
015 /**
016 * The server hostname or IP address.
017 */
018 private String host;
019
020 /**
021 * Constructor.
022 *
023 * @param handlerDebug debugging mode of the handler
024 * @param handler the handler the server will be used by
025 * @param serverElement the XML element that declares the server
026 * @throws Exception Exception
027 */
028 public NtServer(
029 final Boolean handlerDebug,
030 final RedundantHandler handler,
031 final Element serverElement) throws Exception {
032 super(handlerDebug, handler, serverElement);
033 traceBegin();
034
035 host = getServerSubElementContent(serverElement, "host", true/*needed*/);
036 trace("host = " + host);
037
038 Log.warn("NtHandler is not implemented in this version; users will never be authenticted this way.");
039
040 traceEnd();
041 }
042
043
044 /**
045 * Try to authenticate a user (by searching into a NT domain).
046 *
047 * @param username the user's name
048 * @param password the user's password
049 *
050 * @return Server.AUTHENTICATE_SUCCESS, Server.AUTHENTICATE_NOAUTH
051 * or Server.AUTHENTICATE_FAILURE.
052 */
053 public int authenticate(
054 final String username,
055 final String password) {
056 traceBegin();
057 // TODO add Todd's code
058 NtHandler handler = (NtHandler) getHandler();
059
060 // remove this later:
061 traceEnd("AUTHENTICATE_FAILURE");
062 return AUTHENTICATE_FAILURE;
063
064 // Todd, all the rest is the NIS authentication, maybe you can use it as a frame
065 //
066 // String url = "nis://" + _host + "/" + handler.getDomain();
067 // String map = handler.getMap();
068 //
069 // try {
070 // trace("Connecting to the NIS domain...");
071 // Hashtable hashtable = new Hashtable(5, 0.75f);
072 // hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.nis.NISCtxFactory");
073 // hashtable.put(Context.PROVIDER_URL, url);
074 // hashtable.put(Context.SECURITY_AUTHENTICATION, "simple");
075 // InitialContext context = new InitialDirContext(hashtable);
076 //
077 // trace("Retrieving the information corresponding to the user...");
078 // String nisEntry = context.lookup("system/" + map + "/" + username).toString();
079 //
080 // // we've got all needed information, close the context
081 // context.close();
082 //
083 // trace("Username found, checking password (" + handler.getEncryption() + ")...");
084 // // extracting the encrypted password
085 // String[] nisFields = nisEntry.split(":");
086 // String nisEncryptedPassword = nisFields[1];
087 //
088 // // compare the passwords
089 // boolean match = Crypt.match(handler.getEncryption(),password, nisEncryptedPassword);
090 //
091 // if (Crypt.match(handler.getEncryption(),password, nisEncryptedPassword)) {
092 // trace("Password matches.");
093 // traceEnd("AUTHENTICATE_SUCCESS");
094 // return AUTHENTICATE_SUCCESS;
095 // } else {
096 // trace("Password does not match.");
097 // traceEnd("AUTHENTICATE_NOAUTH");
098 // return AUTHENTICATE_NOAUTH;
099 // }
100 // } catch (javax.naming.NoInitialContextException e) {
101 // warn(e.toString());
102 // warn("JNDI nis provider (nis.jar) is probably not installed");
103 // traceEnd("AUTHENTICATE_FAILURE");
104 // return AUTHENTICATE_FAILURE;
105 // } catch (javax.naming.ConfigurationException e) {
106 // warn("Bad NIS configuration: " + e.getMessage());
107 // traceEnd("AUTHENTICATE_FAILURE");
108 // return AUTHENTICATE_FAILURE;
109 // } catch (javax.naming.CommunicationException e) {
110 // warn("NIS server not responding.");
111 // traceEnd("AUTHENTICATE_FAILURE");
112 // return AUTHENTICATE_FAILURE;
113 // } catch (javax.naming.CannotProceedException e) {
114 // warn("Can not proceed: " + e.getMessage());
115 // traceEnd("AUTHENTICATE_NOAUTH");
116 // return AUTHENTICATE_NOAUTH;
117 // } catch (javax.naming.NameNotFoundException e) {
118 // trace("Username not found: " + e.getMessage());
119 // traceEnd("AUTHENTICATE_NOAUTH");
120 // return AUTHENTICATE_NOAUTH;
121 // } catch (Exception e) {
122 // warn("Failure: " + e.toString());
123 // traceEnd("AUTHENTICATE_FAILURE");
124 // return AUTHENTICATE_FAILURE;
125 // }
126 }
127
128 }
129