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