Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Guice + Shiro + Vaadin. Annotations don't work

Daniel Novak
10 years ago Apr 12, 2012 6:10pm

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?

Last updated on Apr, 12th 2012
Daniel Novak
10 years ago Apr 12, 2012 9:56pm
Daniel Novak
9 years ago Apr 18, 2012 6:08pm
Bart Van Remortele
9 years ago Apr 19, 2012 7:56am