Skip to main content
Participant
March 5, 2008
Question

How to *reset* credentials with Consumer?

  • March 5, 2008
  • 11 replies
  • 29724 views
Hi,

I've been trying authentication on BlazeDS and Tomcat using "flex.messaging.security.TomcatValve".

I succeeded authentication only *once*.

I thought things goes like this,
-----
1. Consumer#setCredentials("user1", "pass1")
2. Do something.
3. Consumer#logout()
4. Consumer#setCredentials("user2", "pass2") // Relogin as different user.
5...
-----

But at "4", error occured bellow
-----
Error: Credentials cannot be set while authenticating or logging out.
at mx.messaging::Channel/setCredentials()
at mx.messaging::ChannelSet/setCredentials()
at mx.messaging::MessageAgent/setCredentials()
-----

Then I tried *without* calling Consumer#logout(), other error occured.
-----
Error: Credentials cannot be set when already authenticated. Logout must be performed before changing credentials.
at mx.messaging::Channel/setCredentials()
at mx.messaging::ChannelSet/setCredentials()
at mx.messaging::MessageAgent/setCredentials()
-----

It's completely opposite.
So how should I do?
I'm not good at Enlish but hope make sense.

Thank you.
    This topic has been closed for replies.

    11 replies

    March 10, 2008
    Hi Yoshiyuki,

    You are calling Consumer.setCredentials("user2", "pass2") before Consumer.logout successfully completes. The real problem is though there is no way to know when Consumer.logout has completed. (Consumer.logout is legacy code and it does not work that well.)

    I suggest you use ChannelSet.logout instead. ChannelSet.logout returns an AsyncToken that you can attach result and fault responders to. When ChannelSet.logout returns successfully, you can call Consumer.setCredentials from the result responder.

    I haven't compiled this but it should be something like this:

    var token:AsyncToken = consumer.channelSet.logout();
    token.addResponders(new AsyncResponder(
    function (result:Object, token:Object=null):void
    {
    consumer.setCredentials("user2","pass2")
    },
    function (error:Object, token:Object=null):void
    {
    // Error handling here.
    }));