Skip to content

Commit

Permalink
add ArcGIS MapServer token based security support
Browse files Browse the repository at this point in the history
This adds support for ArcGIS's proprietary token-based authentication for
services. [1]

The solution is not robust: tokens are subject to expiration, after which point
the imagery provider will begin throwing exceptions (rightfully so).

Abstracting authentication further (outside of ArcGIS MapServer imagery
providers) may be a good idea, but is a larger task worth more thought.

Further, ArcGIS supports requesting security tokens for a set of credentials
via HTTP (GET, possibly POST as well), though this is not guaranteed to be
enabled on the server.

[1] - http://resources.arcgis.com/en/help/main/10.1/index.html#/About_ArcGIS_tokens/0155000005s0000000/
  • Loading branch information
nmschulte-aviture committed Jul 9, 2015
1 parent 9691396 commit 1a419cc
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions Source/Scene/ArcGisMapServerImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ define([
*
* @param {Object} options Object with the following properties:
* @param {String} options.url The URL of the ArcGIS MapServer service.
* @param {String} [options.token] The ArcGIS token used to authenticate with the ArcGIS MapServer service.
* @param {TileDiscardPolicy} [options.tileDiscardPolicy] The policy that determines if a tile
* is invalid and should be discarded. If this value is not specified, a default
* {@link DiscardMissingTileImagePolicy} is used for tiled map servers, and a
Expand Down Expand Up @@ -117,6 +118,7 @@ define([
//>>includeEnd('debug');

this._url = options.url;
this._token = options.token;
this._tileDiscardPolicy = options.tileDiscardPolicy;
this._proxy = options.proxy;

Expand Down Expand Up @@ -205,10 +207,16 @@ define([
}

function requestMetadata() {
var parameters = {
f: 'json'
};

if (defined(that._token)) {
parameters.token = that._token;
}

var metadata = jsonp(that._url, {
parameters : {
f : 'json'
},
parameters : parameters,
proxy : that._proxy
});
when(metadata, metadataSuccess, metadataFailure);
Expand Down Expand Up @@ -244,6 +252,14 @@ define([
}
}

var token = imageryProvider._token;
if (defined(token)) {
if (url.indexOf('?') === -1) {
url += '?';
}
url += 'token=' + token;
}

var proxy = imageryProvider._proxy;
if (defined(proxy)) {
url = proxy.getURL(url);
Expand All @@ -265,6 +281,18 @@ define([
}
},

/**
* Gets the ArcGIS token used to authenticate with the ArcGis MapServer service.
* @memberof ArcGisMapServerImageryProvider.prototype
* @type {String}
* @readonly
*/
token : {
get : function() {
return this._token;
}
},

/**
* Gets the proxy used by this provider.
* @memberof ArcGisMapServerImageryProvider.prototype
Expand Down Expand Up @@ -606,6 +634,10 @@ define([
url += ':' + this._layers;
}

if (defined(this._token)) {
url += '&token=' + this._token;
}

if (defined(this._proxy)) {
url = this._proxy.getURL(url);
}
Expand Down

0 comments on commit 1a419cc

Please sign in to comment.