1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.security.access.AccessDeniedException;
24
25 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
26 import com.vaadin.server.ErrorEvent;
27 import com.vaadin.server.ErrorHandler;
28 import com.vaadin.ui.Notification;
29 import com.vaadin.ui.UI;
30
31
32
33
34 public final class UiInstanceErrorHandler implements ErrorHandler {
35
36
37 private static final long serialVersionUID = 1L;
38
39
40 private static final String LOG_WARN_VAADIN_ERROR = "Vaadin error";
41
42
43 private static final Logger LOGGER = LoggerFactory.getLogger(UiInstanceErrorHandler.class);
44
45
46 private final UI ui;
47
48
49
50
51
52
53
54 public UiInstanceErrorHandler(final UI ui) {
55 super();
56 this.ui = ui;
57 }
58
59 @Override
60 public void error(final ErrorEvent event) {
61 if (event.getThrowable() instanceof AccessDeniedException) {
62 final AccessDeniedException accessDeniedException = (AccessDeniedException) event.getThrowable();
63 Notification.show(accessDeniedException.getMessage(), Notification.Type.ERROR_MESSAGE);
64 ui.getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
65 return;
66 } else if (event.getThrowable().getCause() != null && event.getThrowable().getCause().getCause() != null
67 && event.getThrowable().getCause().getCause().getCause() instanceof AccessDeniedException) {
68 final AccessDeniedException accessDeniedException = (AccessDeniedException) event.getThrowable().getCause()
69 .getCause().getCause();
70 Notification.show(accessDeniedException.getMessage(), Notification.Type.ERROR_MESSAGE);
71 ui.getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
72 return;
73 } else {
74 LOGGER.warn(LOG_WARN_VAADIN_ERROR, event.getThrowable());
75 }
76 }
77
78 }