在脚本中使用业务逻辑限定访问权限

使用业务规则脚本提供用于检查访问权限的运行时逻辑。 有关业务规则的详细信息,请参阅 业务规则

若要为任务分配业务规则,请首先设置表示任务的 IAzTask 对象的 BizRuleLanguage 属性。 必须使用 Visual Basic Scripting Edition (VBScript) 编程语言或 JScript 开发软件编写脚本。 指定脚本语言后,使用脚本的字符串表示形式设置 IAzTask 对象的 BizRule 属性。

检查由具有关联业务规则的任务包含的操作的访问时,应用程序必须创建两个大小相同的数组,以作为 IAzClientContext 对象的 AccessCheck 方法的 varParameterNamesvarParameterValues 参数传递。 有关创建客户端上下文的信息,请参阅 在脚本中建立客户端上下文

AccessCheck 方法创建传递给业务规则脚本的 AzBizRuleContext 对象。 然后,该脚本设置 AzBizRuleContext 对象的 BusinessRuleResult 属性。 值为 True 表示已授予访问权限,值为 False 表示拒绝访问。

业务规则脚本不能分配给委托 的 IAzScope 对象包含的 IAzTask 对象。

以下示例演示如何使用业务规则脚本检查客户端对操作的访问权限。 该示例假定驱动器 C 根目录中有一个名为 MyStore.xml 的现有 XML 策略存储,并且此存储包含名为 Expense 的应用程序、名为 Submit Expense 的任务和名为 UseFormControl 的操作。

<%@ Language=VBScript %>
<%
'  Create the AzAuthorizationStore object.
Dim AzManStore
Set AzManStore = CreateObject("AzRoles.AzAuthorizationStore")

'  Initialize the authorization store.
AzManStore.Initialize 0, "msxml://C:\MyStore.xml"

'  Open the application object in the store.
Dim expenseApp
Set expenseApp = AzManStore.OpenApplication("Expense")

'  Create a client context.
Dim clientName
clientName = Request.ServerVariables("LOGON_USER")
Dim clientContext
Set clientContext = _
    expenseApp.InitializeClientContextFromName(clientName)

'  Create a business rule for the Submit Expense task.

'  Open the Submit Expense task.
Dim submitTask
Set submitTask = expenseApp.OpenTask("Submit Expense")

'  Set the business rule language to VBScript.
submitTask.BizRuleLanguage = "VBScript"

'  Create a string with the business rule code.
Dim newline
newline = chr(13)
Dim bizRuleString
bizRuleString = "Dim Amount" + newline _
         +"AzBizRuleContext.BusinessRuleResult = FALSE" + newline _
         +"Amount = AzBizRuleContext.GetParameter(""ExpAmount"")" _
   +newline _
   +"if Amount < 500 then AzBizRuleContext.BusinessRuleResult = TRUE"

'  Assign the business rule to the Submit Expense task.
submitTask.BizRule = bizRuleString
                
'  Save the task information to the store.
submitTask.Submit

'  Open the operation to check.
Dim formOperation
Set formOperation = expenseApp.OpenOperation("UseFormControl")

'  Get the ID of the operation.
Dim operationID
operationID = formOperation.OperationID

'  Set up arrays for operations and results.
Dim Operations(1)
Operations(0) = operationID
Dim Results

'  Set up business rule parameters.
Dim bizNames(1)
Dim bizValues(1)
bizNames(0) = "ExpAmount"
bizValues(0) = 100

'  Check access.
Results = clientContext.AccessCheck _
    ("UseFormControl", Empty, Operations, bizNames, bizValues)
 
%>