2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.view
;
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
;
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
;
25 import eu
.etaxonomy
.cdm
.service
.UserHelperAccess
;
26 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationEvent
;
27 import eu
.etaxonomy
.vaadin
.ui
.navigation
.NavigationManager
;
30 * A {@link SpringViewProvider.setAccessDeniedViewClass(Class<? extends View> accessDeniedViewClass) accessDeniedViewClass}
31 * 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>
32 * is needed. Therefore the <code>RedirectToLoginView</code> is a scoped prototype bean which always available. Using the 'singleton'
33 * scope should also work but is not a good idea for a login view.
34 * The <code>RedirectToLoginView</code> redirects the request to the LoginView which then is in a correctly
38 * @author a.kohlbecker
43 @Scope(ConfigurableBeanFactory
.SCOPE_PROTOTYPE
)
44 public class RedirectToLoginView
extends VerticalLayout
implements View
{
47 private static final long serialVersionUID
= -8763747518841365925L;
50 NavigationManager navigationManager
;
53 protected EventBus
.UIEventBus uiEventBus
;
55 public RedirectToLoginView() {
57 this.setWidth("100%");
58 Label header
= new Label("Access to this content is restricted");
59 header
.setStyleName(ValoTheme
.LABEL_FAILURE
);
60 header
.setWidthUndefined();
63 setComponentAlignment(header
, Alignment
.MIDDLE_CENTER
);
70 public void enter(ViewChangeEvent event
) {
72 if(!UserHelperAccess
.userHelper().userIsAutheticated()){
73 String currentState
= ((Navigator
)navigationManager
).getState();
74 // redirect to the login view and pass over the current state
75 uiEventBus
.publish(this, new NavigationEvent(LoginViewBean
.NAME
, currentState
));