Tuesday, 24 October 2017

Geoserver - Key Authentication against a MySql Database


I am trying to implement a token based security scheme with Geoserver.


What we need to do is send the client a license key when they log into our primary application. This license key is generated by another application and is stored in a MySql Database along with the User name and password, Ip Address form login, etc.


We would like to be able to pass this License key as part of the WMS Request to ensure that only logged in and validated users obtain access to the data.


Has anyone implemented anything similar before, any help, suggestions or code would be appreciated.


Edit ..


I Think I may have answered my own question, we use Classic ASP Still (Dinasour) and something like the following from here might do the trick.


<% 
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
strURL = Request("url")"

objHttp.open "GET", strURL, False
objHttp.Send
If objHttp.status = 200 Then
Response.Expires = 90
Response.ContentType = Request("mimeType")
Response.BinaryWrite objHttp.responseBody
set objHttp = Nothing
End If %>

Answer



Ok, I messed up the code in the comment. Here is the final Code. Thanks for pointing it out Paul.



        <%
Session.Timeout=10 ' ten minute timeout, question is, will same session remain open or not?? Should timeout be longer so sessions will be reused???

ServerName=trim(ucase(Request.ServerVariables("SERVER_NAME")))
MapUrl=urldecode(trim(Request.querystring))

If ServerName <> "MAPS.XXXXX.NET" AND ServerName <> "MAPS1.XXXXX.NET" AND ServerName <> "MAPS2.XXXXX.NET" AND ServerName <> "MAPS3.XXXXX.NET" AND ServerName <> "MAPS4.XXXXX.NET" AND ServerName <> "MAPS5.XXXXX.NET" Then
response.clear
response.end
end if



If Servername="MAPS.XXXXX.NET" Then

newurl="http://java2:8080/geoserver/web"

else

If ServerName = "MAPS1.XXXXX.NET" Or ServerName <> "MAPS3.XXXXX.NET" Then


'newurl="http://java2:8080/geoserver/a_ph/gwc/service/wms?" & MapUrl
'newurl="http://java2:8080/geoserver/a_ph/wms?" & MapUrl
newurl="http://java2:8080/geoserver/wms?" & MapUrl
'newurl="http://java2:8080/geoserver/gwc/service/wms?" & MapUrl

Else

'newurl="http://java1:8080/geoserver/a_ph/gwc/service/wms?" & MapUrl
'newurl="http://java1:8080/geoserver/a_ph/wms?" & MapUrl
newurl="http://java1:8080/geoserver/wms?" & MapUrl

'newurl="http://java1:8080/geoserver/gwc/service/wms?" & MapUrl

End If

end if




set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")




objHttp.open "GET", newURL, False
objHttp.Send

If objHttp.status = 200 Then
Response.Expires = 90
Response.ContentType = Request("mimeType")
Response.BinaryWrite objHttp.responseBody

set objHttp = Nothing

else

Response.Write objHttp.responseBody

'response.clear
'response.end

End If


'======================================================================================


Function URLDecode(str)
Dim re
Set re = new RegExp
str = Replace(str, "+", " ")
re.Pattern = "%([0-9a-fA-F]{2})"
re.Global = True

URLDecode = re.Replace(str, GetRef("URLDecodeHex"))
end function

' Replacement function for the above
Function URLDecodeHex(match, hex_digits, pos, source)
URLDecodeHex = chr("&H" & hex_digits)
End Function

Function URLDecode1(sConvert)


sDecoded = sConvert
Set oRegExpr = Server.CreateObject("VBScript.RegExp")
oRegExpr.Pattern = "%[0-9,A-F]{2}"
oRegExpr.Global = True
Set oMatchCollection = oRegExpr.Execute(sConvert)
For Each oMatch In oMatchCollection
sDecoded = Replace(sDecoded,oMatch.value,Chr(CInt("&H" & Right(oMatch.Value,2))))
Next
URLDecode = sDecoded


end function

Function URLDecode2(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If


' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")

' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")

If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1

sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If

URLDecode = sOutput
End Function



%>

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...