Permalink
Browse files

Add proxy and auth support to wfs client (#3982)

Copied & adapted from similar code in mapwmslayer.c.

Fix two copy-pasto errors while here, wfs_http_cookie was not
looked up.
  • Loading branch information...
1 parent 743a3ea commit 9e552785960326b2d8dab3f59a04cfae14f27bb8 @landryb landryb committed Jul 15, 2013
Showing with 125 additions and 2 deletions.
  1. +125 −2 mapwfslayer.c
View
@@ -504,6 +504,14 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
wfsParamsObj *psParams = NULL;
char *pszHTTPCookieData = NULL;
+ char *pszProxyHost=NULL;
+ long nProxyPort=0;
+ char *pszProxyUsername=NULL, *pszProxyPassword=NULL;
+ char *pszHttpAuthUsername=NULL, *pszHttpAuthPassword=NULL;
+ enum MS_HTTP_AUTH_TYPE eHttpAuthType = MS_BASIC;
+ enum MS_HTTP_AUTH_TYPE eProxyAuthType = MS_BASIC;
+ enum MS_HTTP_PROXY_TYPE eProxyType = MS_HTTP;
+
if (lp->connectiontype != MS_WFS || lp->connection == NULL)
return MS_FAILURE;
@@ -555,13 +563,118 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
nTimeout = atoi(pszTmp);
}
+/* ------------------------------------------------------------------
+ * Check for authentication and proxying metadata. If the metadata is not found
+ * in the layer metadata, check the map-level metadata.
+ * ------------------------------------------------------------------ */
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_host")) != NULL)
+ {
+ pszProxyHost = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_port")) != NULL)
+ {
+ nProxyPort = atol(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_type")) != NULL)
+ {
+
+ if (strcasecmp(pszTmp, "HTTP") == 0)
+ eProxyType = MS_HTTP;
+ else if (strcasecmp(pszTmp, "SOCKS5") == 0)
+ eProxyType = MS_SOCKS5;
+ else
+ {
+ msSetError(MS_WMSERR, "Invalid proxy_type metadata '%s' specified",
+ "msPrepareWFSLayerRequest()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_auth_type")) != NULL)
+ {
+ if (strcasecmp(pszTmp, "BASIC") == 0)
+ eProxyAuthType = MS_BASIC;
+ else if (strcasecmp(pszTmp, "DIGEST") == 0)
+ eProxyAuthType = MS_DIGEST;
+ else if (strcasecmp(pszTmp, "NTLM") == 0)
+ eProxyAuthType = MS_NTLM;
+ else if (strcasecmp(pszTmp, "ANY") == 0)
+ eProxyAuthType = MS_ANY;
+ else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+ eProxyAuthType = MS_ANYSAFE;
+ else
+ {
+ msSetError(MS_WMSERR, "Invalid proxy_auth_type metadata '%s' specified",
+ "msPrepareWMSLayerRequest()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_username")) != NULL)
+ {
+ pszProxyUsername = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "proxy_password")) != NULL)
+ {
+ pszProxyPassword = msDecryptStringTokens(map, pszTmp);
+ if (pszProxyPassword == NULL) {
+ return(MS_FAILURE); /* An error should already have been produced */
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "auth_type")) != NULL)
+ {
+ if (strcasecmp(pszTmp, "BASIC") == 0)
+ eHttpAuthType = MS_BASIC;
+ else if (strcasecmp(pszTmp, "DIGEST") == 0)
+ eHttpAuthType = MS_DIGEST;
+ else if (strcasecmp(pszTmp, "NTLM") == 0)
+ eHttpAuthType = MS_NTLM;
+ else if (strcasecmp(pszTmp, "ANY") == 0)
+ eHttpAuthType = MS_ANY;
+ else if (strcasecmp(pszTmp, "ANYSAFE") == 0)
+ eHttpAuthType = MS_ANYSAFE;
+ else
+ {
+ msSetError(MS_WMSERR, "Invalid auth_type metadata '%s' specified",
+ "msPrepareWFSLayerRequest()", pszTmp);
+ return MS_FAILURE;
+ }
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "auth_username")) != NULL)
+ {
+ pszHttpAuthUsername = msStrdup(pszTmp);
+ }
+
+ if ((pszTmp = msOWSLookupMetadata2(&(lp->metadata), &(map->web.metadata),
+ "FO", "auth_password")) != NULL)
+ {
+ pszHttpAuthPassword = msDecryptStringTokens(map, pszTmp);
+ if (pszHttpAuthPassword == NULL) {
+ return(MS_FAILURE); /* An error should already have been produced */
+ }
+ }
+
/*------------------------------------------------------------------
* Check to see if there's a HTTP Cookie to forward
* If Cookie differ between the two connection, it's NOT OK to merge
* the connection
* ------------------------------------------------------------------ */
if ((pszTmp = msOWSLookupMetadata(&(lp->metadata),
- "MO", "http_cookie")) != NULL) {
+ "FO", "http_cookie")) != NULL) {
if(strcasecmp(pszTmp, "forward") == 0) {
pszTmp= msLookupHashTable(&(map->web.metadata),"http_cookie_data");
if(pszTmp != NULL) {
@@ -571,7 +684,7 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
pszHTTPCookieData = msStrdup(pszTmp);
}
} else if ((pszTmp = msOWSLookupMetadata(&(map->web.metadata),
- "MO", "http_cookie")) != NULL) {
+ "FO", "http_cookie")) != NULL) {
if(strcasecmp(pszTmp, "forward") == 0) {
pszTmp= msLookupHashTable(&(map->web.metadata),"http_cookie_data");
if(pszTmp != NULL) {
@@ -623,6 +736,16 @@ int msPrepareWFSLayerRequest(int nLayerId, mapObj *map, layerObj *lp,
pasReqInfo[(*numRequests)].bbox = bbox;
pasReqInfo[(*numRequests)].debug = lp->debug;
+ pasReqInfo[(*numRequests)].pszProxyAddress = pszProxyHost;
+ pasReqInfo[(*numRequests)].nProxyPort = nProxyPort;
+ pasReqInfo[(*numRequests)].eProxyType = eProxyType;
+ pasReqInfo[(*numRequests)].eProxyAuthType = eProxyAuthType;
+ pasReqInfo[(*numRequests)].pszProxyUsername = pszProxyUsername;
+ pasReqInfo[(*numRequests)].pszProxyPassword = pszProxyPassword;
+ pasReqInfo[(*numRequests)].eHttpAuthType = eHttpAuthType;
+ pasReqInfo[(*numRequests)].pszHttpUsername = pszHttpAuthUsername;
+ pasReqInfo[(*numRequests)].pszHttpPassword = pszHttpAuthPassword;
+
/* ------------------------------------------------------------------
* Pre-Open the layer now, (i.e. alloc and fill msWFSLayerInfo inside
* layer obj). Layer will be ready for use when the main mapserver

0 comments on commit 9e55278

Please sign in to comment.