1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view;
|
10
|
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
13
|
import org.springframework.context.annotation.Scope;
|
14
|
import org.vaadin.spring.events.EventBus;
|
15
|
|
16
|
import com.vaadin.navigator.Navigator;
|
17
|
import com.vaadin.navigator.View;
|
18
|
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
|
19
|
import com.vaadin.spring.annotation.SpringComponent;
|
20
|
import com.vaadin.ui.Alignment;
|
21
|
import com.vaadin.ui.Label;
|
22
|
import com.vaadin.ui.VerticalLayout;
|
23
|
import com.vaadin.ui.themes.ValoTheme;
|
24
|
|
25
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
|
26
|
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager;
|
27
|
|
28
|
/**
|
29
|
* A {@link SpringViewProvider.setAccessDeniedViewClass(Class<? extends View> accessDeniedViewClass) accessDeniedViewClass}
|
30
|
* can not be a view- or UI-scoped bean, since the view context is not set up at the time when the <code>accessDeniedViewClass</code>
|
31
|
* is needed. Therefore the <code>RedirectToLoginView</code> is a scoped prototype bean which always available. Using the 'singleton'
|
32
|
* scope should also work but is not a good idea for a login view.
|
33
|
* The <code>RedirectToLoginView</code> redirects the request to the LoginView which then is in a correctly
|
34
|
* set up view scope.
|
35
|
|
36
|
*
|
37
|
* @author a.kohlbecker
|
38
|
* @since Jul 13, 2017
|
39
|
*
|
40
|
*/
|
41
|
@SpringComponent
|
42
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
43
|
public class RedirectToLoginView extends VerticalLayout implements View {
|
44
|
|
45
|
|
46
|
private static final long serialVersionUID = -8763747518841365925L;
|
47
|
|
48
|
@Autowired
|
49
|
NavigationManager navigationManager;
|
50
|
|
51
|
@Autowired
|
52
|
protected EventBus.UIEventBus uiEventBus;
|
53
|
|
54
|
public RedirectToLoginView() {
|
55
|
|
56
|
this.setWidth("100%");
|
57
|
Label header = new Label("Access denied");
|
58
|
header.setStyleName(ValoTheme.BUTTON_LARGE);
|
59
|
header.setWidthUndefined();
|
60
|
|
61
|
addComponent(header);
|
62
|
setComponentAlignment(header, Alignment.MIDDLE_CENTER);
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* {@inheritDoc}
|
67
|
*/
|
68
|
@Override
|
69
|
public void enter(ViewChangeEvent event) {
|
70
|
|
71
|
String currentState = ((Navigator)navigationManager).getState();
|
72
|
// redirect to the login view and pass over the current state
|
73
|
uiEventBus.publish(this, new NavigationEvent(LoginViewBean.NAME, currentState));
|
74
|
}
|
75
|
|
76
|
}
|