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.spring.navigator.SpringViewProvider;
|
12
|
import com.vaadin.ui.UI;
|
13
|
|
14
|
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
|
15
|
import eu.etaxonomy.cdm.vaadin.view.AuthenticationView;
|
16
|
|
17
|
/**
|
18
|
* @author c.mathew
|
19
|
* @since 2015
|
20
|
*
|
21
|
* @deprecated Use per View based authentication instead. This is provided by the {@link SpringViewProvider}.
|
22
|
*/
|
23
|
@Deprecated
|
24
|
public abstract class AbstractAuthenticatedUI extends CdmBaseUI {
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
*/
|
29
|
private static final long serialVersionUID = 1L;
|
30
|
|
31
|
Navigator navigator;
|
32
|
|
33
|
private static final String AUTHENTICATION_VIEW = "abstractAuthenticatedUI";
|
34
|
|
35
|
private boolean ignoreAuthentication = false;
|
36
|
|
37
|
private final static Logger logger =
|
38
|
Logger.getLogger(AbstractAuthenticatedUI.class.getName());
|
39
|
|
40
|
@Override
|
41
|
protected void init(VaadinRequest request) {
|
42
|
|
43
|
super.init(request);
|
44
|
// Create a navigator to control the views
|
45
|
navigator = new Navigator(this, this);
|
46
|
|
47
|
AuthenticationView av = new AuthenticationView();
|
48
|
navigator.addView(AUTHENTICATION_VIEW, av);
|
49
|
|
50
|
|
51
|
|
52
|
// Create and register the views
|
53
|
CdmVaadinAuthentication cvAuthentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
|
54
|
|
55
|
doInit(request);
|
56
|
URI uri = Page.getCurrent().getLocation();
|
57
|
String context = VaadinServlet.getCurrent().getServletContext().getContextPath();
|
58
|
if(ignoreAuthentication || (cvAuthentication != null && cvAuthentication.isAuthenticated(uri, context))) {
|
59
|
if(cvAuthentication != null) {
|
60
|
cvAuthentication.setSecurityContextAuthentication(uri, context);
|
61
|
}
|
62
|
UI.getCurrent().getNavigator().navigateTo(getFirstViewName());
|
63
|
} else {
|
64
|
UI.getCurrent().getNavigator().navigateTo(AUTHENTICATION_VIEW);
|
65
|
}
|
66
|
}
|
67
|
|
68
|
protected abstract void doInit(VaadinRequest request);
|
69
|
|
70
|
public abstract String getFirstViewName();
|
71
|
|
72
|
public void setIgnoreAuthentication(boolean ignoreAuthentication) {
|
73
|
this.ignoreAuthentication = ignoreAuthentication;
|
74
|
}
|
75
|
|
76
|
}
|