Hi Carmen,
thanks for your suggestion. I've tried with your crossdomain.xml idea but with this code nothing works... I use flash 10 with flex 3.5.
I think the problem is in the api, because the generated token works properly if I insert it in the mxml tag and in actionscript normally after it generation (in 2nd time) but if I generate the token on the fly and I add the new token generated return token is invalid (viewed with firebugs).
Others idea?? Thank you 4 all
Hi everybody,I've found the problem. I don't know why but I explain you my solution to the problem.My configuration is ArcGis Server 9.3.1 SP1 Java version with token authentication on ldap server.Like the code posted above, when I have founded a token I made an alert. In the debug mode I've seen the same string. And my focus wasn't on the token string. This is my big mistake...To solve the problem with this error code {"error":{"code":498,"message":"Invalid token","details":[]}} I've added a simple trim function before set the theToken variable:
theToken = StringUtil.trim(event.result.toString()); and now work all okSee my test code:<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:esri="http://www.esri.com/2008/ags"
pageTitle="Example - ArcGIS API for Flex connecting to a dynamic secured AGS service"
initialize="init()">
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
import flash.utils.setTimeout;
import mx.binding.utils.BindingUtils;
import mx.rpc.http.HTTPService;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
private var theToken:String;
private function init():void {
var unsecuredBaseMap:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://******/arcgis/rest/services/*****/MapServer");
map.addLayer(unsecuredBaseMap);
RequestToken('ldapUser','ldapPassword');
}
public function RequestToken(username:String, password:String):void {
var http:HTTPService = new HTTPService();
// register event handlers (resultHandler and faultHandler functions)
http.addEventListener( ResultEvent.RESULT, tokenResultHandler );
http.addEventListener( FaultEvent.FAULT, faultHandler );
http.url = "http://******/arcgis/tokens?request=gettoken&username="+ username +"&password="+ password +"&clientid=ref.http://******.ti.ch&expiration=1440";
http.method = "GET";
http.resultFormat = "text";
http.send();
function faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.toString());
}
function tokenResultHandler(event:ResultEvent):void
{
theToken = StringUtil.trim(event.result.toString());
caricaLayerProtetti();
}
}
private function caricaLayerProtetti():void {
var protectedMap1:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://******/arcgis/rest/services/*****/MapServer");
protectedMap1.token = theToken;
map.addLayer(protectedMap1);
var protectedMap2:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://******/arcgis/rest/services/*****/MapServer");
protectedMap2.token = theToken;
map.addLayer(protectedMap2);
}
]]>
</mx:Script>
<mx:Label text="Java" fontSize="14"/>
<esri:Map id="map" />
</mx:Application>