Commit a13f40e1b9f01d919777fd9975d91c48cc96775b

Authored by youxiw2000
1 parent 9227cfcc

1

bsthLineProfiles/pom.xml
... ... @@ -287,6 +287,19 @@
287 287 <artifactId>poi-ooxml</artifactId>
288 288 <version>${poi.version}</version>
289 289 </dependency>
  290 +
  291 + <dependency>
  292 + <groupId>org.apache.httpcomponents</groupId>
  293 + <artifactId>httpcore</artifactId>
  294 + <version>4.4.10</version>
  295 + </dependency>
  296 +
  297 + <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
  298 + <dependency>
  299 + <groupId>org.apache.httpcomponents</groupId>
  300 + <artifactId>httpclient</artifactId>
  301 + <version>4.5.6</version>
  302 + </dependency>
290 303  
291 304 </dependencies>
292 305  
... ...
bsthLineProfiles/src/main/java/com/ruoyi/framework/web/service/TokenService.java
... ... @@ -50,17 +50,11 @@ public class TokenService
50 50 *
51 51 * @return 用户信息
52 52 */
53   - public User getUser(HttpServletRequest request)
  53 + public User getUser(String token)
54 54 {
55   - // 获取请求携带的令牌
56   - String token = getToken(request);
57 55 if (StringUtils.isNotEmpty(token))
58 56 {
59   - Claims claims = parseToken(token);
60   - // 解析对应的权限以及用户信息
61   - String uuid = (String) claims.get(Constants.LOGIN_USER_KEY);
62   - String userKey = getTokenKey(uuid);
63   - User user = redisCache.getCacheObject(userKey);
  57 + User user = redisCache.getCacheObject(token);
64 58 return user;
65 59 }
66 60 return null;
... ... @@ -174,10 +168,7 @@ public class TokenService
174 168 */
175 169 private Claims parseToken(String token)
176 170 {
177   - return Jwts.parser()
178   - .setSigningKey(secret)
179   - .parseClaimsJws(token)
180   - .getBody();
  171 + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
181 172 }
182 173  
183 174 /**
... ...
bsthLineProfiles/src/main/java/com/ruoyi/project/system/menu/mapper/MenuMapper.java
... ... @@ -121,4 +121,6 @@ public interface MenuMapper
121 121 * @return 结果
122 122 */
123 123 public Menu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId);
  124 +
  125 + public List<Menu> selectMenuNormalByMenuIds(String[] ids);
124 126 }
... ...
bsthLineProfiles/src/main/java/com/ruoyi/project/system/menu/service/IMenuService.java
... ... @@ -124,4 +124,6 @@ public interface IMenuService
124 124 * @return 结果
125 125 */
126 126 public String checkMenuNameUnique(Menu menu);
  127 +
  128 + public List<Menu> selectMenuNormalByMenuIds(String[] strings);
127 129 }
... ...
bsthLineProfiles/src/main/java/com/ruoyi/project/system/menu/service/MenuServiceImpl.java
... ... @@ -48,17 +48,22 @@ public class MenuServiceImpl implements IMenuService
48 48 {
49 49 List<Menu> menus = new LinkedList<Menu>();
50 50 // 管理员显示所有菜单信息
51   - if (user.isAdmin())
52   - {
  51 +// if (user.isAdmin())
  52 +// {
53 53 menus = menuMapper.selectMenuNormalAll();
54   - }
55   - else
56   - {
57   - menus = menuMapper.selectMenusByUserId(user.getUserId());
58   - }
  54 +// }
  55 +// else
  56 +// {
  57 +// menus = menuMapper.selectMenusByUserId(user.getUserId());
  58 +// }
59 59 return TreeUtils.getChildPerms(menus, 0);
60 60 }
  61 + @Override
  62 + public List<Menu> selectMenuNormalByMenuIds(String[] ids) {
  63 + // TODO Auto-generated method stub
61 64  
  65 + return TreeUtils.getChildPerms(menuMapper.selectMenuNormalByMenuIds(ids), 0);
  66 + }
