Authentication question

Hello,

Has anybody experience with the authentication example on this site?

http://vaadin.com/wiki/-/wiki/Main/Authenticating%20Vaadin-based%20applications/

When I try to authenticate, an error occurs on on the part:

When debugging the part it seams that the follwing line goes wrong:

It seams that
SMSApp.getInstance()
returns
null
.

Has anybody a clue what happens? Is this example still valid? What

Regards,

Mike

The example is quite old, and there is a note at the beginning about things that should be done differently:

Nevertheless, I believe it should work. Check your TransactionListener (or HttpServletRequestListener) - if your application implements one, it should be called automatically if I remember correctly. Check that the listener is actually called, and sets the thread local variable.

There are also other libraries or frameworks on top of Vaadin that handle authentication, including e.g.
AppFoundation
.

Hello Henri,

Is it possible to describe a common usefull login example on vaadin.com? The example that’s published is corrupt, outdated (it dows not work), and the appfoundation.jar do not provide a full example. I should like to see a correct example. A login is a common example that everybody wants.

Regards,

Mike

Have you looked at the
documentation
(given, doesn’t contain a code example, but explains the process) and the
example application
?

Hello Kim,

I studied the example meanwhile. When you try to use it by the refered example application, it requires to use the FacadeFactory. And that example has not been described. It looks to me that the several discussions longer then writing a proper tutorial. It is not working yet. I tried several things. Personally I think this part should be documented at examples. It is a must have feature (FacadeFactory and authentication).

Mike

Hi Mike.

I implemented the code in the article you linked into an application myself about two months ago and noticed that the code did not even compile. I tried to fix all the errors in the article but I clearly missed something. Looking at it, I guess it could work if you add setCurrent(this); as the first row of the application’s init -method. Please test it out and report back here, so that I can update the article accordingly.

As the comment says at the beginning of the article (added by me :)), HTTPServletRequestListener should be quicker and leaner. Here is about what you need to implement it into your applicaiton

public class MyApplication extends Application implements HTTPServletRequestListener
  private static ThreadLocal<MyApplication> currentApplication = new ThreadLocal<MyApplication>();

 @Override
  public void init() {
    set(this);
    ...
  }

  /**
   * @return the current application instance
   */
  public static MyApplication get() {
    return currentApplication.get();
  }

  /**
   * Set the current application instance
   */
  public static void set(MyApplication application) {
    if (get() == null) {
      currentApplication.set(application);
    }
  }  

  @Override
  public void onRequestStart(HttpServletRequest request, HttpServletResponse response) {
    currentApplication.set(this);
  }

  @Override
  public void onRequestEnd(HttpServletRequest request, HttpServletResponse response) {
    currentApplication.set(null);
  }

The documentation for using the FacadeFactory (and the persistence module in general) can be found
here
. The live demo doesn’t yet have the persistence module described, as it is still a work-in-progress.

If you want to use Java EE 6, here’s one I wrote (the video in the blog is no longer available, but it’s not necessary to understand the example):


http://blogs.sun.com/bobby/entry/authentication_without_the_form

Otherwise, just use form-based login and have users log in before getting to the Vaadin application. Personally, I like the idea of not using form-based auth.

Cheers,
Bobby