API Documentation

Classes

Permission

Represents a security permission in the system. Mapped internally to a Servoy security group which must be defined.

Role

Security role which can have user members and can be granted permissions.

Session

Security application session created by a User which starts when the user logs in and ends when the user logs out.

Tenant

Tenant account which is used to segregate all data. Users and Roles belong to a Tenant.

User

Application user account associated with a Tenant. Security Permissions are granted to users through their Role membership.

Functions

changeExternalDBTransactionSupportFlag(mustSupportExternalTransactions)

Use this method to change the behavior of the svySecurity module with respect to DB transactions.

If the flag is set to false (default) then when saving or deleting security-related records if an external DB transaction is detected the operation will fail. If the flag is set to true then when saving or deleting security-related records the module will start/commit a DB transaction only if an external DB transaction is not detected. On exceptions any DB transaction will be rolled back regardless if it is started internally or externally (exceptions will be propagated to the external transaction so callers will be able to react on them accordingly)

cloneTenant(tenantToClone, name, [makeSlave])Tenant

Creates and returns a new tenant with the specified name as a clone of the given tenant. The names of tenants must be unique in the system. The cloned tenant has the same roles and role permissions as the original. When makeSlave is true, the newly created clone will be a slave of the tenant to clone, inheriting all role / permission changes made to the master. WARNING: Cannot call this function when logged in as an user.

consumeAccessToken(token)User

Consumes a secure-access token and returns the user associated with the token if a valid match was found. Tokens may be used only once to identify a user. Subsequent calls to consume the same token will fail. Secure-access tokens are created with generateAccessToken

createTenant(name)Tenant

Creates and returns a new tenant with the specified name. The names of tenants must be unique in the system.

deleteTenant(tenant)Boolean

Immediately and permanently deletes the specified tenant and all records associated with it, including all users and roles. Tenant will not be deleted if it has users with active sessions. If the deleted tenant is a Master tenant and is a slave of another master tenant, this operation will replace the master tenant of it's direct slaves with the master of the tenant that is deleted; If the delated tenant is a Master tenant and has no Master tenant, this operation will remove the master from all it's direct slaves.

getActiveSessions()[ 'Array' ].<Session>

Gets all active sessions for the application.

getPermission(name)Permission

Gets a permission by its unique permission name.

getPermissions()[ 'Array' ].<Permission>

Gets all permissions available in this application.

getRole(roleName, [tenantName])Role

Gets a role by the specified role name and tenant name. If tenant name is not specified will use the tenant of the user currently logged in the application, if available.

getSession()Session

Gets the current user session or null if no session initialized (no user is currently logged in).

getSessionCount()Number

Gets the number of all unique sessions which have ever been initialized in the application. This includes both active sessions (for users currently logged in the application) and inactive sessions (sessions from the past which have already been closed).

getTenant([name])Tenant

Gets a tenant by its unique tenant name. If tenant name is not specified then will return the tenant of the currently logged in user. If tenant name is not specified and no user is currently logged in then will return null.

getTenants()[ 'Array' ].<Tenant>

Gets all tenants in the system.

getUser([userName], [tenantName])User

Gets a user by the specified username and tenant name. If username is not specified will return the user currently logged in the application, if available.

getUsers()[ 'Array' ].<User>

Gets all users in the system.

getVersion()String

Gets the version of this module

login(user, [userUid], [permissionsToApply])Boolean

Logs in the specified user and initializes a new Session for it. The login request will not be successful if the user account or the parent tenant account is locked and the lock has not expired yet. The login request will not be successful also if no permissions have been granted to the specified user. This method internally calls the standard Servoy security.login().

logout()

Logs the current user out of the application and closes the associated Session. This method internally calls security.logout() to end the Servoy client session.

syncPermissions([forcePermissionRemoval])

Utility to sync permission records to the internal, design-time Servoy Security Groups. This should be called on solution import or on startup This action will create new permission records.

NOTE: This action will not delete permissions which have been removed from internal security. Design-time groups should never be renamed. They will be seen only as an ADD and will lose their tie to roles.

Permission

