AuthAdapters

Auth Adapters are customizable authentication modules that can be used with Myna’s permissions system or separately.  An adapter is a combination of a auth_type config file ( /WEB-INF/myna/auth_types/) and an implementation (/shared/js/libOO/auth_adapters).  Myna currently comes with 3 implementations (server_admin, myna, and ldap) and 2 pre-defined auth_types (myna and server_admin). auth_types are analogous to DataSources and auth_adapters are analogous to database drivers.  Here is an example of authenticating a username and password against the server_admin adapter:

var adapter = Myna.Permissions.getAuthAdapter("server_admin");
var adminPassword ="...";
if (adapter.isCorrectPassword("admin",$req.data.password)){
Myna.print("is good")
} else {
Myna.print("is bad")
}

An even more powerfull way to use adapters is in conjunction with the permissions system.  Here is an excerpt from the db_manager authentication function:

var user = Myna.Permissions.getUserByAuth(data.username,data.password)

if (user){
$cookie.setAuthUserId(user.get_user_id());
if (user.hasRight("myna_admin","full_admin_access")){
print({success:true,url:"?fuseaction="+$application.mainFuseAction}.toJson());
} else {
print({success:false,errorMsg:"You do not have access to this application."}.toJson());
}
} else {
$session.clear();
$cookie.clearAuthUserId();
print({success:false,errorMsg:"Login invalid. Please try again."}.toJson());
}

Myna.Permissions.getUserByAuth(username,password[,auth_type]) attempts to authenticate against the indicated adapter, and then look up and return the associated user for that login.  We can then check to see if that user has any rights in this application.  Calling getUserByAuth without specifying an adapter, as in the code above, causes myna to authenticate against every available adapter until there is a match.  Matching more than one user is considered a failure since Myna cannot tell which login is correct.  Because a User can have many logins, it is possible for a given user to authenticate successfully via more than one adapter.  For example, a user may have a local Myna login and an Active Directory (ldap) login.