1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.platform.gadget.services.LoginHistory;
18
19 import java.util.List;
20 import java.util.Set;
21
22 import org.exoplatform.container.xml.InitParams;
23 import org.exoplatform.platform.gadget.services.LoginHistory.storage.LoginHistoryStorage;
24
25
26
27
28
29
30 public class LoginHistoryServiceImpl implements LoginHistoryService {
31 private boolean enableLoginHistory = true;
32
33 private LoginHistoryStorage loginHistoryStorage;
34
35 public LoginHistoryServiceImpl(LoginHistoryStorage loginHistoryStorage, InitParams params) {
36 this.loginHistoryStorage = loginHistoryStorage;
37 if (params != null && params.containsKey(EXO_AUDIT_LOGIN_ENABLED)) {
38 String enableLoginHistoryString = params.getValueParam(EXO_AUDIT_LOGIN_ENABLED).getValue();
39 enableLoginHistory = enableLoginHistoryString.equalsIgnoreCase("true");
40 }
41 }
42
43
44
45
46 public long getLastLogin(String userId) throws Exception {
47 return loginHistoryStorage.getLastLogin(userId);
48 }
49
50
51
52
53
54
55
56
57 public List<LastLoginBean> getLastLogins(int numItems, String userIdFilter) throws Exception {
58 return loginHistoryStorage.getLastLogins(numItems, userIdFilter);
59 }
60
61
62
63
64
65
66
67
68 public void addLoginHistoryEntry(String userId, long loginTime) throws Exception {
69 loginHistoryStorage.addLoginHistoryEntry(userId, loginTime);
70 }
71
72
73
74
75
76
77
78
79
80 public List<LoginHistoryBean> getLoginHistory(String userId, long fromTime, long toTime) throws Exception {
81 return loginHistoryStorage.getLoginHistory(userId, fromTime, toTime);
82 }
83
84
85
86
87 public List<LoginCounterBean> getLoginCountPerDaysInRange(String userId, long fromDate, long toDate) throws Exception {
88 return getLoginCountPerDaysInRange(userId, fromDate, toDate);
89 }
90
91
92
93
94 public List<LoginCounterBean> getLoginCountPerDaysInWeek(String userId, long week) throws Exception {
95 return loginHistoryStorage.getLoginCountPerDaysInWeek(userId, week);
96 }
97
98
99
100
101 public List<LoginCounterBean> getLoginCountPerWeeksInMonths(String userId, long fromMonth, int numOfMonths) throws Exception {
102 return loginHistoryStorage.getLoginCountPerWeeksInMonths(userId, fromMonth, numOfMonths);
103 }
104
105
106
107
108 public List<LoginCounterBean> getLoginCountPerMonthsInYear(String userId, long year) throws Exception {
109 return loginHistoryStorage.getLoginCountPerMonthsInYear(userId, year);
110 }
111
112
113
114
115
116
117
118 public Set<String> getLastUsersLogin(long fromTime) throws Exception {
119 return loginHistoryStorage.getLastUsersLogin(fromTime);
120 }
121
122 public long getBeforeLastLogin(String userId) throws Exception {
123 return loginHistoryStorage.getBeforeLastLogin(userId);
124 }
125
126 public boolean isEnabled() {
127 return enableLoginHistory;
128 };
129 }