<?xml version="1.0" encoding="utf-8"?>
<AzAdminManager MajorVersion="1" MinorVersion="0" Description="MMB Website Authorization Store for use with CoSign (v. 0.1) test">
	<AzApplication Guid="be45f7e5-060a-450f-92ae-40f86a4c10dc" Name="IIS 6.0 URL Authorization" Description="" ApplicationVersion=""><AzOperation Guid="0a5283fb-5d7c-4ed6-b5fa-6bc11e2bbde8" Name="AccessURL" Description=""><OperationID>1</OperationID></AzOperation><AzTask Guid="1bb5dc5d-4fa2-4701-afba-ad56ca917e99" Name="Viewer" Description="" BizRuleImportedPath="C:\URLauthRule.vbs" RoleDefinition="True"><OperationLink>0a5283fb-5d7c-4ed6-b5fa-6bc11e2bbde8</OperationLink><BizRuleLanguage>VBScript</BizRuleLanguage><BizRule>AzBizRuleContext.BusinessRuleResult = false
' Set BizRule result to fail in case script stops prematurely

' ----------------------------------------------------
' Authorization Manager Rule script.
' Retrieves CoSign Uniqname variable from host header,
' and queries database to determine if username
' assigned access to given URL.
'
' David Sweetman - dsweetma@umich.edu
' v0.2.0
' ----------------------------------------------------

Dim oConn, oRS, SQL, URL, URLID, uniqname, UniqnameID, IP, ALL_RAW
Dim s, buf, b, p

' database connection
Set oConn = CreateObject("ADODB.Connection")
Set oRS = CreateObject ("ADODB.Recordset")

oConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" &amp; _
                               "DBQ=c:\MMB\database\URLAuthorization.mdb"


URL = lcase(AzBizRuleContext.GetParameter("URL"))
IP = "0.0.0.0" 'lcase(AzBizRuleContext.GetParameter("REMOTE_ADDR"))
ALL_RAW = AzBizRuleContext.GetParameter("ALL_HTTP")

buf = split(ALL_RAW,chr(10))                            ' split them according to the chr(10)
for each b in buf                                 ' for each element in the split string
   b = trim(b)                                    ' remove spaces
   p = instr(b,"REMOTE_USER:")                    ' search for the remote_user string
   if p&gt;0 then                                    ' if it's there
      uniqname = trim(mid(b,instr(b,chr(32))+1))  ' retrieve the user name and trim all spaces
      uniqname = left(uniqname,len(uniqname))   ' the last character is a chr(10) so remove it
   end if                                         ' end if
Next
Uniqname = lcase(Right(Uniqname, (Len(Uniqname) - Instr(Uniqname, ":"))))

oConn.Open

URLID = returnURLid(URL)

If URLID = 0 Then
   ' URLpath not defined in db for use with URL Authorization
   SQL = "INSERT INTO AccessErrors (DateTimeErr, IP, AccName, URL, ErrMsg) VALUES (" &amp; _
      "#" &amp; Now &amp; "#, '" &amp; IP &amp; "', '" &amp; Uniqname &amp; _
      "', '" &amp; URL &amp; "', 'URLpath not defined in db.')"
   oConn.execute SQL
End If

SQL = "SELECT ID FROM AccessPrincipals WHERE AccName = '" &amp; Uniqname &amp; "'"
oRS.Open SQL, oConn
If oRS.EOF Then
   ' Uniqname not found in db
   SQL = "INSERT INTO AccessErrors (DateTimeErr, IP, AccName, URL, ErrMsg) VALUES (" &amp; _
      "#" &amp; Now &amp; "#, '" &amp; IP &amp; "', '" &amp; Uniqname &amp; _
      "', '" &amp; URL &amp; "', 'Uniqname not found in db.')"
   oConn.execute SQL
   UniqnameID = 0
Else
   UniqnameID = oRS("ID")
End If
oRS.Close

SQL = "SELECT URLAccess.URLID FROM URLAccess, UserGroup WHERE " &amp; _
   "(URLAccess.AccessID = UserGroup.UserID OR URLAccess.AccessID = UserGroup.GroupID) " &amp; _
   "AND URLID = " &amp; URLID &amp; " AND UserID = " &amp; UniqnameID
