Guice + Shiro + Vaadin. Annotations don't work

So I am gluing the frameworks together, it’s almost working.
Using the Apache Shiro annotations works in the main Vaadin application class. For example @RequiresAuthentification.
How do I get this to work inside another Window or CustomComponent?

This is working as expected - the annotation will prevent from executing the method call:

public class MyApplicationextends Application
@Override
public void init() {
          this.setMainWindow(new Window());
          getMainWindow().setContent(new LoginView());
          //this will throw a security exception 
          //because we are not authentificated
          testAuth();
}
   
@RequiresAuthentification
public void testAuth() {
          // some code
}

How do I get the annotations to work inside CustomComponents? The testAuth() method is executed, the Shiro annotation is ignored and the
String test
is not injected.


public class LoginView extends CustomComponent {
        //PROBLEM - this string will not get injected
        @Inject @Named("testString") String test;       

       public LoginView() {
              //PROBLEM HAPPENS HERE -> this method will be called and the "RequiresAuthentification" is ignored
             testAuth();
       }

       @RequiresAuthentification
       public void testAuth() {
           // some code
        } 
}

These annotations require Guice and AOP. So the problem is probably that I am creating the CustomComponent with the
new
keyword (setContent(new LoginView())).
How else can I create the LoginView or any other custom component so that Guice injection and Shiro annotation will work?

A little update, I have found one way get guice working inside login window.
But the annotations are still ignored :frowning:


public class MyApplication extends Application {
   protected final Provider<LoginWindow> loginWindowProvider;

	@Override
	public void init() {
		
		this.setMainWindow(new Window());
		getMainWindow().setContent([b]
this.loginWindowProvider.get()
[/b]);
	}

	@Inject
	public RigipsApplication(Provider<LoginWindow> loginWindowProvider) {
		this.loginWindowProvider = loginWindowProvider;
	}
}

Ok, there must be some more fundamental problem. Can someone please help me out? Guice injection doesn’t work at all in my classes that extend CustomComponent. But it works in other classes…

public class VaadinGuiceApplication extends Application {
	@Inject TestComponent testComponent;

	@Override
	public void init() {
		getMainWindow().setContent(testComponent);
	}

}
public class TestComponent extends CustomComponent {

     @Inject TestService testService;

     public TestComponent() {
          //[b]
THIS FAILS - testService is null
[/b]. Why? It's registered in Guice injector.
          testService.someMethod();
     }

}

Constructor injection does work. But I need field injection. AOP doesn’t work with just constructor injection…

Edit: I have found only a work-around for this. I can inject services to the custom components with constructor injection. These services have Shiro annotations and these work. So I can check Shiro permissions/roles in CustomComponents in code and use annotations inside services…

I haven’t tried Guice with Vaadin yet but perhaps you should read up on GIN: http://code.google.com/p/google-gin/