62 67 /**
63 68 * 查询菜单集合
64 69 *
... ... @@ -321,4 +326,6 @@ public class MenuServiceImpl implements IMenuService
321 326 }
322 327 return UserConstants.MENU_NAME_UNIQUE;
323 328 }
  329 +
  330 +
324 331 }
... ...
bsthLineProfiles/src/main/java/com/ruoyi/project/system/user/controller/LoginController.java
1 1 package com.ruoyi.project.system.user.controller;
2 2  
  3 +import java.util.ArrayList;
3 4 import java.util.Date;
  5 +import java.util.HashMap;
4 6 import java.util.List;
  7 +import java.util.Map;
5 8  
6   -import javax.servlet.http.Cookie;
7 9 import javax.servlet.http.HttpServletRequest;
8 10 import javax.servlet.http.HttpServletResponse;
9 11  
  12 +import org.apache.http.HttpResponse;
  13 +import org.apache.http.client.HttpClient;
  14 +import org.apache.http.client.methods.HttpPost;
  15 +import org.apache.http.entity.StringEntity;
  16 +import org.apache.http.impl.client.DefaultHttpClient;
  17 +import org.apache.http.impl.client.HttpClientBuilder;
  18 +import org.apache.http.util.EntityUtils;
10 19 import org.apache.shiro.SecurityUtils;
11 20 import org.apache.shiro.authc.AuthenticationException;
12 21 import org.apache.shiro.authc.UsernamePasswordToken;
... ... @@ -18,6 +27,9 @@ import org.springframework.web.bind.annotation.GetMapping;
18 27 import org.springframework.web.bind.annotation.PostMapping;
19 28 import org.springframework.web.bind.annotation.ResponseBody;
20 29  
  30 +import com.alibaba.fastjson.JSON;
  31 +import com.alibaba.fastjson.JSONArray;
  32 +import com.alibaba.fastjson.JSONObject;
21 33 import com.ruoyi.common.utils.DateUtils;
22 34 import com.ruoyi.common.utils.ServletUtils;
23 35 import com.ruoyi.common.utils.StringUtils;
... ... @@ -26,13 +38,15 @@ import com.ruoyi.framework.config.RuoYiConfig;
26 38 import com.ruoyi.framework.shiro.service.PasswordService;
27 39 import com.ruoyi.framework.web.controller.BaseController;
28 40 import com.ruoyi.framework.web.domain.AjaxResult;
  41 +import com.ruoyi.framework.web.service.PermissionService;
29 42 import com.ruoyi.framework.web.service.TokenService;
30 43 import com.ruoyi.project.system.config.service.IConfigService;
31 44 import com.ruoyi.project.system.menu.domain.Menu;
32 45 import com.ruoyi.project.system.menu.service.IMenuService;
33   -import com.ruoyi.project.system.menu.service.MenuServiceImpl;
34 46 import com.ruoyi.project.system.user.domain.User;
35 47  
  48 +import io.jsonwebtoken.lang.Assert;
  49 +
36 50 /**
37 51 * 登录验证
38 52 *
... ... @@ -55,6 +69,7 @@ public class LoginController extends BaseController
55 69  
56 70 @Autowired
57 71 private RuoYiConfig ruoYiConfig;
  72 +
58 73  
59 74 @GetMapping("/login")
60 75 public String login(HttpServletRequest request, HttpServletResponse response)
... ... @@ -74,16 +89,55 @@ public class LoginController extends BaseController
74 89  
75 90 if(token != null) {
76 91  
77   - login("admin","admin123",false);
  92 + User user = tokenService.getUser(token);
  93 + if (user == null && token != null) {
  94 +
  95 + String dataJsonStr = sendPost("http://180.169.154.251:18080/information/authenticate/loginAuthentication",token);
  96 +
  97 +
  98 + JSONObject jsonObject = JSON.parseObject(dataJsonStr);
  99 +
  100 +
  101 + JSONObject dataJson = jsonObject.getJSONObject("data");
  102 +
  103 + Assert.notNull(dataJson, "获取用户信息异常");
  104 +
  105 +
  106 + JSONArray jsonMenu = dataJson.getJSONArray("userAuthList").getJSONObject(0).getJSONArray("roleList").getJSONObject(0).getJSONArray("resourceList");
  107 +
  108 +
  109 + Map<Long,Menu> menuMap = new HashMap<Long,Menu>();
  110 +
  111 + String ids = "";
  112 +
  113 + for(Object json:jsonMenu) {
  114 + ids += ((JSONObject)json).getLongValue("menuId") + ",";
  115 + }
  116 +
  117 + ids.substring(0,ids.length() -1);
  118 +
  119 + List<Menu> allMenus = menuService.selectMenuNormalByMenuIds(ids.split(","));
  120 +
  121 +
  122 +
  123 + login("admin","admin123",false);
  124 + user = getSysUser();
  125 + user.setToken(token);
  126 +// user.setPermissions(permissionService.getMenuPermission());
  127 + tokenService.createToken(user);
  128 +
  129 +
  130 + //String username = dataJson.getString("account");
  131 +// String username = "admin";
  132 +// AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
  133 +// SysUser sysUser = sysUserService.selectUserByUserName(username);
  134 +
  135 +// user.setPermissions(permissionService.getMenuPermission(sysUser));
  136 +// user.setUser(sysUser);
  137 +
78 138  
79   - // 取身份信息
80   - User user = getSysUser();
81   - // 根据用户id取出菜单
82   - List<Menu> menus = menuService.selectMenusByUser(user);
83   - mmap.put("menus", menus);
  139 + mmap.put("menus", allMenus);
84 140 mmap.put("user", user);
85   - mmap.put("sideTheme", "theme-dark");
86   - mmap.put("skinName", "skin-blue");
87 141 mmap.put("ignoreFooter", configService.selectConfigByKey("sys.index.ignoreFooter"));
88 142 mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear());
89 143 mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled());
... ... @@ -95,23 +149,12 @@ public class LoginController extends BaseController
95 149 // 移动端,默认使左侧导航菜单,否则取默认配置
96 150 String indexStyle = ServletUtils.checkAgentIsMobile(ServletUtils.getRequest().getHeader("User-Agent")) ? "index" : menuStyle;
97 151  
98   - // 优先Cookie配置导航菜单
99   - Cookie[] cookies = ServletUtils.getRequest().getCookies();
100   - for (Cookie cookie : cookies)
101   - {
102   - if (StringUtils.isNotEmpty(cookie.getName()) && "nav-style".equalsIgnoreCase(cookie.getName()))
103   - {
104   - indexStyle = cookie.getValue();
105   - break;
106   - }
107   - }
108 152  
109 153 return "index";
110 154  
111   - }else {
112   - return "login";
113 155 }
114   -
  156 +
  157 + }
115 158 // User loginUser = tokenService.getUser(ServletUtils.getRequest());
116 159  
117 160  
... ... @@ -121,10 +164,35 @@ public class LoginController extends BaseController
121 164 // subject.login(token);
122 165 // return success();
123 166  
124   -
125   -
  167 + return "index";
126 168 }
127 169  
  170 +public String sendPost(String url,String token) {
  171 + String strresponse = null;
  172 + try{
  173 + HttpClient hc = HttpClientBuilder.create().build();//获取DefaultHttpClient请求
  174 + HttpPost hp = new HttpPost(url);
  175 + JSONObject jsonParam = new JSONObject();
  176 +
  177 + jsonParam.put("token", token);
  178 + jsonParam.put("systemCode", "SYS0015");
  179 + //设置数据为utf-8编码
  180 + StringEntity entity = new StringEntity(jsonParam.toString(),"utf-8");
  181 + //设置请求编码
  182 + entity.setContentEncoding("utf-8");
  183 + //设置请求类型
  184 + entity.setContentType("application/json");
  185 + hp.setEntity(entity);
  186 + //请求并得到结果
  187 + HttpResponse result = hc.execute(hp);
  188 + strresponse = EntityUtils.toString(result.getEntity(),"utf-8").trim();
  189 + }catch(Exception e){
  190 + e.printStackTrace();
  191 + }
  192 + return strresponse;
  193 +
  194 +}
  195 +
128 196 // 检查初始密码是否提醒修改
129 197 public boolean initPasswordIsModify(Date pwdUpdateDate)
130 198 {
... ...
bsthLineProfiles/src/main/resources/mybatis/system/MenuMapper.xml
... ... @@ -45,6 +45,25 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
45 45 where m.menu_type in ('M', 'C') and m.visible = 0
46 46 order by m.parent_id, m.order_num
47 47 </select>
  48 +
  49 + <select id="selectMenuNormalByMenuIds" resultMap="MenuResult" parameterType="String">
  50 + select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.visible, m.is_refresh, ifnull(m.perms,'') as perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time
  51 + from sys_menu m
  52 + <where>
  53 + <if test="ids != null">
  54 + menu_id in
  55 + <foreach item="id" collection="array" open="(" separator=","
  56 + close=")">
  57 + #{id}
  58 + </foreach>
  59 + </if>
  60 + and m.menu_type in ('M', 'C')
  61 + and m.visible = 0
  62 + </where>
  63 +
  64 + order by m.parent_id, m.order_num
  65 + </select>
  66 +
48 67  
49 68 <select id="selectMenuAll" resultMap="MenuResult">
50 69 <include refid="selectMenuVo"/>
... ...