Secured Feature Layer

Complexity: Beginner Data Requirement: ArcGIS Tutorial Data for Desktop

This sample shows how to add a secure feature service to a map and how to execute a query task upon a secure service. ArcGIS Server web service may be secured to permit access to only authorized users through token-based authentication or HTTP authentication. When a layer is failed to be loaded to a map due to security, both the layer and the map will send out EsriSecurityException error. Users can listen to the status changed events on Layer or MapView to handle the error.

Sample Design

When initializes a feature layer from a secure feature service, a credential or a token is passed to the service through a UserCredentials object. In this sample a token is fed in the ArcGISFeatureLayer constructor. The token used in the sample is a short-term token. When the token is expired, the OnStatusChangedListener set on the map will receive an EsriSecurityException. Then the OnStatusChangedListener will reinitialize the layer by passing in username and password. The Information on how to obtain a token is available in "Obtaining a token" section in the "Working with secure ArcGIS services" in ArcGIS API for JavaScript Help.

In the single tap event listener a query on the secure feature service will be executed. The setting of the Query for secure service is the same as the setting for an ordinary service. However, a credential or a token is required for the QueryTask. In this sample username and password are passed to the QueryTask through a UserCredentials object. The QueryTask is independent of the feature layer. Even if the feature layer can't be loaded into the map for some reason, the QueryTask is still able to execute.

Using the Sample

Steps:
  1. Obtain a token from the token service associated with the feature service. Paste the token to the ArcGISFeatureLayer constructor in the sample. Build the sample.
  2. Upload the sample on your device.
  3. Tap on the map to execute the query. The result of the query will be shown in a toast.
  4. If the token expires or the feature layer can’t be loaded due to other security issues, a message will be displayed in a toast. And the feature layer will be reinitialized.
5/31/2012