Represents a security permission in the system. Mapped internally to a Servoy security group which must be defined.


permission.addRole(role) ⇒ Permission

Grants this permission to the specified role. The permission will be granted to all users that are members of the specified role. If the tenant of this permission is a master tenant, the role will also be added to the same permission for all the slaves of this permission tenant. You cannot grant permission to role of a master tenant when logged in as an user. You cannot grant permission to role of a slave tenant at anytime.

Returns: Permission - This permission for call-chaining support. Throws an exception when permission cannot be granted.

Param
Type
Description

role

The role object to which the permission should be granted.

permission.getDisplayName() ⇒ String

Gets the display name of this permission. The display name can be set using setDisplayName.

Returns: String - The display name of the permission. Can be null.

permission.getName() ⇒ String

Gets the name of this permission. The permission name is unique in the system and matches a Servoy security group name.

Returns: String - The name of the permission.

permission.getRoles() ⇒ [ 'Array' ].<Role>

Gets all the roles to which this permission is granted.

Returns: [ 'Array' ].<Role> - An array with all roles to which this permission is granted or an empty array if the permission has not been granted to any role.

permission.getUsers() ⇒ [ 'Array' ].<User>

Gets all users whom this permission is granted to via the users' role membership.

Returns: [ 'Array' ].<User> - An array with all users whom this permission is granted to or an empty array if no user has this permission.

permission.hasRole(role) ⇒ Boolean

Checks if this permission is granted to the specified role.

Returns: Boolean - True if this permission is granted to the specified role.

Param
Type
Description

role

The role object or the name of the role to check.

permission.removeRole(role) ⇒ Permission

Removes this permission from the specified role. The permission will no longer be granted to all users that are members of the specified role. If the tenant of this permission is a master tenant, the role will also be removed from the same permission for all the slaves of this permission tenant. You cannot remove permission from role of a master tenant when logged in as an user. You cannot remove permission from role of a slave tenant at anytime.

Returns: Permission - This permission for call-chaining support. Throws an exception when permission cannot be removed.

Param
Type
Description

role

The role object or the name of the role to remove.

permission.setDisplayName([displayName]) ⇒ Permission

Sets the display name of this permission.

Returns: Permission - This permission for call-chaining support.

Param
Type
Description

[displayName]

String

The display name to use.

new Permission(record)

Permission objects cannot be created through the API. They are created automatically when the scope is loaded. Use getPermission or getPermissions to get permission objects. Creating permission objects with the new operator is reserved for internal use only.

Param
Type

record

[ 'JSRecord' ].<permissions>


Role

Security role which can have user members and can be granted permissions.

role.addPermission(permission) ⇒ Role

Grants the specified permission to this role. Any users that are members of this role will be granted the permission. If the tenant of this role is a master tenant, the permission will also be added to the same role in all slaves of this role tenant. You cannot grant permission to role of a master tenant when logged in as an user. You cannot grant permission to role of a slave tenant at anytime.

Returns: Role - This role for call-chaining support.

Param
Type
Description

permission

The permission object or name of permission to add.\ Throws an exception when permission cannot be grant.

role.addUser(user) ⇒ Role

Adds the specified user as member of this role. All permissions granted to this role will be granted to the user.

Returns: Role - This role for call-chaining support.

Param
Type
Description

user

The user object or username of user to add. The user must be associated with the tenant of this role.

role.getDisplayName() ⇒ String

Gets the display name of this role.

Returns: String - The display name of this role. Can be null.

role.getName() ⇒ String

Gets the name of this role. The role name is unique to the associated tenant.

Returns: String - The role name.

role.getPermissions() ⇒ [ 'Array' ].<Permission>

Gets all the permissions granted to this role.

Returns: [ 'Array' ].<Permission> - An array with all permissions granted to this role or an empty array if no permissions are granted.

role.getTenant() ⇒ Tenant

Gets the tenant which this role belongs to.

Returns: Tenant - The tenant which this role belongs to.

role.getUsers() ⇒ [ 'Array' ].<User>

Gets all the users who are members of this role.

Returns: