Class Authentication
The intended usage is that a server authentication system would require the user to log in,
then provide data about the currently logged in user via setCurrentUser()
and setRoles()
. This data is then available in the
Rule Scope
so that components can use it to enable or disable or
hide themselves, via properties such as FormItem.readOnlyWhen
.
The format for user records is not explicitly defined or restricted by the Authentication
subsystem but we recommend using the format described by getUserSchema()
.
Having a standardized user record allows application designers to rely on a
well-known set of field names at design time, and then at deployment time when a
particular authentication system is chosen, the deployer can simply fill in the
standardized user record from the data that the chosen authentication system returns.
This also allows authentication systems to be swapped out in the future without
the need to change application code.
The DataSource returned by getUserSchema()
is used solely
for visual
tools to help with application authoring.
It is not intended to be used directly to store and retrieve user data, and while we
recommend this format it is not a requirement that user records conform to it.
There are no security implications to calling setRoles()
or
other APIs on the Authentication
class. The provided data affects only
client-side components. All actual security enforcement must be done server-side -
see the QuickStart Guide, especially the sections on Declarative Security,
to understand how role-based authorization can be used on the server.
Rule Context
The default ruleContext obtained from Canvas.getRuleContext()
includes a property
for the current authentication information (based on getUserSchema()
):
- auth
- currentUser
- firstName
- lastName
- ... other fields in schema
- roles
- isSuperUser
{ auth : { currentUser : { userId: "lisa", firstName: "Lisa", lastName: "Admin", roles: "admin", ..other properties.. }, roles : ['admin'], isSuperUser : false }, ..other properties.. }Since the
currentUser
information is based on getUserSchema()
any changes to the schema implemented as an override will be reflected in the rule context.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
Returns the full set of available user roles specified bysetAvailableRoles()
.static Record
Returns the current user specified bysetCurrentUser()
.static String
Convenience method to return the"userId"
attribute of thecurrent user
if there is one.static String[]
getRoles()
Returns the current set of user roles.static DataSource
Returns a DataSource describing the standard schema for user data.static Boolean
Is the current user assigned to the specified role?static void
isSuperUser
(Boolean isSuperUser) Has the current user been marked as a super-user viasetSuperUser()
?static void
setAvailableRoles
(String[] roles) Specify the full set of available user roles.static void
setCurrentUser
(Record user) Set up the current user.static void
Set the user roles for the current user.static void
setSuperUser
(Boolean isSuperUser) Mark the current user as a super-user.
-
Constructor Details
-
Authentication
public Authentication()
-
-
Method Details
-
getAvailableRoles
Returns the full set of available user roles specified bysetAvailableRoles()
.- Returns:
- full set of possible user roles.
-
getCurrentUser
Returns the current user specified bysetCurrentUser()
.This method returns the user record currently available in the
Canvas.ruleScope
as "auth.currentUser".- Returns:
- Record with attributes detailing the current user
-
getCurrentUserId
Convenience method to return the"userId"
attribute of thecurrent user
if there is one.- Returns:
- userId attribute of the
current user record
if there is one.
-
getRoles
Returns the current set of user roles. Forsuper users
this will be the intersection of any roles specified bysetRoles()
and the full set ofavailable roles
- otherwise it will be the set of roles specified bysetRoles()
.Current set of user roles are available in the
Canvas.ruleScope
as a top-level property "userRoles", so that it can be used in criteria such asCanvas.visibleWhen
orFormItem.readOnlyWhen
.- Returns:
- set of roles which apply to the current user
-
getUserSchema
Returns a DataSource describing the standard schema for user data.The schema contains the following fields:
Field Name Type "userId" "text" "email" "text" "firstName" "text" "lastName" "text" "title" "text" "phone" "phoneNumber" "superUser" "boolean" - Returns:
- user schema dataSource
-
hasRole
Is the current user assigned to the specified role?- Parameters:
role
- role to check in current roles- Returns:
- true if the user has the role in its
getRoles()
list; false otherwise - See Also:
-
isSuperUser
Has the current user been marked as a super-user viasetSuperUser()
?- Parameters:
isSuperUser
- New super user status
-
setAvailableRoles
Specify the full set of available user roles.Note that if the current user has been marked as a
superUser
,getRoles()
will return the full set of available roles.- Parameters:
roles
- full set of possible user roles.
-
setCurrentUser
Set up the current user. This method makes the user record available in theCanvas.ruleScope
as "auth.currentUser".- Parameters:
user
- Record with attributes detailing the current user
-
setRoles
Set the user roles for the current user. Roles may be retrieved viagetRoles()
.Calling setRoles() makes the specified set of user roles available in the
Canvas.ruleScope
as a top-level property "userRoles", so that it can be used in criteria such asCanvas.visibleWhen
orFormItem.readOnlyWhen
.Note that if this current user has been
marked as a super-user
,getRoles()
will return the full set of available roles rather than the set of roles specified here.- Parameters:
roles
- set of roles which apply to the current user
-
setSuperUser
Mark the current user as a super-user. This causesgetRoles()
to return the full set ofavailable roles
if specified- Parameters:
isSuperUser
- New super user status
-