|
|
|
@ -1,34 +1,25 @@
|
|
|
|
|
package com.ibeetl.admin.core.conf;
|
|
|
|
|
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreOrg;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.service.CorePlatformService;
|
|
|
|
|
import com.ibeetl.admin.core.service.CoreUserService;
|
|
|
|
|
import com.ibeetl.admin.core.util.HttpRequestLocal;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.beetl.core.GroupTemplate;
|
|
|
|
|
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
|
|
|
|
|
import org.springframework.beans.factory.InitializingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.format.FormatterRegistry;
|
|
|
|
|
import org.springframework.format.datetime.DateFormatter;
|
|
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
@ConditionalOnMissingClass("cn.jlw.Interceptor.WebSessionInterceptor")
|
|
|
|
|
public class MVCConf implements WebMvcConfigurer, InitializingBean {
|
|
|
|
|
|
|
|
|
|
private final Log log = LogFactory.getLog(this.getClass());
|
|
|
|
@ -53,23 +44,15 @@ public class MVCConf implements WebMvcConfigurer, InitializingBean {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
Environment env;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
CoreUserService userService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
BeetlGroupUtilConfiguration beetlGroupUtilConfiguration;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
HttpRequestLocal httpRequestLocal;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
GroupTemplate groupTemplate;
|
|
|
|
|
@Resource
|
|
|
|
|
SessionInterceptor sessionInterceptor;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
|
|
|
|
|
registry.addInterceptor(new SessionInterceptor(httpRequestLocal, this)).addPathPatterns("/**");
|
|
|
|
|
registry.addInterceptor(sessionInterceptor).addPathPatterns("/**");
|
|
|
|
|
// super.addInterceptors(registry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -123,58 +106,6 @@ public class MVCConf implements WebMvcConfigurer, InitializingBean {
|
|
|
|
|
var.put("jsVer", System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
groupTemplate.setSharedVars(var);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SessionInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
|
|
|
|
MVCConf conf;
|
|
|
|
|
HttpRequestLocal httpRequestLocal;
|
|
|
|
|
|
|
|
|
|
public SessionInterceptor(HttpRequestLocal httpRequestLocal, MVCConf conf) {
|
|
|
|
|
this.conf = conf;
|
|
|
|
|
this.httpRequestLocal = httpRequestLocal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
|
|
|
|
throws Exception {
|
|
|
|
|
|
|
|
|
|
// 方便运行时,修改环境变量参数,用于测试类变更登录用户
|
|
|
|
|
Long userId = conf.env.getProperty("user.id", Long.class);
|
|
|
|
|
Long orgId = conf.env.getProperty("user.orgId", Long.class);
|
|
|
|
|
if (userId != null && orgId != null
|
|
|
|
|
&& request.getSession().getAttribute(CorePlatformService.ACCESS_CURRENT_USER) == null) {
|
|
|
|
|
// 模拟用户登录,用于快速开发,未来用rember么代替?
|
|
|
|
|
CoreUser user = conf.userService.getUserById(userId);
|
|
|
|
|
CoreOrg org = conf.userService.getOrgById(orgId);
|
|
|
|
|
List<CoreOrg> orgs = conf.userService.getUserOrg(userId, org.getId());
|
|
|
|
|
request.getSession().setAttribute(CorePlatformService.ACCESS_CURRENT_USER, user);
|
|
|
|
|
request.getSession().setAttribute(CorePlatformService.ACCESS_CURRENT_ORG, org);
|
|
|
|
|
request.getSession().setAttribute(CorePlatformService.ACCESS_USER_ORGS, orgs);
|
|
|
|
|
request.getSession().setAttribute("ip", request.getRemoteHost());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
httpRequestLocal.set(request);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
|
|
|
|
|
ModelAndView modelAndView) throws Exception {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
|
|
|
|
|
throws Exception {
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|