| | |
| | | package com.ks.app.aop; |
| | | |
| | | import com.ks.app.entity.AdminUser; |
| | | import com.ks.app.entity.admin.AdminUser; |
| | | import com.ks.app.service.inter.admin.AdminRoleRuleService; |
| | | import com.ks.app.utils.ApiCodeConstant; |
| | | import com.ks.app.utils.SystemInfoUtil; |
| | | import com.ks.app.vo.AcceptAdminData; |
| | |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.io.IOException; |
| | | import java.io.PrintWriter; |
| | |
| | | @Order(2) |
| | | public class AdminApiFilter { |
| | | |
| | | public static final String EDP = "execution(* com.ks.app.controller.admin..*.*(..))"; |
| | | @Resource |
| | | private AdminRoleRuleService adminRoleRuleService; |
| | | |
| | | public static final String EDP = "execution(* com.yeshi.makemoney.app.controller.admin..*.*(..))"; |
| | | |
| | | @Around(EDP) |
| | | public Object around(ProceedingJoinPoint joinPoint) throws IOException { |
| | | Object[] args = joinPoint.getArgs(); |
| | | ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder |
| | | .getRequestAttributes(); |
| | | servletContainer.getResponse().setCharacterEncoding("UTF-8"); |
| | | |
| | | AcceptAdminData acceptAdminData = null; |
| | | for (Object obj : args) { |
| | |
| | | |
| | | if (acceptAdminData != null) { |
| | | HttpSession session = servletContainer.getRequest().getSession(); |
| | | String url = servletContainer.getRequest().getRequestURI(); |
| | | |
| | | acceptAdminData.setSystem(SystemInfoUtil.getAdminSelectedSystem(servletContainer.getRequest().getSession())); |
| | | if (acceptAdminData.getSystem() == null) { |
| | | acceptAdminData.setSystem(SystemInfoUtil.getAdminSelectedSystem(session)); |
| | | if (acceptAdminData.getSystem() == null && !url.endsWith("index.html") && !url.endsWith("login.html")) { |
| | | PrintWriter out = servletContainer.getResponse().getWriter(); |
| | | out.print(JsonUtil.loadFalseResult(ApiCodeConstant.CODE_ERROR_IN_SERVER, "未选择系统")); |
| | | out.close(); |
| | |
| | | if (contextSession != null) { |
| | | Authentication authentication = contextSession.getAuthentication(); |
| | | AdminUser adminUser = (AdminUser) authentication.getPrincipal(); |
| | | //加载权限 |
| | | if (adminUser != null && adminUser.getRules() == null) { |
| | | adminUser.setRules(adminRoleRuleService.listPaths(adminUser.getAccount())); |
| | | } |
| | | acceptAdminData.setAdminUser(adminUser); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | try { |
| | | return joinPoint.proceed(args); |
| | | } catch (Throwable e) { |
| | | e.printStackTrace(); |
| | | PrintWriter out = servletContainer.getResponse().getWriter(); |
| | | out.print(JsonUtil.loadFalseResult(ApiCodeConstant.CODE_ERROR_IN_SERVER, "服务器内部错误")); |
| | | out.close(); |