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