Commit a13f40e1b9f01d919777fd9975d91c48cc96775b
1 parent
9227cfcc
1
Showing
7 changed files
with
146 additions
and
44 deletions
bsthLineProfiles/pom.xml
| @@ -287,6 +287,19 @@ | @@ -287,6 +287,19 @@ | ||
| 287 | <artifactId>poi-ooxml</artifactId> | 287 | <artifactId>poi-ooxml</artifactId> |
| 288 | <version>${poi.version}</version> | 288 | <version>${poi.version}</version> |
| 289 | </dependency> | 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 | </dependencies> | 304 | </dependencies> |
| 292 | 305 |
bsthLineProfiles/src/main/java/com/ruoyi/framework/web/service/TokenService.java
| @@ -50,17 +50,11 @@ public class TokenService | @@ -50,17 +50,11 @@ public class TokenService | ||
| 50 | * | 50 | * |
| 51 | * @return 用户信息 | 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 | if (StringUtils.isNotEmpty(token)) | 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 | return user; | 58 | return user; |
| 65 | } | 59 | } |
| 66 | return null; | 60 | return null; |
| @@ -174,10 +168,7 @@ public class TokenService | @@ -174,10 +168,7 @@ public class TokenService | ||
| 174 | */ | 168 | */ |
| 175 | private Claims parseToken(String token) | 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,4 +121,6 @@ public interface MenuMapper | ||
| 121 | * @return 结果 | 121 | * @return 结果 |
| 122 | */ | 122 | */ |
| 123 | public Menu checkMenuNameUnique(@Param("menuName") String menuName, @Param("parentId") Long parentId); | 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,4 +124,6 @@ public interface IMenuService | ||
| 124 | * @return 结果 | 124 | * @return 结果 |
| 125 | */ | 125 | */ |
| 126 | public String checkMenuNameUnique(Menu menu); | 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,17 +48,22 @@ public class MenuServiceImpl implements IMenuService | ||
| 48 | { | 48 | { |
| 49 | List<Menu> menus = new LinkedList<Menu>(); | 49 | List<Menu> menus = new LinkedList<Menu>(); |
| 50 | // 管理员显示所有菜单信息 | 50 | // 管理员显示所有菜单信息 |
| 51 | - if (user.isAdmin()) | ||
| 52 | - { | 51 | +// if (user.isAdmin()) |
| 52 | +// { | ||
| 53 | menus = menuMapper.selectMenuNormalAll(); | 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 | return TreeUtils.getChildPerms(menus, 0); | 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,4 +326,6 @@ public class MenuServiceImpl implements IMenuService | ||
| 321 | } | 326 | } |
| 322 | return UserConstants.MENU_NAME_UNIQUE; | 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 | package com.ruoyi.project.system.user.controller; | 1 | package com.ruoyi.project.system.user.controller; |
| 2 | 2 | ||
| 3 | +import java.util.ArrayList; | ||
| 3 | import java.util.Date; | 4 | import java.util.Date; |
| 5 | +import java.util.HashMap; | ||
| 4 | import java.util.List; | 6 | import java.util.List; |
| 7 | +import java.util.Map; | ||
| 5 | 8 | ||
| 6 | -import javax.servlet.http.Cookie; | ||
| 7 | import javax.servlet.http.HttpServletRequest; | 9 | import javax.servlet.http.HttpServletRequest; |
| 8 | import javax.servlet.http.HttpServletResponse; | 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 | import org.apache.shiro.SecurityUtils; | 19 | import org.apache.shiro.SecurityUtils; |
| 11 | import org.apache.shiro.authc.AuthenticationException; | 20 | import org.apache.shiro.authc.AuthenticationException; |
| 12 | import org.apache.shiro.authc.UsernamePasswordToken; | 21 | import org.apache.shiro.authc.UsernamePasswordToken; |
| @@ -18,6 +27,9 @@ import org.springframework.web.bind.annotation.GetMapping; | @@ -18,6 +27,9 @@ import org.springframework.web.bind.annotation.GetMapping; | ||
| 18 | import org.springframework.web.bind.annotation.PostMapping; | 27 | import org.springframework.web.bind.annotation.PostMapping; |
| 19 | import org.springframework.web.bind.annotation.ResponseBody; | 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 | import com.ruoyi.common.utils.DateUtils; | 33 | import com.ruoyi.common.utils.DateUtils; |
| 22 | import com.ruoyi.common.utils.ServletUtils; | 34 | import com.ruoyi.common.utils.ServletUtils; |
| 23 | import com.ruoyi.common.utils.StringUtils; | 35 | import com.ruoyi.common.utils.StringUtils; |
| @@ -26,13 +38,15 @@ import com.ruoyi.framework.config.RuoYiConfig; | @@ -26,13 +38,15 @@ import com.ruoyi.framework.config.RuoYiConfig; | ||
| 26 | import com.ruoyi.framework.shiro.service.PasswordService; | 38 | import com.ruoyi.framework.shiro.service.PasswordService; |
| 27 | import com.ruoyi.framework.web.controller.BaseController; | 39 | import com.ruoyi.framework.web.controller.BaseController; |
| 28 | import com.ruoyi.framework.web.domain.AjaxResult; | 40 | import com.ruoyi.framework.web.domain.AjaxResult; |
| 41 | +import com.ruoyi.framework.web.service.PermissionService; | ||
| 29 | import com.ruoyi.framework.web.service.TokenService; | 42 | import com.ruoyi.framework.web.service.TokenService; |
| 30 | import com.ruoyi.project.system.config.service.IConfigService; | 43 | import com.ruoyi.project.system.config.service.IConfigService; |
| 31 | import com.ruoyi.project.system.menu.domain.Menu; | 44 | import com.ruoyi.project.system.menu.domain.Menu; |
| 32 | import com.ruoyi.project.system.menu.service.IMenuService; | 45 | import com.ruoyi.project.system.menu.service.IMenuService; |
| 33 | -import com.ruoyi.project.system.menu.service.MenuServiceImpl; | ||
| 34 | import com.ruoyi.project.system.user.domain.User; | 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,6 +69,7 @@ public class LoginController extends BaseController | ||
| 55 | 69 | ||
| 56 | @Autowired | 70 | @Autowired |
| 57 | private RuoYiConfig ruoYiConfig; | 71 | private RuoYiConfig ruoYiConfig; |
| 72 | + | ||
| 58 | 73 | ||
| 59 | @GetMapping("/login") | 74 | @GetMapping("/login") |
| 60 | public String login(HttpServletRequest request, HttpServletResponse response) | 75 | public String login(HttpServletRequest request, HttpServletResponse response) |
| @@ -74,16 +89,55 @@ public class LoginController extends BaseController | @@ -74,16 +89,55 @@ public class LoginController extends BaseController | ||
| 74 | 89 | ||
| 75 | if(token != null) { | 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 | mmap.put("user", user); | 140 | mmap.put("user", user); |
| 85 | - mmap.put("sideTheme", "theme-dark"); | ||
| 86 | - mmap.put("skinName", "skin-blue"); | ||
| 87 | mmap.put("ignoreFooter", configService.selectConfigByKey("sys.index.ignoreFooter")); | 141 | mmap.put("ignoreFooter", configService.selectConfigByKey("sys.index.ignoreFooter")); |
| 88 | mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear()); | 142 | mmap.put("copyrightYear", ruoYiConfig.getCopyrightYear()); |
| 89 | mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled()); | 143 | mmap.put("demoEnabled", ruoYiConfig.isDemoEnabled()); |
| @@ -95,23 +149,12 @@ public class LoginController extends BaseController | @@ -95,23 +149,12 @@ public class LoginController extends BaseController | ||
| 95 | // 移动端,默认使左侧导航菜单,否则取默认配置 | 149 | // 移动端,默认使左侧导航菜单,否则取默认配置 |
| 96 | String indexStyle = ServletUtils.checkAgentIsMobile(ServletUtils.getRequest().getHeader("User-Agent")) ? "index" : menuStyle; | 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 | return "index"; | 153 | return "index"; |
| 110 | 154 | ||
| 111 | - }else { | ||
| 112 | - return "login"; | ||
| 113 | } | 155 | } |
| 114 | - | 156 | + |
| 157 | + } | ||
| 115 | // User loginUser = tokenService.getUser(ServletUtils.getRequest()); | 158 | // User loginUser = tokenService.getUser(ServletUtils.getRequest()); |
| 116 | 159 | ||
| 117 | 160 | ||
| @@ -121,10 +164,35 @@ public class LoginController extends BaseController | @@ -121,10 +164,35 @@ public class LoginController extends BaseController | ||
| 121 | // subject.login(token); | 164 | // subject.login(token); |
| 122 | // return success(); | 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 | public boolean initPasswordIsModify(Date pwdUpdateDate) | 197 | public boolean initPasswordIsModify(Date pwdUpdateDate) |
| 130 | { | 198 | { |
bsthLineProfiles/src/main/resources/mybatis/system/MenuMapper.xml
| @@ -45,6 +45,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -45,6 +45,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 45 | where m.menu_type in ('M', 'C') and m.visible = 0 | 45 | where m.menu_type in ('M', 'C') and m.visible = 0 |
| 46 | order by m.parent_id, m.order_num | 46 | order by m.parent_id, m.order_num |
| 47 | </select> | 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 | <select id="selectMenuAll" resultMap="MenuResult"> | 68 | <select id="selectMenuAll" resultMap="MenuResult"> |
| 50 | <include refid="selectMenuVo"/> | 69 | <include refid="selectMenuVo"/> |