Project

General

Profile

Download (1.5 KB) Statistics
| Branch: | Tag: | Revision:
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 UI {
16

    
17
	Navigator navigator;
18
	
19
	private static final String AUTHENTICATION_VIEW = "abstractAuthenticatedUI";
20

    
21
	private final static Logger logger =
22
			Logger.getLogger(AbstractAuthenticatedUI.class.getName());
23

    
24
	@Override
25
	protected void init(VaadinRequest request) {		
26
        
27
        // Create a navigator to control the views
28
        navigator = new Navigator(this, this);
29
        
30
        AuthenticationView av = new AuthenticationView();
31
        navigator.addView(AUTHENTICATION_VIEW, av);
32
        
33
        
34
        new AuthenticationPresenter(av);
35
        // Create and register the views
36
        Authentication authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication");			
37
        
38
        doInit();
39
        
40
        if(authentication != null && authentication.isAuthenticated()) {
41
        	UI.getCurrent().getNavigator().navigateTo(getFirstViewName());
42
        } else {
43
        	UI.getCurrent().getNavigator().navigateTo(AUTHENTICATION_VIEW);
44
        }
45
	}
46
	
47
	protected abstract void doInit();
48
	
49
	public abstract String getFirstViewName();
50

    
51
}
    (1-1/1)