作者 朱兆平

登录成功返回的json修改

正在显示 110 个修改的文件 包含 96 行增加26 行删除
@@ -27,4 +27,4 @@ kakoRevice/ @@ -27,4 +27,4 @@ kakoRevice/
27 /nbbuild/ 27 /nbbuild/
28 /dist/ 28 /dist/
29 /nbdist/ 29 /nbdist/
30 -/.nb-gradle/  
  30 +/.nb-gradle/
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
@@ -31,11 +31,11 @@ @@ -31,11 +31,11 @@
31 <artifactId>mybatis-spring-boot-starter</artifactId> 31 <artifactId>mybatis-spring-boot-starter</artifactId>
32 <version>1.3.2</version> 32 <version>1.3.2</version>
33 </dependency> 33 </dependency>
34 - <dependency>  
35 - <groupId>org.springframework.boot</groupId>  
36 - <artifactId>spring-boot-devtools</artifactId>  
37 - <optional>true</optional>  
38 - </dependency> 34 + <!--<dependency>-->
  35 + <!--<groupId>org.springframework.boot</groupId>-->
  36 + <!--<artifactId>spring-boot-devtools</artifactId>-->
  37 + <!--<optional>true</optional>-->
  38 + <!--</dependency>-->
39 <!--有WEBSOCKET包 包含了spring-boot-starter-web 和spring-boot-starter包 有这个包不要引入这俩包--> 39 <!--有WEBSOCKET包 包含了spring-boot-starter-web 和spring-boot-starter包 有这个包不要引入这俩包-->
40 <dependency> 40 <dependency>
41 <groupId>org.springframework.boot</groupId> 41 <groupId>org.springframework.boot</groupId>
@@ -49,6 +49,11 @@ @@ -49,6 +49,11 @@
49 </dependency> 49 </dependency>
50 <dependency> 50 <dependency>
51 <groupId>org.springframework.boot</groupId> 51 <groupId>org.springframework.boot</groupId>
  52 + <artifactId>spring-boot-configuration-processor</artifactId>
  53 + <optional>true</optional>
  54 + </dependency>
  55 + <dependency>
  56 + <groupId>org.springframework.boot</groupId>
52 <artifactId>spring-boot-starter-thymeleaf</artifactId> 57 <artifactId>spring-boot-starter-thymeleaf</artifactId>
53 </dependency> 58 </dependency>
54 <dependency> 59 <dependency>
  1 +package com.tianbo.warehouse.bean;
  2 +
  3 +import org.springframework.security.core.Authentication;
  4 +
  5 +import java.io.Serializable;
  6 +import java.util.Map;
  7 +
  8 +public class AuthSuccessResponse implements Serializable{
  9 +
  10 + private static final long serialVersionUID = 1L;
  11 +
  12 + private Authentication authentication;
  13 +
  14 + private Map<String,Object> loginUserMenus;
  15 +
  16 + public AuthSuccessResponse (Authentication authentication,Map<String,Object> loginUserMenus){
  17 + this.authentication= authentication;
  18 + this.loginUserMenus = loginUserMenus;
  19 + }
  20 +
  21 + public Authentication getAuthentication() {
  22 + return authentication;
  23 + }
  24 +
  25 + public void setAuthentication(Authentication authentication) {
  26 + this.authentication = authentication;
  27 + }
  28 +
  29 + public Map<String, Object> getLoginUserMenus() {
  30 + return loginUserMenus;
  31 + }
  32 +
  33 + public void setLoginUserMenus(Map<String, Object> loginUserMenus) {
  34 + this.loginUserMenus = loginUserMenus;
  35 + }
  36 +}
@@ -44,17 +44,4 @@ public class PermssionController { @@ -44,17 +44,4 @@ public class PermssionController {
44 } 44 }
45 return resultJson; 45 return resultJson;
46 } 46 }
47 -  
48 - @GetMapping("/perm/userMenus")  
49 - public Map<String,Object> getLoginUserMenus(){  
50 -  
51 - try{  
52 - UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();  
53 - int i;  
54 - }catch (Exception e){  
55 - e.printStackTrace();  
56 - }  
57 - Map<String,Object> menuMap = permissionService.getUserMenus();  
58 - return menuMap;  
59 - }  
60 } 47 }
1 package com.tianbo.warehouse.security.handel; 1 package com.tianbo.warehouse.security.handel;
2 2
3 import com.fasterxml.jackson.databind.ObjectMapper; 3 import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.tianbo.warehouse.bean.AuthSuccessResponse;
  5 +import com.tianbo.warehouse.controller.PermssionController;
  6 +import com.tianbo.warehouse.model.PERMISSION;
  7 +import com.tianbo.warehouse.model.USERS;
4 import com.tianbo.warehouse.security.model.LoginType; 8 import com.tianbo.warehouse.security.model.LoginType;
  9 +import com.tianbo.warehouse.service.PermissionService;
