Select to view content in your preferred language

Change in identity manager between 2.5 and 2.6

2923
45
Jump to solution
01-31-2012 07:22 AM
JeffPace
MVP Alum
My identity manager works at 2.5.  I don't have any custom code in it at the moment, it just hits the first secure service and prompts for login (AWESOME THANK YOU)

when I change my application to 2.6, firebug throws and error saying

tokenserviceurl not defined

and hangs login.

What changed?
0 Kudos
45 Replies
JeffPace
MVP Alum
Are you running the code posted previously at the top of your function that dojo.ready calls?


not using dojo.ready, but i found it.  I was using the old dojo.addonload (now deprecated) command.

It works (meaning it doesnt through security errors) however it breaks other parts of my application, specifically when i load layers that are NOT https/token based.
0 Kudos
JeffPace
MVP Alum
Ok i think i got it but it is a bit kludgy.  It seems as though it works as long as there is a secure service loaded somewhere.  If not, it fails

Since i load my layers based on config parameters (in the url) there isnt always a secure service.  I just had to trap to make sure that dojo.ready function is only called if the site is being accessed securely, seems to work ok.
0 Kudos
derekswingley1
Frequent Contributor II
Not sure how much I can help with that...maybe use an additional query string parameter indicating if there are secure services and check that before defining the serverInfo?

Just as an FYI, dojo.ready and dojo.addOnLoad are the same thing:  http://bugs.dojotoolkit.org/browser/dojo/tags/release-1.6.1/dojo/_base/_loader/loader.js#L202
0 Kudos
JeffPace
MVP Alum
Yes if we use secure services, the entire app is accessed over https.  So for now I am just checking the protocol for https. If it it is i load the serverinfos. Seems to work.

Would still be nice to have an "onSuccessfulIdentity" type event to listen for.  I am running into more and more circumstances where  I need to fire code if a login is successful, and different code if login fails.

Thanks for the help getting this up and running.
0 Kudos
JeffPace
MVP Alum
Did this change again with 2.7 or 2.8? I had to roll back to 2.6 .
0 Kudos
derekswingley1
Frequent Contributor II
Hi Jeff,

Can you recap where you're at with this issue?
0 Kudos
JeffPace
MVP Alum
Let me 'splain.
[pause]
No, there is too much. Let me sum up.


Ok so we are using a highly modified version of the JSViewer sample from many moons ago, accessing Local GIS Server services from multiple servers, one that is secured using tokens (arcgis server 10sp4 for JAVA).

We access these services twice.  Once for the mapLayer, Once directly to the legend for a TOC icon. 

The application is deployed as a war file on tomcat, all services, application, and locally hosted API accessed via a WebApp Firewall (modproxy) to avoid cross-domain issues.

On upgrading from 2.5 to 2.6, i had to add to my index.jsp
         function initSecurity() {
                    // Comment out these lines, and the onresize on body
                    // if you don't want full-screen
                    var serverInfo = new esri.ServerInfo();
                        serverInfo.server = 'https://www.mymanatee.org';
                        serverInfo.tokenServiceUrl = 'https://www.mymanatee.org/arcgis/tokens/generateToken';
                        esri.id.registerServers([serverInfo]);

                };
 if(document.location.protocol==="https:"){
                    dojo.addOnLoad(initSecurity);
                }


for the services, and then for the TOC add
var params = {
                 url:urls+"/legend",
                        layerName:layerNames,
                        content:{f:"json"},
                 handleAs: "json",
                 sync: true,
                 load: dojo.hitch(this, "onLegendLoad"),
                 error: dojo.hitch(this, "onLegendError")
             };
                     if(document.location.protocol==="https:"){
   if(esri.id.credentials.length>0){
                            params.content["token"]=esri.id.credentials[0].token;
   }
                    }

which allows me to add the token to the url call for the legend json.

This worked upgrading from 2.5 to 2.6 (it was not necessary at 2.5 as the token server was guessed)

however it seems to be broken at 2.7/2.8 resulting in an uninitialized variable for me.  Simply changing back to 2.6 gets rid of the error

The onLegendLoad function
     onLegendLoad: function(response, ioArgs) {
                var minScale=591657527.591555;
                var maxScale=0;
                if(!this.tocScales[ioArgs.args.layerName]){
                      this.tocScales[ioArgs.args.layerName]={response:response, ioArgs:ioArgs};
                }
                dojo.forEach(response.layers, dojo.hitch(this,function(layer){
                    dojo.forEach(layer.legend, dojo.hitch(this, function(legend){
                        var legendUrl=    legend.url;
                        if(legendUrl.length<10){
                        legend.url =  ioArgs.url.replace("legend?f=json&token=",layer.layerId+"/images/"+legendUrl+".png?token=");
                        legend.url =  ioArgs.url.replace("legend?f=json",layer.layerId+"/images/"+legendUrl+".png");
                        }
                        minScale=layer.minScale;
                        maxScale=layer.maxScale;
                        if(minScale==0){
                            minScale=591657527.591555;
                        }
                        if((minScale==0&&maxScale<=1)||(this.currentScale>maxScale&&this.currentScale<minScale)){
                            layer.scaleVisible=true;
                        }else{
                           layer.scaleVisible=false;
                        }
                    }))                    
                }))
         this.layersInfoLegend.push(response.layers);              
     },

Does two things, it loops through every service and every sublayer, and grabs the legend icon.  This is where the token needed to be appended for the secure services
It also checks the scale dependency of the service to color code the TOC entry to show scale dependent visibility.

Of course there are alot of other functions involved, but these are the only two that address security. The version of my site (by config file) that does not access any secure layers (http only) throws no errors and works perfectly at 2.8
0 Kudos
JeffPace
MVP Alum
I got this fixed, i think i got bitten by the asynchronous nature of javascript. 

For some reason at 2.6 it worked fine, changing to 2.7 or 2.8 cause a variable i was using to be called before it was set, but only when i used the identitymanager.  Trapping for undefined/null allows me to proceed without the error. 

sorry for the false alarm, i am still baffled as to what changed.
0 Kudos
derekswingley1
Frequent Contributor II
So you're all good now?
0 Kudos
JeffPace
MVP Alum
Yes I am good, for now, mostly.

OF course I am nervous that at 2.9 (and changing to dojo 1.7+) alot of these workarounds will need tweaking, and my biggest concern is the lack of documentation on them.

For example, in the work around, we do

esri.id.registerServers([serverInfo]);

but where is esri.id documented? I am guessing based on the registerServers command that it is related to esri.IdentityManagerBase, but i never created an "id" object, so how am i setting it?
0 Kudos