# Security

(security)

## Overview

The `security` object provides a comprehensive API for managing users, groups, and permissions in a solution. It includes constants for form and table security and methods to control user access and permissions programmatically.

Security constants such as `ACCESSIBLE`, `DELETE`, `INSERT`, `READ`, and `UPDATE` define flags for controlling access to forms and tables. These constants allow developers to set permissions using datasets and apply them at runtime.

The API includes methods for managing users, such as `createUser`, `deleteUser`, and `changeUserName`. Permissions can be assigned or removed with `addPermissionToUser` and `removePermissionFromUser`. Developers can query permissions using methods like `hasPermission` or retrieve user-related information with `getUserName` and `getUserUID`.

Authentication is supported via the `authenticate` method, which integrates with custom authenticators or Servoy's built-in system. The API also allows setting and managing tenant values to filter data access by tenant.

The `security` object facilitates dynamic security configurations and provides control over application access at a granular level.

For more information, please refer to the overall [Security](https://docs.servoy.com/guides/develop/security) documentation.

## **Returned Types**

[JSPermission](https://docs.servoy.com/reference/servoycore/dev-api/security/jspermission),

## Constants Summarized

| Type                                                                         | Name                               | Summary                                                                                       |
| ---------------------------------------------------------------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------- |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [ACCESSIBLE](#accessible)          | Constant representing the accessible flag for form security.                                  |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [DELETE](#delete)                  | Constant representing the delete flag for table security.                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [INSERT](#insert)                  | Constant representing the insert flag for table security.                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [READ](#read)                      | Constant representing the read flag for table security.                                       |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [TRACKING](#tracking)              | Constant representing the tracking flag for table security (tracks sql insert/update/delete). |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [TRACKING\_VIEWS](#tracking_views) | Constant representing the tracking flag for table security (tracks sql select).               |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [UPDATE](#update)                  | Constant representing the update flag for table security.                                     |
| [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) | [VIEWABLE](#viewable)              | Constant representing the viewable flag for form security.                                    |

## Methods Summarized

| Type                                                                                         | Name                                                                                                                  | Summary                                                                                                                                      |
| -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [addPermissionToUser(a\_userUID, permission)](#addpermissiontouser-a_useruid-permission)                              | Gives a user a permission Note: this method can only be called by an admin.                                                                  |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)                 | [authenticate(authenticator\_solution, method)](#authenticate-authenticator_solution-method)                          | Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator.                             |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)                 | [authenticate(authenticator\_solution, method, credentials)](#authenticate-authenticator_solution-method-credentials) | Authenticate to the Servoy Server using one of the installed authenticators or the Servoy default authenticator.                             |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canAccess(formName)](#canaccess-formname)                                                                            | Returns whether form is accessible.                                                                                                          |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canAccess(formName, elementName)](#canaccess-formname-elementname)                                                   | Returns whether element from form is accessible.                                                                                             |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canDelete(dataSource)](#candelete-datasource)                                                                        | Returns a boolean value for security rights.                                                                                                 |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canInsert(dataSource)](#caninsert-datasource)                                                                        | Returns a boolean value for security rights.                                                                                                 |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canRead(dataSource)](#canread-datasource)                                                                            | Returns a boolean value for security rights.                                                                                                 |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canUpdate(dataSource)](#canupdate-datasource)                                                                        | Returns a boolean value for security rights.                                                                                                 |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canView(formName)](#canview-formname)                                                                                | Returns whether form is viewable.                                                                                                            |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [canView(formName, elementName)](#canview-formname-elementname)                                                       | Returns whether element from form is viewable.                                                                                               |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [changeUserName(a\_userUID, username)](#changeusername-a_useruid-username)                                            | Changes the username of the specified userUID.                                                                                               |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [checkPassword(a\_userUID, password)](#checkpassword-a_useruid-password)                                              | Returns true if the password for that userUID is correct, else false.                                                                        |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)                 | [createUser(username, password)](#createuser-username-password)                                                       | Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist).                                      |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)                 | [createUser(username, password, userUID)](#createuser-username-password-useruid)                                      | Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist).                                      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [deleteUser(userUID)](#deleteuser-useruid)                                                                            | Deletes an user.                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getClientID()](#getclientid)                                                                                         | Returns the client ID.                                                                                                                       |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getElementUUIDs(formname)](#getelementuuids-formname)                                                                | Returns the form elements UUID's as dataset, the one with no name is the form itself.                                                        |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getPermissions()](#getpermissions)                                                                                   | Get all the permissions of the solution (returns a dataset).                                                                                 |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getPermissions(userUID)](#getpermissions-useruid)                                                                    | Get all the permissions for given user UID.                                                                                                  |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getSystemUserName()](#getsystemusername)                                                                             | Retrieves the username of the currently logged in user on operating system level.                                                            |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)                   | [getTenantValue()](#gettenantvalue)                                                                                   | 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. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getUserName()](#getusername)                                                                                         | Get the current user name (null if not logged in), finds the user name for given user UID if passed as parameter.                            |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getUserName(userUID)](#getusername-useruid)                                                                          | Get the current user name (null if not logged in), finds the user name for given user UID if passed as parameter.                            |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getUserPermissions()](#getuserpermissions)                                                                           | Get all the permissions of the current user.                                                                                                 |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getUserUID()](#getuseruid)                                                                                           | Get the current user UID (null if not logged in); finds the userUID for given user\_name if passed as parameter.                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)                 | [getUserUID(username)](#getuseruid-username)                                                                          | Get the current user UID (null if not logged in); finds the userUID for given user\_name if passed as parameter.                             |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getUsers()](#getusers)                                                                                               | Get all the users in the security settings (returns a dataset).                                                                              |
| [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) | [getUsers(groupName)](#getusers-groupname)                                                                            | Get all the users in the security settings (returns a dataset).                                                                              |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [hasPermission(permisson)](#haspermission-permisson)                                                                  | Check if the current user has the given permission                                                                                           |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [hasPermission(permission, userUID)](#haspermission-permission-useruid)                                               | Check if the given user has the given permission                                                                                             |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [login(username, a\_userUID, permissions)](#login-username-a_useruid-permissions)                                     | Login to be able to leave the solution loginForm.                                                                                            |
| void                                                                                         | [logout()](#logout)                                                                                                   | Logout the current user and close the solution, if the solution requires authentication and user is logged in.                               |
| void                                                                                         | [logout(solutionToLoad)](#logout-solutiontoload)                                                                      | Logout the current user and close the solution, if the solution requires authentication and user is logged in.                               |
| void                                                                                         | [logout(solutionToLoad, argument)](#logout-solutiontoload-argument)                                                   | Logout the current user and close the solution, if the solution requires authentication and user is logged in.                               |
| void                                                                                         | [logout(solutionToLoad, method)](#logout-solutiontoload-method)                                                       | Logout the current user and close the solution, if the solution requires authentication and user is logged in.                               |
| void                                                                                         | [logout(solutionToLoad, method, argument)](#logout-solutiontoload-method-argument)                                    | Logout the current user and close the solution, if the solution requires authentication and user is logged in.                               |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [removePermissionFromUser(a\_userUID, permission)](#removepermissionfromuser-a_useruid-permission)                    | Removes an permission from a user.                                                                                                           |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [setPassword(a\_userUID, password)](#setpassword-a_useruid-password)                                                  | Set a new password for the given userUID.                                                                                                    |
| void                                                                                         | [setSecuritySettings(dataset)](#setsecuritysettings-dataset)                                                          | Sets the security settings; the entries contained in the given dataset will override those contained in the current security settings.       |
| void                                                                                         | [setTenantValue(value)](#settenantvalue-value)                                                                        | 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.      |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean)               | [setUserUID(a\_userUID, newUserUID)](#setuseruid-a_useruid-newuseruid)                                                | Set a new userUID for the given userUID.                                                                                                     |

## Constants Detailed

### ACCESSIBLE

Constant representing the accessible flag for form security.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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).

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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).

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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.

**Type**\
[Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number)

**Sample**

```js
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 Detailed

### addPermissionToUser(a\_userUID, permission)

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

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the user UID to be added
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **permission** the permission to add to

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if added

**Sample**

```js
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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **authenticator\_solution** authenticator solution installed on the Servoy Server, null for servoy built-in authentication
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **method** authenticator method, null for servoy built-in authentication

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) authentication result from authenticator solution or boolean in case of servoy built-in authentication

**Sample**

```js
// 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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **authenticator\_solution** authenticator solution installed on the Servoy Server, null for servoy built-in authentication
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **method** authenticator method, null for servoy built-in authentication
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) authentication result from authenticator solution or boolean in case of servoy built-in authentication

**Sample**

```js
// 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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formName** form name

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if accessible

### canAccess(formName, elementName)

Returns whether element from form is accessible.

security.canAccess(formName,elementName)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formName** form name
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **elementName** element name from specified form

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if accessible

### canDelete(dataSource)

Returns a boolean value for security rights.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **dataSource** the datasource

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if allowed

**Sample**

```js
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](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **dataSource** the datasource

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if allowed

**Sample**

```js
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);
```

### canRead(dataSource)

Returns a boolean value for security rights.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **dataSource** the datasource

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if allowed

**Sample**

```js
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);
```

### canUpdate(dataSource)

Returns a boolean value for security rights.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **dataSource** the datasource

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if allowed

**Sample**

```js
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);
```

### canView(formName)

Returns whether form is viewable.

security.canView(formName)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formName** form name

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if viewable

### canView(formName, elementName)

Returns whether element from form is viewable.

security.canView(formName,elementName)

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formName** form name
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **elementName** element name from specified form

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if viewable

### changeUserName(a\_userUID, username)

Changes the username of the specified userUID.\
Note: this method can only be called by an admin user or a normal logged in user changing its own userName.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the userUID to work on
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** the new username

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if changed

**Sample**

```js
if(security.changeUserName(security.getUserUID('name1'), 'name2'))
{
	application.output('Username changed');
}
```

### checkPassword(a\_userUID, password)

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

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the userUID to check the password for
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** the new password

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if password oke

**Sample**

```js
if(security.checkPassword(security.getUserUID(), 'password1'))
{
	security.setPassword(security.getUserUID(), 'password2')
}
else
{
	application.output('wrong password')
}
```

### createUser(username, password)

Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist).\
Note: this method can only be called by an admin.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** the username
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** the user password

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) the userUID the created userUID, will be same if provided

**Sample**

```js
var removeUser = true;
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
	// Get all the permissions
	var set = security.getPermissions();
	for(var p = 1 ; p <= set.getMaxRowIndex() ; p++)
	{
		// output name of the permission
		application.output(set.getValue(p, 2));
		// add permission to user
		security.addPermissionToUser(uid, set.getValue(p,2));
	}
	// if not remove user, remove user from all the permissions
	if(!removeUser)
	{
		// get now all the permissions that that users has (all if above did go well)
		var set =security.getPermissions(uid);
		for(var p = 1;p<=set.getMaxRowIndex();p++)
		{
			// output name of the permission
			application.output(set.getValue(p, 2));
			// remove permission from user
			security.removePermissionFromUser(uid, set.getValue(p,2));
		}
	}
	else
	{
		// delete the user (the user will be removed from the permissions)
		security.deleteUser(uid);
	}
}
```

### createUser(username, password, userUID)

Creates a new user, returns new uid (or null when permission couldn't be created or user alreay exist).\
Note: this method can only be called by an admin.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** the username
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** the user password
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **userUID** the user UID to use

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) the userUID the created userUID, will be same if provided

**Sample**

```js
var removeUser = true;
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
	// Get all the permissions
	var set = security.getPermissions();
	for(var p = 1 ; p <= set.getMaxRowIndex() ; p++)
	{
		// output name of the permission
		application.output(set.getValue(p, 2));
		// add permission to user
		security.addPermissionToUser(uid, set.getValue(p,2));
	}
	// if not remove user, remove user from all the permissions
	if(!removeUser)
	{
		// get now all the permissions that that users has (all if above did go well)
		var set =security.getPermissions(uid);
		for(var p = 1;p<=set.getMaxRowIndex();p++)
		{
			// output name of the permission
			application.output(set.getValue(p, 2));
			// remove permission from user
			security.removePermissionFromUser(uid, set.getValue(p,2));
		}
	}
	else
	{
		// delete the user (the user will be removed from the permissions)
		security.deleteUser(uid);
	}
}
```

### deleteUser(userUID)

Deletes an user. returns true if no error was reported.\
Note: this method can only be called by an admin.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **userUID** The UID of the user to be deleted.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if the user is successfully deleted.

**Sample**

```js
var removeUser = true;
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
	// Get all the permissions
	var set = security.getPermissions();
	for(var p = 1 ; p <= set.getMaxRowIndex() ; p++)
	{
		// output name of the permission
		application.output(set.getValue(p, 2));
		// add permission to user
		security.addPermissionToUser(uid, set.getValue(p,2));
	}
	// if not remove user, remove user from all the permissions
	if(!removeUser)
	{
		// get now all the permissions that that users has (all if above did go well)
		var set =security.getPermissions(uid);
		for(var p = 1;p<=set.getMaxRowIndex();p++)
		{
			// output name of the permission
			application.output(set.getValue(p, 2));
			// remove permission from user
			security.removePermissionFromUser(uid, set.getValue(p,2));
		}
	}
	else
	{
		// delete the user (the user will be removed from the permissions)
		security.deleteUser(uid);
	}
}
```

### getClientID()

Returns the client ID.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the clientId as seen on the server admin page

**Sample**

```js
var clientId = security.getClientID()
```

### getElementUUIDs(formname)

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

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **formname** the formname to retieve the dataset for

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with element info

**Sample**

```js
var formElementsUUIDDataSet = security.getElementUUIDs('orders_form');
```

### getPermissions()

Get all the permissions of the solution (returns a dataset).\
first id column is deprecated!, use only the permission name column.

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with all the groups

**Sample**

```js
var removeUser = true;
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
	// Get all the permissions
	var set = security.getPermissions();
	for(var p = 1 ; p <= set.getMaxRowIndex() ; p++)
	{
		// output name of the permission
		application.output(set.getValue(p, 2));
		// add permission to user
		security.addPermissionToUser(uid, set.getValue(p,2));
	}
	// if not remove user, remove user from all the permissions
	if(!removeUser)
	{
		// get now all the permissions that that users has (all if above did go well)
		var set =security.getPermissions(uid);
		for(var p = 1;p<=set.getMaxRowIndex();p++)
		{
			// output name of the permission
			application.output(set.getValue(p, 2));
			// remove permission from user
			security.removePermissionFromUser(uid, set.getValue(p,2));
		}
	}
	else
	{
		// delete the user (the user will be removed from the permissions)
		security.deleteUser(uid);
	}
}
```

### getPermissions(userUID)

Get all the permissions for given user UID.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **userUID** to retrieve the user permissions

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with permissions names

**Sample**

```js
//get all the users in the security settings (Returns a JSDataset)
var dsUsers = security.getUsers()

//loop through each user to get their permissions
//The getValue call is (row,column) where column 1 == id and 2 == name
for(var i=1 ; i<=dsUsers.getMaxRowIndex() ; i++)
{
	//print to the output debugger tab: "user: " and the username
	application.output("user:" + dsUsers.getValue(i,2));

	//set p to the user permissions for the current user
	/** @type {JSDataSet} */
	var p = security.getPermissions(dsUsers.getValue(i,1));

	for(k=1;k<=p.getMaxRowIndex();k++)
	{
		//print to the output debugger tab: "permission" and the permission(s)
		//the user has
		application.output("permission: " + p.getValue(k,2));
	}
}
```

### getSystemUserName()

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

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the os user name

**Sample**

```js
//gets the current os username
var osUserName = security.getSystemUserName();
```

### getTenantValue()

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. This results in adding a table filter for that table based on that column and the this value.

A client with tenant value will only receive databroadcasts from other clients that have no or a common tenant value set Be sure to not access or depend on records having different tenant values, as no databroadcasts will be received for those

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) An array of tenant values for this client.

### getUserName()

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

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the user name

**Sample**

```js
//gets the current loggedIn username
var userName = security.getUserName();
```

### getUserName(userUID)

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

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **userUID** the user UID used to retrieve the name

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the user name

**Sample**

```js
//gets the current loggedIn username
var userName = security.getUserName();
```

### getUserPermissions()

Get all the permissions of the current user.

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with permissions

**Sample**

```js
//set p to the user permissions for the current user
	/** @type {JSDataSet} */
	var p = security.getUserPermissions();

	for(k=1;k<=p.getMaxRowIndex();k++)
	{
		//print to the output debugger tab: "permission" and the permissons(s)
		//the user has
		application.output("permission: " + p.getValue(k,2));
	}
```

### getUserUID()

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

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the userUID

**Sample**

```js
//gets the current loggedIn username
var userName = security.getUserName();
//gets the uid of the given username
var userUID = security.getUserUID(userName);
//is the same as above
//var my_userUID = security.getUserUID();
```

### getUserUID(username)

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

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** the username to find the userUID for

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) the userUID

**Sample**

```js
//gets the current loggedIn username
var userName = security.getUserName();
//gets the uid of the given username
var userUID = security.getUserUID(userName);
//is the same as above
//var my_userUID = security.getUserUID();
```

### getUsers()

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

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with all the users

### getUsers(groupName)

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

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **groupName** the group to filter on

**Returns:** [JSDataSet](https://docs.servoy.com/reference/servoycore/dev-api/database-manager/jsdataset) dataset with all the users

### hasPermission(permisson)

Check if the current user has the given permission

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **permisson** name of the permission

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if it has the given permission

**Sample**

```js
//check whatever user is part of the Administrators permission
if(security.hasPermission('Administrators'))
{
	// do administration stuff
}
```

### hasPermission(permission, userUID)

Check if the given user has the given permission

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **permission** name of the permission to check
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **userUID** UID of the user to check

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if it has that given permission

**Sample**

```js
//check whatever user is part of the Administrators permission
if(security.hasPermission('Administrators', security.getUserUID('admin')))
{
	// do administration stuff
}
```

### login(username, a\_userUID, permissions)

Login to be able to leave the solution loginForm.

Example: Permissions names may be received from LDAP (Lightweight Directory Access Protocol) - a standard protocol used in web browsers and email applications to enable lookup queries that access a directory listing.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **username** the username, like 'JamesWebb'
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the user UID to process login for
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **permissions** the permissions array

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if loggedin

**Sample**

```js
var permissions = ['Administrators']; //normally these groups are for example received from LDAP
var user_uid = scopes.globals.email; //also this uid might be received from external authentication method
var ok =  security.login(scopes.globals.username, user_uid , permissions)
if (!ok)
{
	plugins.dialogs.showErrorDialog('Login failure',  'Already logged in? or no user_uid/permissions specified?', 'OK')
}
```

### logout()

Logout the current user and close the solution, if the solution requires authentication and user is logged in.\
You can redirect to another solution if needed; if you want to go to a different url, you need to call application.showURL(url) before calling security.logout().\
An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().

**Returns:** void

**Sample**

```js
//Set the url to go to after logout.
//application.showURL('http://www.servoy.com', '_self');
security.logout();
//security.logout('solution_name');//log out and close current solution and open solution 'solution_name'
//security.logout('solution_name','global_method_name');//log out, close current solution, open solution 'solution_name' and call global method 'global_method_name' of the newly opened solution
//security.logout('solution_name','global_method_name','my_string_argument');//log out, close current solution, open solution 'solution_name', call global method 'global_method_name' with argument 'my_argument'
//security.logout('solution_name','global_second_method_name',2);
//security.logout('solution_name', {a: 'my_string_argument', p1: 'param1', p2: 'param2'});//log out, close current solution, open solution 'solution_name', call (login) solution's onOpen with argument 'my_argument' and queryParams p1,p2
//Note: specifying a solution will not work in the Developer due to debugger dependencies
//specified solution should be of compatible type with client (normal type or client specific type )
```

### logout(solutionToLoad)

Logout the current user and close the solution, if the solution requires authentication and user is logged in.\
You can redirect to another solution if needed; if you want to go to a different url, you need to call application.showURL(url) before calling security.logout().\
An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **solutionToLoad** the solution to load after logout

**Returns:** void

**Sample**

```js
//Set the url to go to after logout.
//application.showURL('http://www.servoy.com', '_self');
security.logout();
//security.logout('solution_name');//log out and close current solution and open solution 'solution_name'
//security.logout('solution_name','global_method_name');//log out, close current solution, open solution 'solution_name' and call global method 'global_method_name' of the newly opened solution
//security.logout('solution_name','global_method_name','my_string_argument');//log out, close current solution, open solution 'solution_name', call global method 'global_method_name' with argument 'my_argument'
//security.logout('solution_name','global_second_method_name',2);
//security.logout('solution_name', {a: 'my_string_argument', p1: 'param1', p2: 'param2'});//log out, close current solution, open solution 'solution_name', call (login) solution's onOpen with argument 'my_argument' and queryParams p1,p2
//Note: specifying a solution will not work in the Developer due to debugger dependencies
//specified solution should be of compatible type with client (normal type or client specific type )
```

### logout(solutionToLoad, argument)

Logout the current user and close the solution, if the solution requires authentication and user is logged in.\
You can redirect to another solution if needed; if you want to go to a different url, you need to call application.showURL(url) before calling security.logout().\
An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **solutionToLoad** the solution to load after logout
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **argument** the argument to pass to the (login) solution onOpen

**Returns:** void

**Sample**

```js
//Set the url to go to after logout.
//application.showURL('http://www.servoy.com', '_self');
security.logout();
//security.logout('solution_name');//log out and close current solution and open solution 'solution_name'
//security.logout('solution_name','global_method_name');//log out, close current solution, open solution 'solution_name' and call global method 'global_method_name' of the newly opened solution
//security.logout('solution_name','global_method_name','my_string_argument');//log out, close current solution, open solution 'solution_name', call global method 'global_method_name' with argument 'my_argument'
//security.logout('solution_name','global_second_method_name',2);
//security.logout('solution_name', {a: 'my_string_argument', p1: 'param1', p2: 'param2'});//log out, close current solution, open solution 'solution_name', call (login) solution's onOpen with argument 'my_argument' and queryParams p1,p2
//Note: specifying a solution will not work in the Developer due to debugger dependencies
//specified solution should be of compatible type with client (normal type or client specific type )
```

### logout(solutionToLoad, method)

Logout the current user and close the solution, if the solution requires authentication and user is logged in.\
You can redirect to another solution if needed; if you want to go to a different url, you need to call application.showURL(url) before calling security.logout().\
An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **solutionToLoad** the solution to load after logout
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **method** the method to run in the solution to load

**Returns:** void

**Sample**

```js
//Set the url to go to after logout.
//application.showURL('http://www.servoy.com', '_self');
security.logout();
//security.logout('solution_name');//log out and close current solution and open solution 'solution_name'
//security.logout('solution_name','global_method_name');//log out, close current solution, open solution 'solution_name' and call global method 'global_method_name' of the newly opened solution
//security.logout('solution_name','global_method_name','my_string_argument');//log out, close current solution, open solution 'solution_name', call global method 'global_method_name' with argument 'my_argument'
//security.logout('solution_name','global_second_method_name',2);
//security.logout('solution_name', {a: 'my_string_argument', p1: 'param1', p2: 'param2'});//log out, close current solution, open solution 'solution_name', call (login) solution's onOpen with argument 'my_argument' and queryParams p1,p2
//Note: specifying a solution will not work in the Developer due to debugger dependencies
//specified solution should be of compatible type with client (normal type or client specific type )
```

### logout(solutionToLoad, method, argument)

Logout the current user and close the solution, if the solution requires authentication and user is logged in.\
You can redirect to another solution if needed; if you want to go to a different url, you need to call application.showURL(url) before calling security.logout().\
An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **solutionToLoad** the solution to load after logout
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **method** the method to run in the solution to load
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **argument** the argument to pass to the method to run

**Returns:** void

**Sample**

```js
//Set the url to go to after logout.
//application.showURL('http://www.servoy.com', '_self');
security.logout();
//security.logout('solution_name');//log out and close current solution and open solution 'solution_name'
//security.logout('solution_name','global_method_name');//log out, close current solution, open solution 'solution_name' and call global method 'global_method_name' of the newly opened solution
//security.logout('solution_name','global_method_name','my_string_argument');//log out, close current solution, open solution 'solution_name', call global method 'global_method_name' with argument 'my_argument'
//security.logout('solution_name','global_second_method_name',2);
//security.logout('solution_name', {a: 'my_string_argument', p1: 'param1', p2: 'param2'});//log out, close current solution, open solution 'solution_name', call (login) solution's onOpen with argument 'my_argument' and queryParams p1,p2
//Note: specifying a solution will not work in the Developer due to debugger dependencies
//specified solution should be of compatible type with client (normal type or client specific type )
```

### removePermissionFromUser(a\_userUID, permission)

Removes an permission from a user.\
Note: this method can only be called by an admin.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the user UID to be removed
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **permission** the permission to remove from

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if removed

**Sample**

```js
var removeUser = true;
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
	// Get all the permissions
	var set = security.getPermissions();
	for(var p = 1 ; p <= set.getMaxRowIndex() ; p++)
	{
		// output name of the permission
		application.output(set.getValue(p, 2));
		// add permission to user
		security.addPermissionToUser(uid, set.getValue(p,2));
	}
	// if not remove user, remove user from all the permissions
	if(!removeUser)
	{
		// get now all the permissions that that users has (all if above did go well)
		var set =security.getPermissions(uid);
		for(var p = 1;p<=set.getMaxRowIndex();p++)
		{
			// output name of the permission
			application.output(set.getValue(p, 2));
			// remove permission from user
			security.removePermissionFromUser(uid, set.getValue(p,2));
		}
	}
	else
	{
		// delete the user (the user will be removed from the permissions)
		security.deleteUser(uid);
	}
}
```

### setPassword(a\_userUID, password)

Set a new password for the given userUID.\
Note: this method can only be called by an admin user or a normal logged in user changing its own password.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the userUID to set the new password for
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **password** the new password

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if changed

**Sample**

```js
if(security.checkPassword(security.getUserUID(), 'password1'))
{
	security.setPassword(security.getUserUID(), 'password2')
}
else
{
	application.output('wrong password')
}
```

### setSecuritySettings(dataset)

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

NOTE: The security.getElementUUIDs and security.setSecuritySettings functions can be used to define custom security that overrides Servoy security.\
For additional information see the function security.getElementUUIDs.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **dataset** the dataset with security settings

**Returns:** void

**Sample**

```js
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
```

### setTenantValue(value)

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. This results in adding a table filter for that table based on that column and the given value, using JSTableFilter.dataBroadcast(true).

When creating a new record, this value will be auto filled in for all the columns that are marked as a tenant column. If you give an array of values then the first array value is used for this.

When a tenant value is set the client will only receive databroadcasts from other clients that have no or a common tenant value set. If the tenant value is a list then the broadcast will be filtered only if there is single element match between the 2 list, so \['a','b'] will match \['a','c'] but not \['c','d'], the actual data of a recod is ignored for this. Be sure to not access or depend on records having different tenant values, as no databroadcasts will be received for those

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** a single tenant value or an array of tenant values to filter tables having a column flagged as Tenant column by.

**Returns:** void

### setUserUID(a\_userUID, newUserUID)

Set a new userUID for the given userUID.\
Note: this method can only be called by an admin.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **a\_userUID** the userUID to set the new user UID for
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **newUserUID** the new user UID

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) true if changed

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/security.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
