Select to view content in your preferred language

Trouble with secured services

2979
11
11-26-2013 07:04 AM
RobertHupp
Deactivated User
We are currently in the process of trying to secure our services in our organization and I am not understanding an error with a secure service I'm working with.
Going thru ArcGIS Server Manager I set the security settings for private and specify roles for the individual service. This of course removes the service from our REST services directory until I log in with my credentials, then I am able to see it. Using the secured service I am able to create a web map in AGOL which of course prompts me for my credentials at which time when entered displays the sercured service on the web map.

My problem or question is that when I use the service in a javascript application it prompts me for authorization but when I enter my credentials it does not allow me access to the secured service through the javascript application. I get an "Unable to access the authentication service". What am I missing? Why can't I access the service through the application?
Here is my code:

<script>
      dojo.require("esri.map");
      dojo.require("dojox.grid.DataGrid");
      dojo.require("dojo.data.ItemFileReadStore");
      dojo.require("esri.tasks.find");
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("dijit.form.Button");
      dojo.require("esri.dijit.Legend");
      dojo.require("esri.InfoTemplate");

      var map, center, zoom, grid;

      function init() {
        center = [-98.495, 29.42];
        zoom = 13;
        map = new esri.Map("map", {
          basemap: "streets",
          center: center,
          zoom: zoom
        });
        
  var transMapLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer", {
          id: "trans",
    minScale: "4500",
    opacity: "0.6"
    
        });
  

        var mainMapLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://mapservices2.bexar.org/arcgis/rest/services/GecoVector/ACA_locations_test/MapServer");
        map.addLayers([transMapLayer, mainMapLayer]);
        
        var legend = new esri.dijit.Legend({
          map: map,
          layerInfos: [{layer:mainMapLayer,title:"ACA Enrollment Assistance"}],
          arrangement: esri.dijit.Legend.ALIGN_RIGHT
        },"legendDiv");
        legend.startup();
        
        map.on("click", identifyPOI);
        dojo.connect(grid, "onRowClick", onRowClickHandler);
      };
      
      function identifyPOI(evt){
        var identify = new esri.tasks.IdentifyTask("http://mapservices2.bexar.org/arcgis/rest/services/GecoVector/ACA_locations_test/MapServer");
        var identifyParams = new esri.tasks.IdentifyParameters();
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
        identifyParams.returnGeometry = true;
        identifyParams.tolerance = 3;
        
        map.infoWindow.clearFeatures();
        
        identify.execute(identifyParams, function(results){
          map.infoWindow.setFeatures(dojo.map(results, function(result){
            var feature = result.feature;
            feature.setInfoTemplate(new esri.InfoTemplate( "Name", "<tr>Name:<td>${Name}</tr></td><br><tr>Address:<td>${Address}</tr></td><br><tr>Zip:<td>${ZIP}</tr></td>"));
            return feature;
          }));
          map.infoWindow.show(evt.mapPoint);
        });
      };
      
      function doFind() {
        var findTask = new esri.tasks.FindTask("http://mapservices2.bexar.org/arcgis/rest/services/GecoVector/ACA_locations_test/MapServer");
        findParams = new esri.tasks.FindParameters();
        findParams.returnGeometry = true;
        findParams.layerIds = [0];
        findParams.searchFields = [ "Name", "Address", "ZIP"];
        findParams.outSpatialReference = map.spatialReference;
        findParams.searchText = dojo.byId("ownerName").value;
        findTask.execute(findParams,showResults);
      };

      function showResults(results) {
        map.graphics.clear();
        var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 25, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
        var items = dojo.map(results,function(result){
          var graphic = result.feature;
          graphic.setSymbol(symbol);
          map.graphics.add(graphic);
          return result.feature.attributes;
        });
        
        //Create data object to be used in store
        var data = {
          identifier: "OBJECTID",  //This field needs to have unique values
          label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
          items: items
        };

         //Create data store and bind to grid.
        var store = new dojo.data.ItemFileReadStore({ data:data });
        grid = dijit.byId('grid');
        grid.setStore(store);

        //Zoom back to the initial map extent
        map.centerAndZoom(center, zoom);
      }

      //Zoom to the parcel when the user clicks a row
      function onRowClickHandler(evt){
        var clickedTaxLotId = grid.getItem(evt.rowIndex).OBJECTID;
        var selectedTaxLot;
        var distance = 100;

        dojo.forEach(map.graphics.graphics,function(graphic){
          if((graphic.attributes) && graphic.attributes.OBJECTID === clickedTaxLotId){
            selectedTaxLot = graphic.geometry;
            return;
          }
        });
        var newExtent = new esri.geometry.Extent({
          "xmin": selectedTaxLot.x - distance,
          "ymin": selectedTaxLot.y - distance,
          "xmax": selectedTaxLot.x + distance,
          "ymax": selectedTaxLot.y + distance,
          "spatialReference": {
            "wkid": 102100
          }
        });
        map.setExtent(newExtent);
      };
      
      dojo.ready(init);
    </script>


Here is the error:
[ATTACH=CONFIG]29368[/ATTACH]

Any help or direction would be greatly appreciated!
0 Kudos
11 Replies
RobertHupp
Deactivated User
I'm trying to use a token for credentials in a proxy page page but I can't seem to get it to work. Does my service need to be https? Right now I'm using http.  It seems like a pretty easy task, I just can't get it to work.
0 Kudos
KevinMacLeod1
Frequent Contributor
I'm trying to use a token for credentials in a proxy page page but I can't seem to get it to work. Does my service need to be https? Right now I'm using http.  It seems like a pretty easy task, I just can't get it to work.


If memory serves right, Yes.  You must force it to use http.  I think it was some ArcGIS Server setting.  This is security by design if I remember correctly.

Security can be weird, though.  For me, for example, I get the Identiy Manager popup locally when running in Visual Studio and although it authenticates correctly and loads the layers in the map object the AGS JS TOC doesn't work.  Yet it works perfectly fine on our Amazon cloud which is also set to use proxies.  TOC looks fine.  Identity Manager never pops up. You'd never even know it was secured.  Only thing different is the token in the proxy of course.  Interesting.    Well I hope this helps and you get everything working.
0 Kudos