Security Scripts

 

How to Perform Complex Real-time Security Check

  • Usage: Security script

  • Description: Recursively executes a query after inserting the item IDs in batches and then determines whether access is granted.

Complex Real-time Security Check
Copy
Dim sIm()() As String = HOST.GetSecurityItems() 
Dim sqlString As String = HOST.GetSecuritySQL()
For i As Integer = 0 To sIm.Length - 1    
    Dim docId As String = sIm(i)(0)
    Dim docVer As String = sIm(i)(1) 
    dim tSQL as String = sqlString.Replace("[SPW_ID]",docId).Replace("[SPW_SUBID]",docVer).Replace("[SPW_USERID]",HOST.GetResolvedUserID()) 
    HOST.WriteTrace("SCRIPTSQL:" & tSQL)
    dim ds as Dataset = HOST.FillDataSet(tSQ
    If (ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0) Then        
        Dim fail As Boolean = False    
        For ii As Integer = 0 To ds.Tables(0).Rows.Count - 1        
            If (ds.Tables(0).Rows(ii).Item(0).ToString() = "0") Then            
                fail = True 
                Exit For     
            End if            
        Next
        If Not fail Then        
            HOST.GrantItemAccess(docId, docVer)            
        End If        
    End If    
Next

How to Run a Recursive Security Script

  • Usage: Security script

  • Description: Use an SQL statement and batch the queries into smaller chunks. BA Insight recommends this script for single, ID-based items.

Recursive Security Script
Copy
Dim sIm()() As String = HOST.GetSecurityItems()
Dim sqlString As String = HOST.GetSecuritySQL()
dim parmStr as String = ""dim parmCnt as Integer = 0
Dim itemverHT as New Hashtable()
Dim alreadyRan as Boolean = false
HOST.WriteTrace("Items:" & sIm.Length.tostring())
For i As Integer = 0 To sIm.Length - 1
    Dim docId As String = sIm(i)(0)
    if parmStr <> "" then    
        parmStr += ", "    
    end if
    parmCnt += 1
    parmStr += "'" & docId & "'"    if (i = sIm.Length - 1 or parmCnt = 30) and not alreadyRan then    
        alreadyRan = true    
        dim tSQL as String = sqlString.Replace("[SPW_ID]",parmStr).Replace("[SPW_USERID]",HOST.GetResolvedUserID())    
        HOST.WriteTrace("SCRIPTSQL:" & tSQL)    
        Dim ds as DataSet = HOST.FillDataSet(tSQL)    
        If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
            For ii As Integer = 0 To ds.Tables(0).Rows.Count - 1        
                Dim dId as String = ds.Tables(0).Rows(ii).Item(0).ToString()        
                HOST.GrantItemAccess(dId,"")        
            Next    
        End If
        parmStr = ""        parmCnt = 0
    end if
Next