Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 79a32d0

Browse files
author
Reed Williams
committed
Accounted for absence of 403/404
Header still built if 403 or 404 is missing. An error is reported to the user
1 parent 3badfbc commit 79a32d0

1 file changed

Lines changed: 34 additions & 21 deletions

File tree

AdfsEventsModule.psm1

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ function ConstructHeader
251251
Write-Output $Dictionary
252252
}
253253

254+
function CreateHeaderObject
255+
{
256+
$Obj = New-Object PSObject -Property @{
257+
"QueryString" = ""
258+
"ResponseString" = ""
259+
"RequestHeader" = @{}
260+
"ResponseHeader"= @{}
261+
}
262+
263+
Write-Output $Obj
264+
}
265+
254266
function GetHTTPRequestInformation
255267
{
256268
param(
@@ -271,29 +283,35 @@ function GetHTTPRequestInformation
271283

272284

273285
$HTTPTraffic = @()
286+
$HeaderObject = CreateHeaderObject
274287
#Parse relevant information and store in readable/accessible format
275-
for($I = 0; $I -lt $RequestAndResponseEvents.length-1; $I=$I+2)
288+
for($I = 0; $I -lt $RequestAndResponseEvents.length; $I++)
276289
{
277-
if($RequestAndResponseEvents[$I].ID -eq 403 -and $RequestAndResponseEvents[$I+1].ID -eq 404)
278-
{
279-
$QueryString = $RequestAndResponseEvents[$I].RemoteProperties[4] + $RequestAndResponseEvents[$I].RemoteProperties[5] + $RequestAndResponseEvents[$I].RemoteProperties[6]
280-
$ResponseString = $RequestAndResponseEvents[$I+1].RemoteProperties[3] + " " + $RequestAndResponseEvents[$I+1].RemoteProperties[4]
290+
$CurrentID = $RequestAndResponseEvents[$I].ID
281291

282-
$Request = ConstructHeader -Event $HeaderEvents[$I]
283-
$Response = ConstructHeader -Event $HeaderEvents[$I+1]
292+
if($CurrentID -eq 403)
293+
{
294+
$HeaderObject.QueryString = $RequestAndResponseEvents[$I].RemoteProperties[4] + $RequestAndResponseEvents[$I].RemoteProperties[5] + $RequestAndResponseEvents[$I].RemoteProperties[6]
295+
$HeaderObject.RequestHeader = ConstructHeader -Event $HeaderEvents[$I]
296+
297+
}
298+
else #Event is a 404
299+
{
300+
$HeaderObject.ResponseString = $ResponseString = $RequestAndResponseEvents[$I].RemoteProperties[3] + " " + $RequestAndResponseEvents[$I].RemoteProperties[4]
301+
$HeaderObject.ResponseHeader = ConstructHeader -Event $HeaderEvents[$I]
302+
}
284303

285-
$Obj = New-Object PSObject -Property @{
286-
"QueryString" = $QueryString
287-
"ResponseString" = $ResponseString
288-
"RequestHeader" = $Request
289-
"ResponseHeader"= $Response
290-
}
291-
$HTTPTraffic += $Obj
304+
if(($CurrentID -eq 404) -or $I -eq ($RequestAndResponseEvents.length-1) -or ($RequestAndResponseEvents[$I+1].ID -eq 403))
305+
{
306+
#Begin reconstructing next header if current event is 404 (response), at the end of events list, or the next event represents a request
307+
$HTTPTraffic += $HeaderObject
308+
$HeaderObject = CreateHeaderObject #Clear object for next iteration of loop
292309
}
293310

294-
else
311+
if(($I % 2 -eq 0 -and $CurrentID -eq 404) -or ($I %2 -eq 1 -and $CurrentID -eq 403))
295312
{
296-
Write-Error "Unable to match request and response headers"
313+
#Expecting each 403 to be followed by a 404. Each 403 should have an even index and each 404 should have an odd index in the list.
314+
Write-Warning "Unable to match request and response headers"
297315
}
298316
}
299317

@@ -508,11 +526,6 @@ function Get-ADFSEvents
508526
#Print the result of gathering events for all correlation ids
509527
foreach($EventList in $HashTable.Values)
510528
{
511-
<# if(!$Headers)
512-
{
513-
AggregateOutputObject -CorrID $EventList[0].CorrelationID -Events $EventList -Headers []
514-
}
515-
#>
516529

517530
if($Headers){ #Gather headers for each correlation id from each server
518531
foreach($Machine in $ServerList)

0 commit comments

Comments
 (0)