diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/WebConfig.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/WebConfig.java index d299a7728..03979a781 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/WebConfig.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/config/WebConfig.java @@ -1,10 +1,11 @@ package com.fuint.common.config; import com.fuint.common.web.AdminUserInterceptor; -import com.fuint.common.web.CommandInterceptor; import com.fuint.common.web.ClientUserInterceptor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.http.CacheControl; import org.springframework.web.filter.CharacterEncodingFilter; import org.springframework.web.servlet.config.annotation.*; @@ -20,16 +21,20 @@ import java.util.concurrent.TimeUnit; */ @Configuration public class WebConfig extends WebMvcConfigurationSupport { + @Autowired + private Environment env; + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { + String pathRoot = env.getProperty("images.root"); registry.addResourceHandler("/resources/**") .addResourceLocations("/resources/", "classpath:/other-resources/") .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) .resourceChain(false) .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")) .addTransformer(new CssLinkResourceTransformer()); - registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); + registry.addResourceHandler("/static/**") .addResourceLocations("file:" + pathRoot + "/static/"); registry.addResourceHandler("/**").addResourceLocations( "classpath:/static/"); @@ -40,10 +45,6 @@ public class WebConfig extends WebMvcConfigurationSupport { super.addResourceHandlers(registry); } - @Bean - public CommandInterceptor commandInterceptor() { - return new CommandInterceptor(); - } @Bean public AdminUserInterceptor adminUserInterceptor() { @@ -57,9 +58,6 @@ public class WebConfig extends WebMvcConfigurationSupport { @Override public void addInterceptors(InterceptorRegistry registry) { - // Command - registry.addInterceptor(commandInterceptor()) - .addPathPatterns("/cmd/**"); // 后台拦截 registry.addInterceptor(adminUserInterceptor()) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/CommonFilter.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/CommonFilter.java new file mode 100644 index 000000000..cf8a18968 --- /dev/null +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/CommonFilter.java @@ -0,0 +1,81 @@ +package com.fuint.common.shiroConfig; + +import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fuint.common.dto.AccountInfo; +import com.fuint.common.util.Constants; +import com.fuint.common.util.RedisUtil; +import com.fuint.common.util.TokenUtil; +import com.fuint.framework.FrameworkConstants; +import com.fuint.framework.web.ResponseObject; +import com.fuint.system.dept.entity.SysDept; +import com.fuint.system.dept.service.ISysDeptService; +import com.fuint.utils.SpringUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.io.PrintWriter; + +@Slf4j +public class CommonFilter implements Filter { + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + try { + HttpServletRequest request = (HttpServletRequest) servletRequest; + String token = request.getHeader("Access-Token"); + Object loginInfo = RedisUtil.get(Constants.SESSION_ADMIN_USER + token); + ObjectMapper objectMapper = new ObjectMapper(); + AccountInfo nowAccountInfo = objectMapper.convertValue(loginInfo, AccountInfo.class); + if (ObjectUtil.isNotEmpty(nowAccountInfo)) { + ISysDeptService deptService = SpringUtils.getBean(ISysDeptService.class); + //判断机构的状态 + SysDept dept = deptService.getById(nowAccountInfo.getDeptId()); + if (dept.getStatus().equals("qy")){ + filterChain.doFilter(servletRequest, servletResponse); + }else { + ResponseObject responseObject = new ResponseObject(444, "机构禁用", ""); + returnJson(servletResponse, JSONObject.toJSONString(responseObject)); + } + }else { + ResponseObject responseObject = new ResponseObject(401, "登录信息已失效,请重新登录", ""); + returnJson(servletResponse, JSONObject.toJSONString(responseObject)); + } + }catch (Exception e){ + log.error(e.getMessage()); + } + } + + + + /** + * 封装异常返回数据 + * @param response + * @param json + * @throws Exception + */ + + private void returnJson(ServletResponse response, String json) throws Exception{ + PrintWriter writer = null; + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html; charset=utf-8"); + try { + writer = response.getWriter(); + writer.print(json); + + } catch (IOException e) { + log.error("response error",e); + } finally { + if (writer != null) { + writer.close(); + } + } + } + + + +} diff --git a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/ShiroConfig.java similarity index 80% rename from fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java rename to fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/ShiroConfig.java index 5bbbab166..f04b84e90 100644 --- a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/ShiroConfig.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/ShiroConfig.java @@ -1,18 +1,16 @@ -package com.fuint.framework.shiroConfig; +package com.fuint.common.shiroConfig; -import org.apache.shiro.authc.credential.HashedCredentialsMatcher; import org.apache.shiro.mgt.SecurityManager; -import org.apache.shiro.spring.LifecycleBeanPostProcessor; import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.util.ThreadContext; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; -import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; +import javax.servlet.Filter; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; /** @@ -28,15 +26,14 @@ public class ShiroConfig { public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean filter=new ShiroFilterFactoryBean(); filter.setSecurityManager(securityManager); - //设置shiro的拦截规则 - //anon 匿名用户可访问 authc 认证用户可访问 - //user 使用RemeberMe的用户可访问 perms 对应权限可访问 - //role 对应的角色可访问 + Map filters =new HashMap<>(); + filters.put("commonFilter",new CommonFilter()); + filter.setFilters(filters); LinkedHashMap filterMap=new LinkedHashMap<>(); filterMap.put("/backendApi/login/doLogin","anon"); filterMap.put("/clientApi/captcha/getCode","anon"); filterMap.put("/static/**","anon"); - filterMap.put("/**","authc"); + filterMap.put("/**","commonFilter"); filter.setFilterChainDefinitionMap(filterMap); filter.setLoginUrl("/login"); return filter; diff --git a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/UserRealm.java similarity index 98% rename from fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java rename to fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/UserRealm.java index 45bef0e2a..53ce0204b 100644 --- a/fuintBackend/fuint-framework/src/main/java/com/fuint/framework/shiroConfig/UserRealm.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/common/shiroConfig/UserRealm.java @@ -1,4 +1,4 @@ -package com.fuint.framework.shiroConfig; +package com.fuint.common.shiroConfig; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/CommandInterceptor.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/CommandInterceptor.java deleted file mode 100644 index ff3e8c92a..000000000 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/CommandInterceptor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.fuint.common.web; - -import org.apache.commons.lang.StringUtils; -import org.springframework.web.servlet.AsyncHandlerInterceptor; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Created by FSQ - * CopyRight https://www.fuint.cn - */ -public class CommandInterceptor implements AsyncHandlerInterceptor { - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - String serverName = request.getServerName(); - if (!StringUtils.isEmpty(serverName) && serverName.equals("localhost")) { - return true; - } else { - return false; - } - } -} diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/SpringContextHolder.java b/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/SpringContextHolder.java deleted file mode 100644 index 186cdc88a..000000000 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/common/web/SpringContextHolder.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.fuint.common.web; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Service; - -/** - * Created by FSQ - * CopyRight https://www.fuint.cn - */ -@Service -public class SpringContextHolder implements ApplicationContextAware { - private static ApplicationContext applicationContext; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - SpringContextHolder.applicationContext = applicationContext; - } - - public static ApplicationContext getApplicationContext() { - return applicationContext; - } - - public static Object getBean(String beanName) { - return applicationContext.getBean(beanName); - } - - public static T getBean(Class clazz) { - return applicationContext.getBean(clazz); - } - - public static T getBean(String beanName, Class clazz) { - return applicationContext.getBean(beanName, clazz); - } - -} diff --git a/fuintBackend/fuint-application/src/main/resources/urlRewrite.xml b/fuintBackend/fuint-application/src/main/resources/urlRewrite.xml deleted file mode 100644 index 8918d70e9..000000000 --- a/fuintBackend/fuint-application/src/main/resources/urlRewrite.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - -