added global authenticate() function that authenticates

a user against a standard Unix passwd file.
This commit is contained in:
hns 2001-03-22 17:58:51 +00:00
parent 2ba56a02cb
commit df78802f57
2 changed files with 31 additions and 0 deletions

View file

@ -76,6 +76,8 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
protected CacheMap skincache = new CacheMap (100);
private CryptFile pwfile;
public Application () throws RemoteException {
super ();
@ -112,6 +114,11 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
File propfile = new File (appDir, "app.properties");
props = new SystemProperties (propfile.getAbsolutePath (), sysProps);
File pwf = new File (home, "passwd");
CryptFile parentpwfile = new CryptFile (pwf, null);
pwf = new File (appDir, "passwd");
pwfile = new CryptFile (pwf, parentpwfile);
nmgr = new NodeManager (this, dbDir.getAbsolutePath (), props);
debug = "true".equalsIgnoreCase (props.getProperty ("debug"));
@ -432,6 +439,17 @@ public class Application extends UnicastRemoteObject implements IRemoteApp, Runn
return true;
}
/**
* In contrast to login, this works outside the Hop user object framework. Instead, the user is
* authenticated against a passwd file in the application directory. This is to have some sort of
* authentication available *before* the application is up and running, i.e. for application setup tasks.
*/
public boolean authenticate (String uname, String password) {
if (uname == null || password == null)
return false;
return pwfile.authenticate (uname, password);
}
public String getNodePath (INode n, String tmpname) {
INode root = getDataRoot ();
INode users = getUserRoot ();

View file

@ -108,6 +108,7 @@ public class HopExtension {
go.putHiddenProperty("createSkin", new GlobalCreateSkin ("createSkin", evaluator, fp));
go.putHiddenProperty("renderSkin", new RenderSkin ("renderSkin", evaluator, fp, reval, true, false));
go.putHiddenProperty("renderSkin_as_string", new RenderSkin ("renderSkin_as_string", evaluator, fp, reval, true, true));
go.putHiddenProperty("authenticate", new GlobalAuthenticate ("authenticate", evaluator, fp));
go.deleteProperty("exit", "exit".hashCode());
// and some methods for session management from JS...
@ -558,6 +559,18 @@ public class HopExtension {
}
}
class GlobalAuthenticate extends BuiltinFunctionObject {
GlobalAuthenticate (String name, Evaluator evaluator, FunctionPrototype fp) {
super (fp, evaluator, name, 1);
}
public ESValue callFunction (ESObject thisObject, ESValue[] arguments) throws EcmaScriptException {
if (arguments.length != 2)
return ESBoolean.makeBoolean (false);
return ESBoolean.makeBoolean (app.authenticate (arguments[0].toString (), arguments[1].toString ()));
}
}
/**
* Get a parsed Skin from the central skin cache if possible, otherwise create it
*/