oRS.Open SQL, oConn
If oRS.EOF Then
   ' Uniqname not found in db
   SQL = "INSERT INTO AccessErrors (DateTimeErr, IP, AccName, URL, ErrMsg) VALUES (" &amp; _
      "#" &amp; Now &amp; "#, '" &amp; IP &amp; "', '" &amp; Uniqname &amp; _
      "', '" &amp; URL &amp; "', 'User not authorized to access resource.')"
   oConn.execute SQL
Else
' for troubleshooting
   SQL = "INSERT INTO AccessErrors (DateTimeErr, IP, AccName, URL, ErrMsg) VALUES (" &amp; _
      "#" &amp; Now &amp; "#, '" &amp; IP &amp; "', '" &amp; Uniqname &amp; _
      "', '" &amp; URL &amp; "', 'Access granted.')"
   oConn.execute SQL

   ' Person is authorized, set result to true
   AzBizRuleContext.BusinessRuleResult = true
End If
oRS.Close
  
oConn.Close

' -------------------------------------------------------------------------

Function ReturnURLid(URL)
  ' returns db id of URL specified, or closest parent dir
  ' zero if id not found or abnormal function termination

  ReturnURLid = 0

  Dim resultURL, URLarray, dir, ArrMax, i, j
 
  resultURL = URL
  URLarray = split(URL, "/") ' create array of dirs/filename in URL
  For each dir in URLArray
     If Len(dir) &gt; 1 Then    ' for initial (empty) value
        ArrMax = ArrMax + 1
     End If
  Next

  If Instr(URLArray(arrMax), ".") Then
     ' assumes directories will not have "." in name
     ' decrements Array to then recurse for deepest folder defined in db
     ArrMax = ArrMax - 1
  End If

  For i = 1 to arrMax
     resultURL = ""
     ' starts at root, higher directories will overwrite value
     For j = 1 to i
        ' re-construct construct URL
        resultURL = resultURL &amp; "/" &amp; URLArray(j)
     Next

     SQL = "SELECT ID FROM URLpaths WHERE URL = '" &amp; resultURL &amp; "'"
     oRS.Open SQL, oConn
     If NOT oRS.EOF Then
        returnURLid = oRS("ID")
     End If
     oRS.Close
  Next

End Function

Set oConn = Nothing
Set oRS = Nothing
</BizRule></AzTask><AzScope Guid="16b2db41-ebb3-410c-a6c9-17c7b9f50283" Name="CoSign" Description=""><AzRole Guid="aa6ebc36-6535-4887-bab7-b8adb7c38037" Name="Viewer"><TaskLink>1bb5dc5d-4fa2-4701-afba-ad56ca917e99</TaskLink><Member>S-1-5-21-3238728885-3433763950-1021928860-1003</Member></AzRole><AzRole Guid="c33080e1-d52e-4354-b885-08b5c1c83bfa" Name="ViewAlways"><TaskLink>a75f97f0-e728-4cda-94eb-7527c2c06920</TaskLink><Member>S-1-5-32-544</Member></AzRole></AzScope><AzTask Guid="a75f97f0-e728-4cda-94eb-7527c2c06920" Name="ViewAlways" Description="" BizRuleImportedPath="C:\URLAuth\URLAuthRuleTrue.vbs" RoleDefinition="True"><BizRuleLanguage>VBScript</BizRuleLanguage><BizRule>AzBizRuleContext.BusinessRuleResult = true</BizRule><OperationLink>0a5283fb-5d7c-4ed6-b5fa-6bc11e2bbde8</OperationLink></AzTask><AzTask Guid="85b7089a-a9cf-46ff-86de-8dbd7c0fd1e3" Name="ViewNever" Description="" BizRuleImportedPath="C:\URLAuth\URLAuthRuleFalse.vbs" RoleDefinition="True"><BizRuleLanguage>VBScript</BizRuleLanguage><BizRule>AzBizRuleContext.BusinessRuleResult = false</BizRule><OperationLink>0a5283fb-5d7c-4ed6-b5fa-6bc11e2bbde8</OperationLink></AzTask></AzApplication></AzAdminManager>
