1
0
mirror of https://github.com/chatopera/cosin.git synced 2025-08-01 16:38:02 +08:00

Fix BasicErrorController's package path

This commit is contained in:
dengchao@xgtl 2020-04-15 17:32:00 +08:00
parent d0d85ead52
commit 25d3298b71

View File

@ -1,194 +1,193 @@
/* /*
* Copyright (C) 2017 优客服-多渠道客服系统 * Copyright (C) 2017 优客服-多渠道客服系统
* Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com> * Modifications copyright (C) 2018-2019 Chatopera Inc, <https://www.chatopera.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.chatopera.cc.interceptor; package com.chatopera.cc.interceptor;
import com.chatopera.cc.acd.ACDServiceRouter; import com.chatopera.cc.acd.ACDServiceRouter;
import com.chatopera.cc.basic.Constants; import com.chatopera.cc.basic.Constants;
import com.chatopera.cc.basic.MainContext; import com.chatopera.cc.basic.MainContext;
import com.chatopera.cc.basic.MainUtils; import com.chatopera.cc.basic.MainUtils;
import com.chatopera.cc.config.MessagingServerConfigure; import com.chatopera.cc.config.MessagingServerConfigure;
import com.chatopera.cc.model.Dict; import com.chatopera.cc.model.Dict;
import com.chatopera.cc.model.SystemConfig; import com.chatopera.cc.model.SystemConfig;
import com.chatopera.cc.model.User; import com.chatopera.cc.model.User;
import com.chatopera.cc.proxy.AgentSessionProxy; import com.chatopera.cc.proxy.AgentSessionProxy;
import com.chatopera.cc.proxy.UserProxy; import com.chatopera.cc.proxy.UserProxy;
import com.chatopera.cc.util.Menu; import com.chatopera.cc.util.Menu;
import org.apache.commons.lang.StringUtils; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
import org.springframework.boot.autoconfigure.web.BasicErrorController; import org.springframework.lang.NonNull;
import org.springframework.web.method.HandlerMethod; import org.springframework.lang.Nullable;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserInterceptorHandler extends HandlerInterceptorAdapter {
private final static Logger logger = LoggerFactory.getLogger(UserInterceptorHandler.class); @Slf4j
private static UserProxy userProxy; public class UserInterceptorHandler extends HandlerInterceptorAdapter {
private static AgentSessionProxy agentSessionProxy;
private static Integer webimport; private static UserProxy userProxy;
private static AgentSessionProxy agentSessionProxy;
@Override private static Integer webIMPort;
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, Object handler)
throws Exception { private static Integer getWebIMPort() {
boolean filter = false; if (webIMPort == null) {
User user = (User) request.getSession(true).getAttribute(Constants.USER_SESSION_NAME); webIMPort = MainContext.getContext().getBean(MessagingServerConfigure.class).getWebIMPort();
}
if (handler instanceof HandlerMethod) { return webIMPort;
HandlerMethod handlerMethod = (HandlerMethod) handler; }
Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class);
if (user != null || (menu != null && menu.access()) || handlerMethod.getBean() instanceof BasicErrorController) { private static UserProxy getUserProxy() {
filter = true; if (userProxy == null) {
if (user != null && StringUtils.isNotBlank(user.getId())) { userProxy = MainContext.getContext().getBean(UserProxy.class);
}
/** return userProxy;
* 每次刷新用户的组织机构角色和权限 }
* TODO 此处代码执行频率高但是并不是每次都要执行存在很多冗余
* 待用更好的方法实现 private static AgentSessionProxy getAgentSessionProxy() {
*/ if (agentSessionProxy == null) {
getUserProxy().attachOrgansPropertiesForUser(user); agentSessionProxy = MainContext.getContext().getBean(AgentSessionProxy.class);
getUserProxy().attachRolesMap(user); }
return agentSessionProxy;
request.getSession(true).setAttribute(Constants.USER_SESSION_NAME, user); }
}
} @Override
public boolean preHandle(@NonNull final HttpServletRequest request, @NonNull final HttpServletResponse response,
if (!filter) { @NonNull Object handler) throws Exception {
if (StringUtils.isNotBlank(request.getParameter("msg"))) { boolean filter = false;
response.sendRedirect("/login.html?msg=" + request.getParameter("msg")); User user = (User) request.getSession(true).getAttribute(Constants.USER_SESSION_NAME);
} else {
response.sendRedirect("/login.html"); if (handler instanceof HandlerMethod) {
} HandlerMethod handlerMethod = (HandlerMethod) handler;
} Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class);
} else { if (user != null || (menu != null && menu.access()) || handlerMethod.getBean() instanceof BasicErrorController) {
filter = true; filter = true;
} if (user != null && StringUtils.isNotBlank(user.getId())) {
return filter;
} /*
* 每次刷新用户的组织机构角色和权限
@Override * TODO 此处代码执行频率高但是并不是每次都要执行存在很多冗余
public void postHandle( * 待用更好的方法实现
HttpServletRequest request, HttpServletResponse response, Object arg2, */
ModelAndView view) { getUserProxy().attachOrgansPropertiesForUser(user);
final User user = (User) request.getSession().getAttribute(Constants.USER_SESSION_NAME); getUserProxy().attachRolesMap(user);
final String infoace = (String) request.getSession().getAttribute(
Constants.CSKEFU_SYSTEM_INFOACQ); //进入信息采集模式 request.getSession(true).setAttribute(Constants.USER_SESSION_NAME, user);
final SystemConfig systemConfig = MainUtils.getSystemConfig(); }
if (view != null) { }
if (user != null) {
view.addObject("user", user); if (!filter) {
if (StringUtils.isNotBlank(request.getParameter("msg"))) {
if (systemConfig != null && systemConfig.isEnablessl()) { response.sendRedirect("/login.html?msg=" + request.getParameter("msg"));
view.addObject("schema", "https"); } else {
if (request.getServerPort() == 80) { response.sendRedirect("/login.html");
view.addObject("port", 443); }
} else { }
view.addObject("port", request.getServerPort()); } else {
} filter = true;
} else { }
view.addObject("schema", request.getScheme()); return filter;
view.addObject("port", request.getServerPort()); }
}
view.addObject("hostname", request.getServerName()); @Override
public void postHandle(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler,
HandlerMethod handlerMethod = (HandlerMethod) arg2; @Nullable ModelAndView view) {
Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class); final User user = (User) request.getSession().getAttribute(Constants.USER_SESSION_NAME);
if (menu != null) { final String infoace = (String) request.getSession().getAttribute(
view.addObject("subtype", menu.subtype()); Constants.CSKEFU_SYSTEM_INFOACQ); //进入信息采集模式
view.addObject("maintype", menu.type()); final SystemConfig systemConfig = MainUtils.getSystemConfig();
view.addObject("typename", menu.name()); if (view != null) {
} if (user != null) {
view.addObject("orgi", user.getOrgi()); view.addObject("user", user);
}
if (StringUtils.isNotBlank(infoace)) { if (systemConfig != null && systemConfig.isEnablessl()) {
view.addObject("infoace", infoace); //进入信息采集模式 view.addObject("schema", "https");
} if (request.getServerPort() == 80) {
view.addObject("webimport", getWebimport()); view.addObject("port", 443);
view.addObject("sessionid", MainUtils.getContextID(request.getSession().getId())); } else {
view.addObject("port", request.getServerPort());
view.addObject("models", MainContext.getModules()); }
} else {
if (user != null) { view.addObject("schema", request.getScheme());
view.addObject( view.addObject("port", request.getServerPort());
"agentStatusReport", }
ACDServiceRouter.getAcdWorkMonitor().getAgentReport(user.getOrgi())); view.addObject("hostname", request.getServerName());
}
/** HandlerMethod handlerMethod = (HandlerMethod) handler;
* WebIM共享用户 Menu menu = handlerMethod.getMethod().getAnnotation(Menu.class);
*/ if (menu != null) {
User imUser = (User) request.getSession().getAttribute(Constants.IM_USER_SESSION_NAME); view.addObject("subtype", menu.subtype());
if (imUser == null && view != null) { view.addObject("maintype", menu.type());
imUser = new User(); view.addObject("typename", menu.name());
imUser.setUsername(Constants.GUEST_USER); }
imUser.setId(MainUtils.getContextID(request.getSession(true).getId())); view.addObject("orgi", user.getOrgi());
imUser.setSessionid(imUser.getId()); }
view.addObject("imuser", imUser); if (StringUtils.isNotBlank(infoace)) {
} view.addObject("infoace", infoace); //进入信息采集模式
}
if (request.getParameter("msg") != null) { view.addObject("webimport", getWebIMPort());
view.addObject("msg", request.getParameter("msg")); view.addObject("sessionid", MainUtils.getContextID(request.getSession().getId()));
}
view.addObject("models", MainContext.getModules());
view.addObject("uKeFuDic", Dict.getInstance()); //处理系统 字典数据 通过 字典code 获取
if (user != null) {
view.addObject( view.addObject(
"uKeFuSecField", MainContext.getCache().findOneSystemByIdAndOrgi( "agentStatusReport",
Constants.CSKEFU_SYSTEM_SECFIELD, ACDServiceRouter.getAcdWorkMonitor().getAgentReport(user.getOrgi()));
MainContext.SYSTEM_ORGI)); //处理系统 需要隐藏号码的字段 启动的时候加载 }
/*
if (systemConfig != null) { * WebIM共享用户
view.addObject("systemConfig", systemConfig); */
} else { User imUser = (User) request.getSession().getAttribute(Constants.IM_USER_SESSION_NAME);
view.addObject("systemConfig", new SystemConfig()); if (imUser == null) {
} imUser = new User();
view.addObject("tagTypeList", Dict.getInstance().getDic("com.dic.tag.type")); imUser.setUsername(Constants.GUEST_USER);
imUser.setId(MainUtils.getContextID(request.getSession(true).getId()));
view.addObject("advTypeList", Dict.getInstance().getDic("com.dic.adv.type")); imUser.setSessionid(imUser.getId());
view.addObject("ip", request.getRemoteAddr()); view.addObject("imuser", imUser);
} }
}
if (request.getParameter("msg") != null) {
@Override view.addObject("msg", request.getParameter("msg"));
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { }
}
view.addObject("uKeFuDic", Dict.getInstance()); //处理系统 字典数据 通过 字典code 获取
private static Integer getWebimport() { view.addObject(
if (webimport == null) { "uKeFuSecField", MainContext.getCache().findOneSystemByIdAndOrgi(
webimport = MainContext.getContext().getBean(MessagingServerConfigure.class).getWebIMPort(); Constants.CSKEFU_SYSTEM_SECFIELD,
} MainContext.SYSTEM_ORGI)); //处理系统 需要隐藏号码的字段 启动的时候加载
return webimport;
} if (systemConfig != null) {
view.addObject("systemConfig", systemConfig);
} else {
private static UserProxy getUserProxy() { view.addObject("systemConfig", new SystemConfig());
if (userProxy == null) { }
userProxy = MainContext.getContext().getBean(UserProxy.class); view.addObject("tagTypeList", Dict.getInstance().getDic("com.dic.tag.type"));
}
return userProxy; view.addObject("advTypeList", Dict.getInstance().getDic("com.dic.adv.type"));
} view.addObject("ip", request.getRemoteAddr());
}
private static AgentSessionProxy getAgentSessionProxy() { }
if (agentSessionProxy == null) {
agentSessionProxy = MainContext.getContext().getBean(AgentSessionProxy.class); @Override
} public void afterCompletion(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull Object handler, @Nullable Exception ex) {
return agentSessionProxy; }
}
}
}