Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
resp.ContentType = "application/json"
Dim AuthorizationHeader As String = req.GetHeader("Authorization")
Dim Result As Boolean
Dim token As String
If AuthorizationHeader.Length > 7 Then
token = AuthorizationHeader.SubString(7).Trim
End If
If Database.IsTokenAValidOne(token) Then
If req.GetSession.GetAttribute2(token, False) = True Then
If req.GetSession.LastAccessedTime + DateTime.TicksPerMinute * 30 > DateTime.Now Then
req.GetSession.SetAttribute(token, True)
status = 200
message = "success"
Result = True
Else
req.GetSession.SetAttribute(token, False)
req.GetSession.RemoveAttribute(token)
status = 422
message = "Session timed out."
Result = False
End If
Else
status = 401
message = "Unauthorized."
Result = False
End If
Else
status = 400
message = "Invalid token."
Result = False
End If
Dim ResponseMap As Map
ResponseMap.Initialize
ResponseMap.Put("status", status)
ResponseMap.Put("message", message)
Variables.jsonGenerator.Initialize(ResponseMap)
resp.Write(Variables.jsonGenerator.ToString)
Log(Variables.jsonGenerator.ToString)
Return Result
End Sub