Security

(security)

Constants Summary

TypeNameSummary

Constant representing the accessible flag for form security..

Constant representing the delete flag for table security..

Constant representing the insert flag for table security..

Constant representing the read flag for table security..

Constant representing the tracking flag for table security (tracks sql insert/update/delete)..

Constant representing the tracking flag for table security (tracks sql select)..

Constant representing the update flag for table security..

Constant representing the viewable flag for form security..

Methods Summary

TypeNameSummary

Gives a user a permission Note: this method can only be called by an admin..

Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator..

Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator..

Returns whether form is accessible..

Returns whether element from form is accessible..

Returns a boolean value for security rights..

Returns a boolean value for security rights..

Returns a boolean value for security rights..

Returns a boolean value for security rights..

Returns whether form is viewable..

Returns whether element from form is viewable..

Changes the username of the specified userUID..

Returns true if the password for that userUID is correct, else false..

Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist)..

Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist)..

Deletes an user..

Returns the client ID..

Returns the form elements UUID's as dataset, the one with no name is the form itself..

Get all the permissions of the solution (returns a dataset)..

Get all the permissions for given user UID..

Retrieves the username of the currently logged in user on operating system level..

Retrieve the tenant value for this Client, this value will be used as the value for all tables that have a column marked as a tenant column..

Get the current user name (null if not logged in), finds the user name for given user UID if passed as parameter..

Get the current user name (null if not logged in), finds the user name for given user UID if passed as parameter..

Get all the permissions of the current user..

Get the current user UID (null if not logged in); finds the userUID for given user_name if passed as parameter..

Get the current user UID (null if not logged in); finds the userUID for given user_name if passed as parameter..

Get all the users in the security settings (returns a dataset)..

Get all the users in the security settings (returns a dataset)..

Check if the current user has the given permission.

Check if the given user has the given permission.

Login to be able to leave the solution loginForm..

void

Logout the current user and close the solution, if the solution requires authentication and user is logged in..

void

Logout the current user and close the solution, if the solution requires authentication and user is logged in..

void

Logout the current user and close the solution, if the solution requires authentication and user is logged in..

void

Logout the current user and close the solution, if the solution requires authentication and user is logged in..

void

Logout the current user and close the solution, if the solution requires authentication and user is logged in..

Removes an permission from a user..

Set a new password for the given userUID..

void

Sets the security settings; the entries contained in the given dataset will override those contained in the current security settings..

void

Set the tenant value for this Client, this value will be used as the value for all tables that have a column marked as a tenant column..

Set a new userUID for the given userUID..

Constants Details

ACCESSIBLE

Constant representing the accessible flag for form security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

DELETE

Constant representing the delete flag for table security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

INSERT

Constant representing the insert flag for table security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

READ

Constant representing the read flag for table security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

TRACKING

Constant representing the tracking flag for table security (tracks sql insert/update/delete).

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

TRACKING_VIEWS

Constant representing the tracking flag for table security (tracks sql select).

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

UPDATE

Constant representing the update flag for table security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

VIEWABLE

Constant representing the viewable flag for form security.

Returns Number

Sample

var colNames = new Array();
colNames[0] = 'uuid';
colNames[1] = 'flags';
var dataset = databaseManager.createEmptyDataSet(0,colNames);

var row = new Array();
row[0] = '413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)
row[1] = JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for both
dataset.addRow(row);//setting element security

row = new Array();
row[0] = 'example_data.orders';
row[1] = JSSecurity.READ|JSSecurity.INSERT|JSSecurity.UPDATE|JSSecurity.DELETE|JSSecurity.TRACKING; //use bitwise 'or' for multiple flags
dataset.addRow(row);//setting table security

security.setSecuritySettings(dataset);//to be called in solution startup method

Methods Details

addPermissionToUser(a_userUID, permission)

Gives a user a permission Note: this method can only be called by an admin.

Parameters Object a_userUID the user UID to be added Object permission the permission to add to

Returns Boolean true if added

Sample

var userUID = security.getUserUID();
security.addPermissionToUser(userUID, 'permission');

authenticate(authenticator_solution, method)

Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator.

Note: this method should be called from a login solution.

Parameters String authenticator_solution authenticator solution installed on the Servoy Server, null for servoy built-in authentication String method authenticator method, null for servoy built-in authentication

Returns Object authentication result from authenticator solution or boolean in case of servoy built-in authentication

Sample

// create the credentials object as expected by the authenticator solution
var ok =  security.authenticate('myldap_authenticator', 'login', [scopes.globals.userName, scopes.globals.passWord])
if (!ok)
{
	plugins.dialogs.showErrorDialog('Login failed', 'OK')
}

// if no authenticator name is used, the credentials are checked using the Servoy built-in user management
ok = security.authenticate(null, null, [scopes.globals.userName, scopes.globals.passWord])

authenticate(authenticator_solution, method, credentials)

Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator.

Note: this method should be called from a login solution, once logged in, the authenticate method has no effect.

Parameters String authenticator_solution authenticator solution installed on the Servoy Server, null for servoy built-in authentication String method authenticator method, null for servoy built-in authentication Array credentials array whose elements are passed as arguments to the authenticator method, in case of servoy built-in authentication this should be [username, password]

Returns Object authentication result from authenticator solution or boolean in case of servoy built-in authentication

Sample

// create the credentials object as expected by the authenticator solution
var ok =  security.authenticate('myldap_authenticator', 'login', [scopes.globals.userName, scopes.globals.passWord])
if (!ok)
{
	plugins.dialogs.showErrorDialog('Login failed', 'OK')
}

// if no authenticator name is used, the credentials are checked using the Servoy built-in user management
ok = security.authenticate(null, null, [scopes.globals.userName, scopes.globals.passWord])

canAccess(formName)

Returns whether form is accessible.

security.canAccess(formName)

Parameters String formName form name

Returns Boolean true if accessible

Sample

canAccess(formName, elementName)

Returns whether element from form is accessible.

security.canAccess(formName,elementName)

Parameters String formName form name String elementName element name from specified form

Returns Boolean true if accessible

Sample

canDelete(dataSource)

Returns a boolean value for security rights.

Parameters String dataSource the datasource

Returns Boolean true if allowed

Sample

var dataSource = controller.getDataSource();
var canDelete = security.canDelete(dataSource);
var canInsert = security.canInsert(dataSource);
var canUpdate = security.canUpdate(dataSource);
var canRead = security.canRead(dataSource);
application.output("Can delete? " + canDelete);
application.output("Can insert? " + canInsert);
application.output("Can update? " + canUpdate);
application.output("Can read? " + canRead);

canInsert(dataSource)

Returns a boolean value for security rights.

Parameters String dataSource the datasource

Returns Boolean true if allowed

Sample

var dataSource = controller.getDataSource();
var canDelete = security.canDelete(dataSource);
var canInsert = security.canInsert(dataSource);
var canUpdate = security.canUpdate(dataSource);
var canRead = security.canRead(dataSource);
application.output("Can delete? " + canDelete);
application.output("Can insert? " + canInsert);
application.output("Can update? " +