Define Conditions

Author: Visual Guard 72 views

You can also define a condition for a security action. Visual Guard evaluates the condition just before executing an action. If the condition is false, the action is not executed.

  • You can specify the condition by selecting Condition checkbox in Security action wizard.
  • Once you select the condition checkbox the highlighted controls will be activated.
  • Visual Guard provides you an expression language. The Visual Guard expression language supports logical and arithmetic operators, method invocation and allows to access to the context of the security action.
  • Visual Guard evaluates the value of the expression at runtime for the current context of the security action and uses the return value to determine whether the action should be executed or not. The action is executed when the value is equal to true.
  • Once you click on the option (B) following values will be displayed to you.
  • Visual Guard provides you both variables and expressions for selection:
#PermissionA VGIPermission object containing the permission for which the security action is executed. You can access to the value of a permission argument by using the syntax: #Permission[‘myarg’].
#PrincipalA VGIPrincipal object containing the principal for which the action is executed.You can use this variable to check whether the user is authenticated or not (#Principal.Identity.IsAuthenticated) or if the current user is member of a specific role (#Principal.IsInRole(‘administrator’)).
Current User IdA string value containing the Visual Guard repository Id of the user for which the action is executed.
Current UsernameA string value containing the name of the user for which the action is executed.
andThis the logical or conditional AND operator (compatible with integer, enum or boolean types)For Example1 == 1 and ‘a’ == ‘a’
MyEnum.Value1 and MyEnum.Value2
1 and 2
orThis is the logical or conditional OR operator (compatible with integer, enum or boolean types)For Example1 == 1 or ‘a’ == ‘b’
MyEnum.Value1 or MyEnum.Value2
1 or 2
==Equality for example0==0
!=Inequality for example 1 !=0
>=Greater than or Equal for example 1>=1
<=Less than or equal for example 1<=1
>Greater than for example 1>0
<Less Than for example 1<0
isThis option checks if an object is compatible with a given type.For example ‘1’ is string
likeThis option compares a string against a pattern.For example ‘Abc’ like ‘[A-Z]b*’
betweenThis option checks if a numeric or string value is between two valuesFor example1 between {0,2}
‘efg’ between {‘abc’, ‘xyz’}
type ofThis option checks the data type of the value.
  • The specified condition will be displayed in the highlighted section.
  • The Visual Guard security action designer tries to check the specified expression at design time. It parses the expression and evaluates the type of the declared objects.
  • Please Note: In some cases, Visual Guard cannot evaluate the right type of an object and generates a warning.
  • The errors / warnings will be displayed in the highlighted section as shown below.