views:

230

answers:

2

I'm writing a Swing application client (it's runs over webstart, and I'm using glassfish). In the application class I have:

@EJB private static MyBean myBean;

and in MyBean I have:

@Remote
public interface MyBean {
  public int getRand();
}

@DeclareRoles(("admin"))
@Stateful(name="MyBean")
public class MyBeanImpl implements MyBean {
  @RolesAllowed(("admin"))
  public int getRand() {
    return 9; // Guaranteed to be random
  }
}

So far so good. I start the app using javaws http://server/app/app-client, it asks for user/pass and authenticates properly (using the fileRealm from glassfish).

I have two problems:

  • It seems to try to authenticate right away (when the bean is referenced) rather than when I try to call the method. I can live with this.
  • I want to use my own login dialog. Partly for aesthetic reasons, but also for graceful error handling, retries, etc

So I need to specify a callback. Using new LoginContext("fileRealm", myCallback) I get an error about no login modules for fileRealm. I've tried various mixtures of examples from the net, but very few are designed to application clients.

A: 

It seems to try to authenticate right away (when the bean is referenced) rather than when I try to call the method. I can live with this.

This is because it needs to be authenticated to create an RMI context.

rodrigoap
It's nice to have an explanation, but I desperately need to know how to get my own dialog to appear.
Draemon
+2  A: 

Well I've solved the second (and most important issue) by Adding the following to application-client.xml:

<application-client...>
  ...
  <callback-handler>package.name.ClassName</callback-handler>
</application-client>
Draemon
Ok that's stupid - I can't accept my own answer
Draemon
After reading http://meta.stackoverflow.com/questions/1413/why-an-answer-cant-be-accepted-after-an-unresolved-bounty/36904#36904, +1 to push your answer and feedback to the top ;)
VonC
Hehe, Thanks VonC!
Draemon