This commit is contained in:
yutou 2021-05-28 18:32:55 +08:00
parent 470d07d416
commit be3e3bbf9d
2 changed files with 44 additions and 40 deletions

View File

@ -350,7 +350,7 @@ public class Live implements ApplicationContextAware {
BilibiliLiveData liveData = new BilibiliLiveData();
String danmu;
GiftData giftData;
Log.i(AppTools.getToDayTimeToString(startTime),roomId,json.toJSONString());
Log.i(AppTools.getToDayTime(),roomId,json.toJSONString());
switch (json.getString("cmd")) {
case "INTERACT_WORD"://普通用户进直播间
danmu = json.getJSONObject("data").getString("uname") + " 进入到直播间";

View File

@ -31,48 +31,52 @@ public class APIFilter implements Filter {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
String token = request.getParameter("token");
if(StringUtils.isEmpty(token)){
Cookie cookie=AppTools.getCookie(request,"login");
if(cookie!=null){
token=cookie.getValue();
if (StringUtils.isEmpty(token)) {
Cookie cookie = AppTools.getCookie(request, "login");
if (cookie != null) {
token = cookie.getValue();
}
}
String tmp = request.getRequestURI();
if(tmp.contains("/user/login.do")
||tmp.contains("/user/reg.do")
||tmp.contains("/user/logout.do")
||tmp.contains("/user/get/test.do")
||tmp.contains("/system/public/reg.do")
||tmp.contains("/favicon.ico")
){
filterChain.doFilter(servletRequest,servletResponse);
}else {
UUser user= service.getUserToUid(Integer.parseInt(RedisTools.get(token)));;
if(user==null){
response.sendRedirect("/");
}else{
String url=null;
try {
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
} catch (Exception e) {
com.yutou.bilibili.Tools.Log.e(e);
com.yutou.bilibili.Tools.Log.i("无权限请求:"+tmp);
return;
}
JSONArray powers = JSONArray.parseArray(user.getPower());
if(powers.toJavaList(Integer.class).contains(-1)){
filterChain.doFilter(servletRequest,servletResponse);
}else {
PermissionExample pExample = new PermissionExample();
pExample.createCriteria().andUrlEqualTo(url);
List<Permission> permissions = permissionDao.selectByExample(pExample);
if (permissions != null && permissions.size() > 0) {
if (powers.toJavaList(Integer.class).contains(permissions.get(0).getId())) {
filterChain.doFilter(servletRequest,servletResponse);
}
}
}
}
if (tmp.contains("/user/login.do")
|| tmp.contains("/user/reg.do")
|| tmp.contains("/user/logout.do")
|| tmp.contains("/user/get/test.do")
|| tmp.contains("/system/public/reg.do")
|| tmp.contains("/favicon.ico")
) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
if (StringUtils.isEmpty(token)) {
response.sendRedirect("/");
return;
}
UUser user = service.getUserToUid(Integer.parseInt(RedisTools.get(token)));
if (user == null) {
response.sendRedirect("/");
} else {
String url = null;
try {
url = tmp.split(tmp.split("/")[tmp.split("/").length - 1])[0];
} catch (Exception e) {
com.yutou.bilibili.Tools.Log.e(e);
com.yutou.bilibili.Tools.Log.i("无权限请求:" + tmp);
return;
}
JSONArray powers = JSONArray.parseArray(user.getPower());
if (powers.toJavaList(Integer.class).contains(-1)) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
PermissionExample pExample = new PermissionExample();
pExample.createCriteria().andUrlEqualTo(url);
List<Permission> permissions = permissionDao.selectByExample(pExample);
if (permissions != null && permissions.size() > 0) {
if (powers.toJavaList(Integer.class).contains(permissions.get(0).getId())) {
filterChain.doFilter(servletRequest, servletResponse);
}
}
}
}
}
}