1
|
package eu.etaxonomy.cdm.vaadin.ui;
|
2
|
|
3
|
import java.util.logging.Logger;
|
4
|
|
5
|
import org.springframework.security.core.Authentication;
|
6
|
|
7
|
import com.vaadin.navigator.Navigator;
|
8
|
import com.vaadin.server.VaadinRequest;
|
9
|
import com.vaadin.server.VaadinSession;
|
10
|
import com.vaadin.ui.UI;
|
11
|
|
12
|
import eu.etaxonomy.cdm.vaadin.presenter.AuthenticationPresenter;
|
13
|
import eu.etaxonomy.cdm.vaadin.view.AuthenticationView;
|
14
|
|
15
|
public abstract class AbstractAuthenticatedUI extends CdmBaseUI {
|
16
|
|
17
|
/**
|
18
|
*
|
19
|
*/
|
20
|
private static final long serialVersionUID = 1L;
|
21
|
|
22
|
Navigator navigator;
|
23
|
|
24
|
private static final String AUTHENTICATION_VIEW = "abstractAuthenticatedUI";
|
25
|
|
26
|
private boolean ignoreAuthentication = false;
|
27
|
|
28
|
private final static Logger logger =
|
29
|
Logger.getLogger(AbstractAuthenticatedUI.class.getName());
|
30
|
|
31
|
@Override
|
32
|
protected void init(VaadinRequest request) {
|
33
|
|
34
|
super.init(request);
|
35
|
// Create a navigator to control the views
|
36
|
navigator = new Navigator(this, this);
|
37
|
|
38
|
AuthenticationView av = new AuthenticationView();
|
39
|
navigator.addView(AUTHENTICATION_VIEW, av);
|
40
|
|
41
|
|
42
|
new AuthenticationPresenter(av);
|
43
|
// Create and register the views
|
44
|
Authentication authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");
|
45
|
|
46
|
doInit(request);
|
47
|
|
48
|
if(ignoreAuthentication || (authentication != null && authentication.isAuthenticated())) {
|
49
|
UI.getCurrent().getNavigator().navigateTo(getFirstViewName());
|
50
|
} else {
|
51
|
UI.getCurrent().getNavigator().navigateTo(AUTHENTICATION_VIEW);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
protected abstract void doInit(VaadinRequest request);
|
56
|
|
57
|
public abstract String getFirstViewName();
|
58
|
|
59
|
public void setIgnoreAuthentication(boolean ignoreAuthentication) {
|
60
|
this.ignoreAuthentication = ignoreAuthentication;
|
61
|
}
|
62
|
|
63
|
}
|