var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
DELETE
Constant representing the delete flag for table security.
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
INSERT
Constant representing the insert flag for table security.
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
READ
Constant representing the read flag for table security.
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
TRACKING
Constant representing the tracking flag for table security (tracks sql insert/update/delete).
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
TRACKING_VIEWS
Constant representing the tracking flag for table security (tracks sql select).
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
UPDATE
Constant representing the update flag for table security.
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
VIEWABLE
Constant representing the viewable flag for form security.
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.setSecuritySettings(dataset);//to be called in solution startup method
Methods Details
addPermissinToUser(a_userUID, permission)
Gives a user a permission Note: this method can only be called by an admin.
ParametersObject a_userUID the user UID to be added
Object permission the permission to add to
var userUID =security.getUserUID();security.addPermissinToUser(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.
ParametersString 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
ReturnsObject authentication result from authenticator solution or boolean in case of servoy built-in authentication
Sample
// create the credentials object as expected by the authenticator solutionvar 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 managementok =security.authenticate(null,null, [scopes.globals.userName,scopes.globals.passWord])
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.
ParametersString 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]
ReturnsObject authentication result from authenticator solution or boolean in case of servoy built-in authentication
Sample
// create the credentials object as expected by the authenticator solutionvar 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 managementok =security.authenticate(null,null, [scopes.globals.userName,scopes.globals.passWord])
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.
ParametersObject a_userUID the userUID to work on
String username the new username
Creates a new user, returns new uid (or null when group couldn't be created or user alreay exist). Note: this method can only be called by an admin.
ParametersString username the username
String password the user password
ReturnsObject the userUID the created userUID, will be same if provided
Sample
var removeUser =true;//create a uservar uid =security.createUser('myusername','mypassword');if (uid) //test if user was created{// Get all the groupsvar set =security.getGroups();for(var p =1 ; p <=set.getMaxRowIndex() ; p++) {// output name of the groupapplication.output(set.getValue(p,2));// add user to groupsecurity.addUserToGroup(uid,set.getValue(p,2)); }// if not remove user, remove user from all the groupsif(!removeUser) {// get now all the groups that that users has (all if above did go well)var set =security.getUserGroups(uid);for(var p =1;p<=set.getMaxRowIndex();p++) {// output name of the groupapplication.output(set.getValue(p,2));// remove the user from the groupsecurity.removeUserFromGroup(uid,set.getValue(p,2)); } }else {// delete the user (the user will be removed from the groups)security.deleteUser(uid); }}
createUser(username, password, userUID)
Creates a new user, returns new uid (or null when group couldn't be created or user alreay exist). Note: this method can only be called by an admin.
ParametersString username the username
String password the user password
Object userUID the user UID to use
ReturnsObject the userUID the created userUID, will be same if provided
Sample
var removeUser =true;//create a uservar uid =security.createUser('myusername','mypassword');if (uid) //test if user was created{// Get all the groupsvar set =security.getGroups();for(var p =1 ; p <=set.getMaxRowIndex() ; p++) {// output name of the groupapplication.output(set.getValue(p,2));// add user to groupsecurity.addUserToGroup(uid,set.getValue(p,2)); }// if not remove user, remove user from all the groupsif(!removeUser) {// get now all the groups that that users has (all if above did go well)var set =security.getUserGroups(uid);for(var p =1;p<=set.getMaxRowIndex();p++) {// output name of the groupapplication.output(set.getValue(p,2));// remove the user from the groupsecurity.removeUserFromGroup(uid,set.getValue(p,2)); } }else {// delete the user (the user will be removed from the groups)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.
ParametersObject userUID The UID of the user to be deleted.
ReturnsBoolean true if the user is successfully deleted.
Sample
var removeUser =true;//create a uservar uid =security.createUser('myusername','mypassword');if (uid) //test if user was created{// Get all the groupsvar set =security.getGroups();for(var p =1 ; p <=set.getMaxRowIndex() ; p++) {// output name of the groupapplication.output(set.getValue(p,2));// add user to groupsecurity.addUserToGroup(uid,set.getValue(p,2)); }// if not remove user, remove user from all the groupsif(!removeUser) {// get now all the groups that that users has (all if above did go well)var set =security.getUserGroups(uid);for(var p =1;p<=set.getMaxRowIndex();p++) {// output name of the groupapplication.output(set.getValue(p,2));// remove the user from the groupsecurity.removeUserFromGroup(uid,set.getValue(p,2)); } }else {// delete the user (the user will be removed from the groups)security.deleteUser(uid); }}
getClientID()
Returns the client ID.
ReturnsString the clientId as seen on the server admin page
Sample
var clientId =security.getClientID()
getElementUUIDs(formname)
Returns the form elements UUID's as dataset, the one with no name is the form itself.
ParametersString formname the formname to retieve the dataset for
var removeUser =true;//create a uservar uid =security.createUser('myusername','mypassword');if (uid) //test if user was created{// Get all the groupsvar set =security.getGroups();for(var p =1 ; p <=set.getMaxRowIndex() ; p++) {// output name of the groupapplication.output(set.getValue(p,2));// add user to groupsecurity.addUserToGroup(uid,set.getValue(p,2)); }// if not remove user, remove user from all the groupsif(!removeUser) {// get now all the groups that that users has (all if above did go well)var set =security.getUserGroups(uid);for(var p =1;p<=set.getMaxRowIndex();p++) {// output name of the groupapplication.output(set.getValue(p,2));// remove the user from the groupsecurity.removeUserFromGroup(uid,set.getValue(p,2)); } }else {// delete the user (the user will be removed from the groups)security.deleteUser(uid); }}
getPermissions(userUID)
Get all the permissions for given user UID.
ParametersObject userUID to retrieve the user groups
//get all the users in the security settings (Returns a JSDataset)var dsUsers =security.getUsers()//loop through each user to get their group//The getValue call is (row,column) where column 1 == id and 2 == namefor(var i=1 ; i<=dsUsers.getMaxRowIndex() ; i++){//print to the output debugger tab: "user: " and the usernameapplication.output("user:"+dsUsers.getValue(i,2));//set p to the user group 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 hasapplication.output("permission: "+p.getValue(k,2)); }}
getSystemUserName()
Retrieves the username of the currently logged in user on operating system level.
//gets the current os usernamevar 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
ReturnsArray An array of tenant values for this client.
Sample
getUserName()
Get the current user name (null if not logged in), finds the user name for given user UID if passed as parameter.
//set p to the user group 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 hasapplication.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.
//gets the current loggedIn usernamevar userName =security.getUserName();//gets the uid of the given usernamevar 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.
ParametersString username the username to find the userUID for
//gets the current loggedIn usernamevar userName =security.getUserName();//gets the uid of the given usernamevar 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).
ReturnsBoolean true if it has the given permission
Sample
//check whatever user is part of the Administrators permissionif(security.hasPermission('Administrators')){// do administration stuff}
hasPermission(permission, userUID)
Check if the given user has the given permission
ParametersString permission name of the permission to check
Object userUID UID of the user to check
ReturnsBoolean true if it has that given permission
Sample
//check whatever user is part of the Administrators permissionif(security.hasPermission('Administrators',security.getUserUID('admin'))){// do administration stuff}
login(username, a_userUID, groups)
Login to be able to leave the solution loginForm.
Example: Group 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.
ParametersString username the username, like 'JamesWebb'
Object a_userUID the user UID to process login for
Array groups the groups array
var groups = ['Administrators']; //normally these groups are for example received from LDAPvar user_uid =scopes.globals.email; //also this uid might be received from external authentication methodvar ok =security.login(scopes.globals.username, user_uid , groups)if (!ok){plugins.dialogs.showErrorDialog('Login failure','Already logged in? or no user_uid/groups 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() (this is only applicable for Web Client). An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().
Returns
void
Sample
//Set the url to go to after logout.//application.showURL('http://www.servoy.com', '_self'); //Web Client onlysecurity.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(Smart client only/Web client only) 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() (this is only applicable for Web Client). An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().
ParametersString solutionToLoad the solution to load after logout
Returns
void
Sample
//Set the url to go to after logout.//application.showURL('http://www.servoy.com', '_self'); //Web Client onlysecurity.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(Smart client only/Web client only) 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() (this is only applicable for Web Client). An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().
ParametersString solutionToLoad the solution to load after logout
Object argument the argument to pass to the (login) solution onOpen
Returns
void
Sample
//Set the url to go to after logout.//application.showURL('http://www.servoy.com', '_self'); //Web Client onlysecurity.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(Smart client only/Web client only) 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() (this is only applicable for Web Client). An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().
ParametersString solutionToLoad the solution to load after logout
String method the method to run in the solution to load
Returns
void
Sample
//Set the url to go to after logout.//application.showURL('http://www.servoy.com', '_self'); //Web Client onlysecurity.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(Smart client only/Web client only) 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() (this is only applicable for Web Client). An alternative option to close a solution and to open another solution, while keeping the user logged in, is application.closeSolution().
ParametersString solutionToLoad the solution to load after logout
String method the method to run in the solution to load
Object argument the argument to pass to the method to run
Returns
void
Sample
//Set the url to go to after logout.//application.showURL('http://www.servoy.com', '_self'); //Web Client onlysecurity.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(Smart client only/Web client only) type )
removePermissionFromUser(a_userUID, permission)
Removes an permission from a user. Note: this method can only be called by an admin.
ParametersObject a_userUID the user UID to be removed
Object permission the permission to remove from
var removeUser =true;//create a uservar uid =security.createUser('myusername','mypassword');if (uid) //test if user was created{// Get all the groupsvar set =security.getGroups();for(var p =1 ; p <=set.getMaxRowIndex() ; p++) {// output name of the groupapplication.output(set.getValue(p,2));// add user to groupsecurity.addUserToGroup(uid,set.getValue(p,2)); }// if not remove user, remove user from all the groupsif(!removeUser) {// get now all the groups that that users has (all if above did go well)var set =security.getUserGroups(uid);for(var p =1;p<=set.getMaxRowIndex();p++) {// output name of the groupapplication.output(set.getValue(p,2));// remove the user from the groupsecurity.removeUserFromGroup(uid,set.getValue(p,2)); } }else {// delete the user (the user will be removed from the groups)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.
ParametersObject a_userUID the userUID to set the new password for
String password the new password
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.
ParametersObject dataset the dataset with security settings
Returns
void
Sample
var colNames =newArray();colNames[0] ='uuid';colNames[1] ='flags';var dataset =databaseManager.createEmptyDataSet(0,colNames);var row =newArray();row[0] ='413a4d69-becb-4ae4-8fdd-980755d6a7fb';//normally retreived via security.getElementUUIDs(...)row[1] =JSSecurity.VIEWABLE|JSSecurity.ACCESSIBLE; // use bitwise 'or' for bothdataset.addRow(row);//setting element securityrow =newArray();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 securitysecurity.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 this value.
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 Be sure to not access or depend on records having different tenant values, as no databroadcasts will be received for those
ParametersObject value a single tenant value or an array of tenant values to filter tables having a column flagged as Tenant column by.
Returns
void
Sample
setUserUID(a_userUID, newUserUID)
Set a new userUID for the given userUID. Note: this method can only be called by an admin.
ParametersObject a_userUID the userUID to set the new user UID for
String newUserUID the new user UID
var deleteGroup = true;
//ceate a group
var groupName = security.createGroup('myGroup');
if (groupName)
{
//create a user
var uid = security.createUser('myusername', 'mypassword');
if (uid) //test if user was created
{
//set a newUID for the user
var isChanged = security.setUserUID(uid,'myUserUID')
// add user to group
security.addUserToGroup(uid, groupName);
// if not delete group, do delete group
if (deleteGroup)
{
security.deleteGroup(groupName);
}
}
}