SessionHandler.java
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package fi.codecrew.moya.terminal.handler;
import java.util.TimeZone;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.clientutils.BortalLocalContextHolder;
import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.model.EventUser;
@Named()
@RequestScoped
public class SessionHandler {
private static final Logger logger = LoggerFactory
.getLogger(SessionHandler.class);
// @Inject
// private HttpServletRequest httprequest;
// @EJB
// private RoleBeanLocal rolebean;
@EJB
private EventBeanLocal eventbean;
@EJB
private PermissionBeanLocal permbean;
public TimeZone getTimezone() {
return TimeZone.getTimeZone("Europe/Helsinki");
}
public String getLocale() {
// TODO: Locale selection code missing
// return "en_ST_v7";
// return "fi_IN_XIII";
return "fi_FI";
}
public String getLayout() {
// TODO: layout selection code missing!!
// return "stream1";
// return "insomnia2";
return "default";
}
public String getDateFormat() {
return "dd.MM.yyyy";
}
public String getDatetimeFormat() {
return "dd.MM.yyyy HH:mm";
}
public boolean hasPermission(IAppPermission permission) {
if (permission == null) {
logger.warn("permission is null");
throw new RuntimeException("Empty target or permission!");
}
boolean ret = permbean.hasPermission(permission);
return ret;
}
public boolean isLoggedIn() {
boolean ret = permbean.isLoggedIn();
return ret;
}
public boolean isSuperadmin() {
return permbean.getCurrentUser().getUser().isSuperadmin();
}
public EventUser getCurrentUser() {
return permbean.getCurrentUser();
}
public String flushCache() {
return eventbean.flushCache();
}
private String preurlString = null;
public String getRequestPreUrl() {
if (preurlString == null) {
Object ext = FacesContext.getCurrentInstance().getExternalContext()
.getRequest();
if (ext instanceof HttpServletRequest) {
StringBuffer url = ((HttpServletRequest) ext).getRequestURL();
preurlString = url.substring(0, url.indexOf("/", 8));
} else {
preurlString = "";
}
}
return preurlString;
}
public boolean isInDevelopmentMode() {
return BortalLocalContextHolder.isInDevelopmentMode();
}
}