2 Replies Latest reply on May 21, 2012 3:10 AM by Hunternif

    HTTPService redirect

    bldrbldr
      I'm trying to use J2EE Servlet form based authentication by posting to the well-known url j_security_check. In my web.xml file I specify FORM authentication and my custom Flex login page. Upon accessing a protected resource, I am redirected to my login page as expected. Upon successful login the server sends an HTTP redirect back to the protected resource, but I can't figure out how to capture this redirect. My fault method will get called if I use the wrong password, however the result method does not get called, probably because it is a redirect. The server is actually authenticating the user, because if I access the protected resource again in the same session it works fine.

      How can I get the HTTPService to follow a redirect, or at least how can I get notification that the call has completed?

      I'm using Tomcat in JBoss and the following code demonstrates the problem, even without configuring web.xml.

      Thanks,
      Brian



      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      horizontalScrollPolicy="off"
      verticalScrollPolicy="off"
      defaultButton="{login}"
      >

      <mx:Script>
      <![CDATA[
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;
      private function onResult(event:ResultEvent):void {
      // Never reached
      trace(event);
      }
      private function onFault(event:FaultEvent):void {
      // Called after unsuccessful login
      trace(event);
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="loginService" url="j_security_check" method="POST" result="onResult(event)" fault="onFault(event)">
      <mx:request>
      <j_username>{username.text}</j_username>
      <j_password>{password.text}</j_password>
      </mx:request>
      </mx:HTTPService>

      <mx:Panel id="panel" title="Login">

      <mx:Form id="form">
      <mx:Label id="directions" text="Please Login:"/>
      <mx:FormItem label="Username">
      <mx:TextInput id="username"/>
      </mx:FormItem>
      <mx:FormItem label="Password">
      <mx:TextInput id="password" displayAsPassword="true"/>
      </mx:FormItem>

      <mx:FormItem id="passwordConfirmItem" label="Confirm:" visible="false">
      <mx:TextInput id="passwordConfirm" displayAsPassword="true"/>
      </mx:FormItem>
      </mx:Form>
      <mx:ControlBar>
      <mx:Spacer width="100%" id="spacer1"/>
      <mx:Button label="Login" id="login" click="loginService.send();"/>
      </mx:ControlBar>

      </mx:Panel>

      </mx:Application>