Repository navigation
Expand file tree
/
Copy pathBMSContext.java
More file actions
69 lines (53 loc) · 1.75 KB
/
Copy pathBMSContext.java
File metadata and controls
69 lines (53 loc) · 1.75 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
package bms.core.common;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import bms.core.common.Consts.Keys;
import bms.core.common.util.StringUtil;
/**
* @author xu.jian
*
*/
@Component
public class BMSContext {
public static List<String> systemUrl = null;
// 权限是否只对应到菜单层级
private boolean menuAuthType;
private final static Pattern pattern = Pattern.compile("(?://|\\\\)");
public boolean isMenuAuthType() {
return menuAuthType;
}
public void setMenuAuthType(boolean menuAuthType) {
this.menuAuthType = menuAuthType;
}
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
}
public String getPath() {
String path = getRequest().getServletPath();
Matcher matcher = pattern.matcher(path);
path = matcher.replaceAll("/");
System.out.println("getPath:" + path);
return path;
}
public void setSession(String key, Object data) {
HttpSession session = getRequest().getSession();
session.setAttribute(Keys.SESSION_AUTHS, data);
}
public Object getSessionValue(String key) {
return getRequest().getSession().getAttribute(key) != null ? getRequest()
.getSession().getAttribute(key) : null;
}
public HttpSession getSession() {
return getRequest().getSession();
}
public String getUserIp() {
return StringUtil.getIpAddr(getRequest());
}
}