|
|
@ -1,5 +1,7 @@ |
|
|
|
package awesome.group.game.web.filter; |
|
|
|
|
|
|
|
import awesome.group.game.service.cache.CacheKey; |
|
|
|
import awesome.group.game.service.cache.JedisManager; |
|
|
|
import awesome.group.game.web.RequestContext; |
|
|
|
import awesome.group.game.service.common.log.L; |
|
|
|
import awesome.group.game.service.common.response.R; |
|
|
@ -11,6 +13,7 @@ import jakarta.servlet.annotation.WebFilter; |
|
|
|
import jakarta.servlet.http.Cookie; |
|
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
@ -22,6 +25,9 @@ import java.util.List; |
|
|
|
@WebFilter(filterName = "AdminLoginFilter", urlPatterns = {"/api/admin/*"}) |
|
|
|
public class AdminLoginFilter implements Filter { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private JedisManager jedisManager; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void init(FilterConfig filterConfig) throws ServletException { |
|
|
@ -33,7 +39,7 @@ public class AdminLoginFilter implements Filter { |
|
|
|
try { |
|
|
|
HttpServletRequest httpRequest = (HttpServletRequest) request; |
|
|
|
String token = ""; |
|
|
|
if(httpRequest.getCookies() != null) { |
|
|
|
if (httpRequest.getCookies() != null) { |
|
|
|
for (Cookie c : httpRequest.getCookies()) { |
|
|
|
if (c.getName().equals("MatrixToken")) { |
|
|
|
token = c.getValue(); |
|
|
@ -64,6 +70,12 @@ public class AdminLoginFilter implements Filter { |
|
|
|
} |
|
|
|
if (pass) { |
|
|
|
RequestContext.initAdmin(httpRequest, (HttpServletResponse) response, adminId); |
|
|
|
String channel = RequestContext.getRequestChannel(); |
|
|
|
String cacheKey = CacheKey.disableChannel(); |
|
|
|
if (adminId != null && adminId != 1 && jedisManager.sIsMember(cacheKey, channel)) { |
|
|
|
channelDisable(response); |
|
|
|
return; |
|
|
|
} |
|
|
|
chain.doFilter(request, response); |
|
|
|
} else { |
|
|
|
authFail(response); |
|
|
@ -82,6 +94,15 @@ public class AdminLoginFilter implements Filter { |
|
|
|
response.getWriter().flush(); |
|
|
|
} |
|
|
|
|
|
|
|
private void channelDisable(ServletResponse response) throws IOException { |
|
|
|
R<String> res = new R<>(-99999, "服务已停机", null); |
|
|
|
Gson gson = new Gson(); |
|
|
|
response.setContentType("application/json;charset=UTF-8"); |
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
response.getWriter().write(gson.toJson(res)); |
|
|
|
response.getWriter().flush(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void destroy() { |
|
|
|
|
|
|
|