作者 朱兆平

登录成功返回的json修改

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