users@glassfish.java.net

Re: My own GUI Login Dialog

From: Miroslav Nachev <miro_at_space-comm.com>
Date: Tue, 08 May 2007 18:31:59 +0300

Hi,

I haven't any exceptions like yours. But I separate the CallbackHandler
and Swing LoginDialog because it is not possible and correct both to be
in as one class.

> By the way: right now, when user enter incorrect uid/password,
> application crashes. Does anyone know how to avoid that? I would like
> to display some window with "incorrect login, try again". Any ideas?
This is very interesting idea and now I am looking how to do that. In my
opinion this is not possible, because the error for wrong password or
username is not returned from the GlassFish AS. Maybe this must be done
with catching the exception, but how to inform the client that must show
some window which is not expected?


Regards,
Miro.

Witold Szczerba wrote:
> Hi,
> just yesterday, I was investigating how to create my own login panel.
> I suppose you are talking about Swing application in ACC?
> If so, you must know, that providing custom class does not work for
> Glasfish v1. The issue was fixed, when Glassfish team abandoned V1 :/
> The good news is that newest V2 builds should be stable enough to
> switch.
>
> Here is how does my custom CallbackHandler look like:
>
> public class CallbackHandler
> implements javax.security.auth.callback.CallbackHandler {
>
> /** Creates a new instance of CallbackHandler */
> public CallbackHandler() {
> }
>
> public synchronized void handle(Callback[] callbacks)
> throws IOException, UnsupportedCallbackException {
>
> LoginWindow loginWindow = new LoginWindow(this);
> try {
> this.wait();
> String username = loginWindow.getUsername();
> char[] password = loginWindow.getPassword();
> loginWindow.dispose();
> loginWindow = null;
> for (Callback callback : callbacks) {
> if (callback instanceof NameCallback)
> ((NameCallback)callback).setName(username);
> else if (callback instanceof PasswordCallback)
> ((PasswordCallback)callback).setPassword(password);
> }
> } catch (InterruptedException ex) {
> ex.printStackTrace();
> }
> }
>
> }
>
> At first try, I implemented CallbackHandler as a JFrame. I have no
> idea why, but when CallbackHandler was a JFrame, my application
> couldn't start... Actually it was starting, but I got millions of
> exceptions; can't remember what that was exactly, but it was
> complaining about some ComponentUI that could not be
> registered/initialized/loaded/something like that. It was happening
> after successful authorization, just before GUI was about to show up.
> Any ideas why that was happening?
>
> I implemented my login frame as separate object. It looks +/- like
> that...
> it was generated using Matisse, so it is actually veeery long, here is
> the outline:
>
> public class LoginWindow
> extends JFrame implements Runnable {
>
> private final Object lock;
>
> public LoginWindow(Object lock) {
> this.lock = lock;
> EventQueue.invokeLater(this);
> }
> public void run() {
> initComponents();
> }
> public String getUsername() {
> return usernameField.getText().trim();
> }
> public char[] getPassword() {
> return passwordField.getPassword();
> }
> private void okActionPerformed(java.awt.event.ActionEvent evt) {
> synchronized (lock) {
> lock.notifyAll();
> }
> }
>
> ......rest of the class.....
> }
>
> I must confess, that LoginWindow + CallbackHandler was my first
> attempt, when I used methods object.wait() and object.notifyAll(). I
> am actually not sure it it is done as it should be, but it works.
> I would be happy receiving some advices, if it can be done better :)
>
> You said, Miroslav, you would like to implement additional
> functionality, like an option to add new user. I am not sure how you
> could implement this, I suppose there is no way of using @EJB
> injection before Main classes loads. I think, if you would like to get
> explicit access to session beans, you would have to do it using
> InitialContext and lookup.
>
> By the way: right now, when user enter incorrect uid/password,
> application crashes. Does anyone know how to avoid that? I would like
> to display some window with "incorrect login, try again". Any ideas?
>
> -josh
>
>
>
> 2007/5/7, Miroslav Nachev <miro_at_space-comm.com>:
>> Hi,
>>
>> How can I configure GlassFish to use my own GUILoginDialog instead to
>> the embedded. My idea to use my own Login Dialog is because I would like
>> to add the following features to the existing one:
>> 1. Registration of new user;
>> 2. Banner/Logo image.
>>
>> Any idea how can I do that or suggestions?
>>
>> Thank you in advance.
>>
>>
>> Regards,
>> Miro.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>