From be3e3bbf9d8e6433e7eeb348c6c83be0206ddb65 Mon Sep 17 00:00:00 2001 From: yutou Date: Fri, 28 May 2021 18:32:55 +0800 Subject: [PATCH] update --- .../com/yutou/bilibili/BiliBili/Live.java | 2 +- .../com/yutou/bilibili/Tools/APIFilter.java | 82 ++++++++++--------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index 1cfb8d0..b5d5ae9 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -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") + " 进入到直播间"; diff --git a/src/main/java/com/yutou/bilibili/Tools/APIFilter.java b/src/main/java/com/yutou/bilibili/Tools/APIFilter.java index 9c12d98..c28c95d 100644 --- a/src/main/java/com/yutou/bilibili/Tools/APIFilter.java +++ b/src/main/java/com/yutou/bilibili/Tools/APIFilter.java @@ -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 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 permissions = permissionDao.selectByExample(pExample); + if (permissions != null && permissions.size() > 0) { + if (powers.toJavaList(Integer.class).contains(permissions.get(0).getId())) { + filterChain.doFilter(servletRequest, servletResponse); + } + } + } + } } }