Listed below are some typical security implementations in Servoy applications.

Basic Servoy Authentication 

Practical where the security will be managed by the developer of the application and does not require anyone else configuring users or permissions.

Steps

Custom Authentication

To allow tenant administrators or "super users" to adminstrate users, or if you are using an external authentication source, you must create custom authentication.  Custom authentication will allow the developer to use a users table in the database for authentication or access an external authentication directory.

 To use external authentication, most likely a plugin is required.

Steps

When first introduced in Servoy, this method of using Login and Authenticator solutions was referred to as Enhanced Security. If you are looking for any references to this method in other resources (such as the Servoy Forum), you may try searching Enhanced Security.

Solution onOpen Method

For almost every implementation of security, the solution should have an onOpen method assigned. This event is triggered right after the authentication process is complete. Some of the functions of this method in regards to security include:

Example Login Method

The code below is an example of a typical custom login method. In this scenario, the login page contains the following form variables:

The tenant is verified during login before actual authentication occurs.

function login(){

	errorMessage = null;

	if(!userName){
		errorMessage = 'Please specify a user name';
		return false;
	}
	if(!password){
		errorMessage = 'Please specify a password';
		return false;
	}

	var tenantID = security.authenticate("myAuthenticator","getTenant",[userName]);
	if(tenantID){
		if(security.authenticate("myAuthenticator","loginUser",[userName,password])){
			return true;
		} else {
			errorMessage = "No tenant found. Please check your password";
		}
	}
	errorMessage = 'Login Failed';
}

Example Authentication Method

The code below is an example of a typical authentication method.

function loginUser(user, password) {
	if (!(user && password)) {
		application.output('Unexpected credentials received', LOGGINGLEVEL.DEBUG);
		return false;
	}
	var authenticated = ... //either query database or use LDAP

	if (authenticated) {
		var ok = security.login(user, user, ['group']) // Assume a group for each department
		application.output('User ' + user + ' authenticated: ' + ok, LOGGINGLEVEL.DEBUG);
		return ok;
	}
	application.output('User ' + user + ' could not be authenticated', LOGGINGLEVEL.DEBUG);
	// Sleep for 3 seconds to discourage brute force attacks
	application.sleep(3000);
	return false;
}

When authentication fails, adding a pauze can be useful to discourage brute force password attacks.

Note that you have the choice of querying the database or getting an external authentication.  You may also read a user groups table to create the array of groups the user has privileges with. Also not that the only thing that is returned is a true or false and that reporting errors to the user does not occur at the authenticator level.

Fully Custom Security

In a fully custom security implementation, both authentication and authorization information is handled outside of Servoy built in security paradigm.

Steps

The developer writes code to assign form and table security to each part of the solution.  This style of solution is normally managed by exclusion: instead of assigning permission to every part, just assign permissions to the part you want controlled.  An example of this working can be found on the ServoyForge site in the Security framework.