5 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory; 11 import org.apache.commons.logging.LogFactory;
7 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +24,7 @@ import javax.servlet.ServletException; @@ -19,6 +24,7 @@ import javax.servlet.ServletException;
19 import javax.servlet.http.HttpServletRequest; 24 import javax.servlet.http.HttpServletRequest;
20 import javax.servlet.http.HttpServletResponse; 25 import javax.servlet.http.HttpServletResponse;
21 import java.io.IOException; 26 import java.io.IOException;
  27 +import java.util.Map;
22 28
23 /** 29 /**
24 * 登录成功后的返回处理 30 * 登录成功后的返回处理
@@ -30,6 +36,8 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat @@ -30,6 +36,8 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
30 @Autowired 36 @Autowired
31 private ObjectMapper objectMapper; 37 private ObjectMapper objectMapper;
32 38
  39 + @Autowired
  40 + private PermissionService permissionService;
33 private RequestCache requestCache = new HttpSessionRequestCache(); 41 private RequestCache requestCache = new HttpSessionRequestCache();
34 42
35 @Autowired 43 @Autowired
@@ -42,7 +50,9 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat @@ -42,7 +50,9 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
42 //将 authention 信息打包成json格式返回 50 //将 authention 信息打包成json格式返回
43 response.setContentType("application/json;charset=UTF-8"); 51 response.setContentType("application/json;charset=UTF-8");
44 response.setHeader("Access-Control-Allow-Origin","*"); 52 response.setHeader("Access-Control-Allow-Origin","*");
45 - response.getWriter().write(objectMapper.writeValueAsString(authentication)); 53 + USERS loginedUser = (USERS) authentication.getPrincipal();
  54 + Map<String,Object> menuMap = permissionService.getUserMenus(loginedUser.getUserId());
  55 + response.getWriter().write(objectMapper.writeValueAsString(new AuthSuccessResponse(authentication,menuMap)));
46 }else { 56 }else {
47 //走原来的处理流程 57 //走原来的处理流程
48 SavedRequest savedRequest = this.requestCache.getRequest(request, response); 58 SavedRequest savedRequest = this.requestCache.getRequest(request, response);
@@ -12,5 +12,10 @@ public interface PermissionService { @@ -12,5 +12,10 @@ public interface PermissionService {
12 12
13 int insertSelective(PERMISSION record); 13 int insertSelective(PERMISSION record);
14 14
15 - Map<String,Object> getUserMenus(); 15 + /**
  16 + * 获取登录用户可访问的权限menus列表
  17 + * @param userId
  18 + * @return
  19 + */
  20 + Map<String,Object> getUserMenus(Integer userId);
16 } 21 }
@@ -32,11 +32,11 @@ public class PermissionServiceImp implements PermissionService{ @@ -32,11 +32,11 @@ public class PermissionServiceImp implements PermissionService{
32 } 32 }
33 33
34 @Override 34 @Override
35 - public Map<String,Object> getUserMenus(){ 35 + public Map<String,Object> getUserMenus(Integer userId){
36 Map<String,Object> data = new HashMap<String,Object>(); 36 Map<String,Object> data = new HashMap<String,Object>();
37 try { 37 try {
38 //查询所有菜单 38 //查询所有菜单
39 - List<PERMISSION> allMenu = permissionMapper.getAllMenus(); 39 + List<PERMISSION> allMenu = permissionMapper.findByUserId(userId);
40 //根节点 40 //根节点
41 List<PERMISSION> rootMenu = new ArrayList<PERMISSION>(); 41 List<PERMISSION> rootMenu = new ArrayList<PERMISSION>();
42 for (PERMISSION nav : allMenu) { 42 for (PERMISSION nav : allMenu) {
@@ -32,9 +32,36 @@ @@ -32,9 +32,36 @@
32 </select> 32 </select>
33 33
34 <select id="getAllMenus" resultMap="BaseResultMap" > 34 <select id="getAllMenus" resultMap="BaseResultMap" >
35 - select  
36 - <include refid="Base_Column_List" />  
37 - from permission where ismenu is TRUE ORDER BY permission_order 35 + SELECT
  36 + P .*
  37 + FROM
  38 + permission P
  39 + WHERE
  40 + P .PERMISSION_ID IN (
  41 + SELECT
  42 + RP.permission_id
  43 + FROM
  44 + ROLE_PERMISSION RP
  45 + WHERE
  46 + RP.role_id IN (
  47 + SELECT
  48 + R.ROLE_ID
  49 + FROM
  50 + role R
  51 + WHERE
  52 + R.ROLE_ID IN (
  53 + SELECT
  54 + UR.ROLE_ID
  55 + FROM
  56 + USER_ROLE UR
  57 + WHERE
  58 + UR.USER_ID = #{userId,jdbcType=INTEGER} AND P.ismenu is TRUE
  59 + )
  60 + )
  61 + ) ORDER BY P.permission_order
  62 + <!--select-->
  63 + <!--<include refid="Base_Column_List" />-->
  64 + <!--from permission where ismenu is TRUE ORDER BY permission_order-->
38 </select> 65 </select>
39 <select id="findRoleListByUrl" resultType="java.lang.String" parameterType="java.lang.String"> 66 <select id="findRoleListByUrl" resultType="java.lang.String" parameterType="java.lang.String">
40 SELECT 67 SELECT