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?