-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppUtils.java
47 lines (35 loc) · 1.38 KB
/
AppUtils.java
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
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpSession;
public class AppUtils {
private static int REDIRECT_ID = 0;
private static final Map<Integer, String> id_uri_map = new HashMap<Integer, String>();
private static final Map<String, Integer> uri_id_map = new HashMap<String, Integer>();
// Store user info in Session.
public static void storeLoginedUser(HttpSession session, UserAccount loginedUser) {
// On the JSP can access via ${loginedUser}
session.setAttribute("loginedUser", loginedUser);
}
// Get the user information stored in the session.
public static UserAccount getLoginedUser(HttpSession session) {
UserAccount loginedUser = (UserAccount) session.getAttribute("loginedUser");
return loginedUser;
}
public static int storeRedirectAfterLoginUrl(HttpSession session, String requestUri) {
Integer id = uri_id_map.get(requestUri);
if (id == null) {
id = REDIRECT_ID++;
uri_id_map.put(requestUri, id);
id_uri_map.put(id, requestUri);
return id;
}
return id;
}
public static String getRedirectAfterLoginUrl(HttpSession session, int redirectId) {
String url = id_uri_map.get(redirectId);
if (url != null) {
return url;
}
return null;
}
}