public interface DeclarativeSecurity
See the QuickStart Guide for more in depth documentation on how declarative security works and how to use it in your application.
See Standalone DataSource Usage
for
information on how to use
declarative security in a standalone application.
NOTE: Declarative security only works for DataSource operations (including DataSource DMI operations). If you want to limit access to an ordinary RPC-DMI method - so it can only be called by authenticated users, only users with a certain role, etc - you have two choices:
HttpServletRequest
; that will
cause Smart GWT to pass the current servlet request into your method, and you can directly
call the getRemoteUser()
and isUserInRole()
methods to implement
your own securitycustom
operation
Requests that fail to pass Declarative Security checks will return a response with status of
STATUS_AUTHORIZATION_FAILURE
.
To use client-side declarative security simulation, just create a
clientOnly dataSource
that specifies
some of the declarative
security rules linked to below. All of these rules, at a minimum, require authentication,
so you will also have to provide a dummy authenticated user to the simulator by use of the
client side Authentication class
Record currentUser = new Record(); currentUser.setAttribute("userId", "john_doe"); Authentication.setCurrentUser(currentUser);Many declarative security rules also require a role, such as "payroll" or "manager", so you may also need to provide roles to the client-side simulator
Authentication.setRoles(new String[] {"order_handling","supervisor"});The example linked below shows how to use the client-side declarative security simulator to implement and test role-based security rules on both operations and individual fields.
StandaloneDataSourceUsage
,
DataSource.requiresAuthentication
,
DataSource.requiresRole
,
DataSource.requires
,
DataSource.creatorOverrides
,
DataSourceField.viewRequiresAuthentication
,
DataSourceField.editRequiresAuthentication
,
DataSourceField.initRequiresAuthentication
,
DataSourceField.updateRequiresAuthentication
,
DataSourceField.viewRequiresRole
,
DataSourceField.editRequiresRole
,
DataSourceField.initRequiresRole
,
DataSourceField.updateRequiresRole
,
DataSourceField.viewRequires
,
DataSourceField.editRequires
,
DataSourceField.initRequires
,
DataSourceField.updateRequires
,
DataSourceField.creatorOverrides
,
OperationBinding.requiresAuthentication
,
OperationBinding.requiresRole
,
OperationBinding.requires
,
OperationBinding.creatorOverrides
,
DataSource.getEnforceSecurityOnClient()