parent
a78b4f3fc1
commit
0ad5f18336
|
@ -109,6 +109,25 @@ public class JwtUtils {
|
||||||
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据令牌获取公司标识
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCompanySign (String token) {
|
||||||
|
Claims claims = parseToken(token);
|
||||||
|
return getValue(claims, SecurityConstants.COMPANY_SIGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据身份信息获取公司标识
|
||||||
|
* @param claims
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCompanySign (Claims claims) {
|
||||||
|
return getValue(claims, SecurityConstants.COMPANY_SIGN);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据身份信息获取键值
|
* 根据身份信息获取键值
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,12 +36,8 @@ public class SecurityUtils {
|
||||||
/**
|
/**
|
||||||
* 获取公司标识
|
* 获取公司标识
|
||||||
*/
|
*/
|
||||||
public static String formatToken (String token) {
|
public static String getCompanySign () {
|
||||||
// 如果前端设置了令牌前缀,则裁剪掉前缀
|
return SecurityContextHolder.getCompanySign();
|
||||||
if (StringUtils.isNotEmpty(token) && token.startsWith(TokenConstants.PREFIX)) {
|
|
||||||
token = token.replaceFirst(TokenConstants.PREFIX, StringUtils.EMPTY);
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -66,11 +66,13 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||||
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
|
if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
|
||||||
return unauthorizedResponse(exchange, "令牌验证失败");
|
return unauthorizedResponse(exchange, "令牌验证失败");
|
||||||
}
|
}
|
||||||
|
String companySign = JwtUtils.getCompanySign(claims);
|
||||||
|
|
||||||
// 设置用户信息到请求
|
// 设置用户信息到请求
|
||||||
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
|
addHeader(mutate, SecurityConstants.USER_KEY, userkey);
|
||||||
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
|
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
|
||||||
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
|
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
|
||||||
|
addHeader(mutate, SecurityConstants.COMPANY_SIGN, companySign);
|
||||||
// 内部请求来源参数清除
|
// 内部请求来源参数清除
|
||||||
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
|
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
|
||||||
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||||
|
|
|
@ -36,8 +36,7 @@ public class SysDeptController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysDeptService deptService;
|
private SysDeptService deptService;
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门列表
|
* 获取部门列表
|
||||||
|
@ -45,8 +44,7 @@ public class SysDeptController extends BaseController {
|
||||||
@RequiresPermissions("system:dept:list")
|
@RequiresPermissions("system:dept:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public Result list (SysDept dept, HttpServletRequest request) {
|
public Result list (SysDept dept, HttpServletRequest request) {
|
||||||
String companySign = getCompanySign(request);
|
dept.setCompanySign(SecurityUtils.getCompanySign());
|
||||||
dept.setCompanySign(companySign);
|
|
||||||
List<SysDept> depts = deptService.selectDeptList(dept);
|
List<SysDept> depts = deptService.selectDeptList(dept);
|
||||||
return success(depts);
|
return success(depts);
|
||||||
}
|
}
|
||||||
|
@ -124,15 +122,15 @@ public class SysDeptController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getCompanySign(HttpServletRequest request){
|
// public String getCompanySign(HttpServletRequest request){
|
||||||
Cookie[] cookies = request.getCookies();
|
// Cookie[] cookies = request.getCookies();
|
||||||
for (Cookie cookie : cookies) {
|
// for (Cookie cookie : cookies) {
|
||||||
if ("companySign".equals(cookie.getName())){
|
// if ("companySign".equals(cookie.getName())){
|
||||||
return cookie.getValue();
|
// return cookie.getValue();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
throw new RuntimeException("公司标识无法获取");
|
// throw new RuntimeException("公司标识无法获取");
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,6 +288,8 @@ public class SysUserController extends BaseController {
|
||||||
@RequiresPermissions("system:user:list")
|
@RequiresPermissions("system:user:list")
|
||||||
@GetMapping("/deptTree")
|
@GetMapping("/deptTree")
|
||||||
public Result deptTree (SysDept dept) {
|
public Result deptTree (SysDept dept) {
|
||||||
|
String companySign = SecurityUtils.getCompanySign();
|
||||||
|
dept.setCompanySign(companySign);
|
||||||
return success(deptService.selectDeptTreeList(dept));
|
return success(deptService.selectDeptTreeList(dept));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,9 @@
|
||||||
<select id="selectDeptList" parameterType="com.zhilian.common.system.domain.SysDept" resultMap="SysDeptResult">
|
<select id="selectDeptList" parameterType="com.zhilian.common.system.domain.SysDept" resultMap="SysDeptResult">
|
||||||
<include refid="selectDeptVo"/>
|
<include refid="selectDeptVo"/>
|
||||||
where d.del_flag = '0'
|
where d.del_flag = '0'
|
||||||
<choose>
|
<if test="companySign != null and companySign != '' and 'ZL' != companySign">
|
||||||
<when test="'ZL' == companySign">
|
and d.company_sign = #{companySign}
|
||||||
</when>
|
</if>
|
||||||
<otherwise>
|
|
||||||
and d.company_sign = #{companySign,jdbcType=VARCHAR}
|
|
||||||
</otherwise>
|
|
||||||
</choose>
|
|
||||||
<if test="deptId != null and deptId != 0">
|
<if test="deptId != null and deptId != 0">
|
||||||
AND dept_id = #{deptId}
|
AND dept_id = #{deptId}
|
||||||
</if>
|
</if>
|
||||||
|
|
Loading…
Reference in New Issue