Commit fd5e68ec by wqc

单点登录调整

parent 9b7e55b6
...@@ -29,6 +29,9 @@ public interface SysFeign { ...@@ -29,6 +29,9 @@ public interface SysFeign {
@PostMapping("/api/user/modifyPasswd") @PostMapping("/api/user/modifyPasswd")
ResultVo modifyPasswd(@RequestBody Map<String, Object> paramsMap); ResultVo modifyPasswd(@RequestBody Map<String, Object> paramsMap);
@PostMapping("/sso/verifyToken")
ResultVo getVerifyToken(@RequestBody Map<String, Object> paramsMap);
@GetMapping("/api/version/getAppVersion") @GetMapping("/api/version/getAppVersion")
ResultVo getAppVersion(@RequestParam String appName); ResultVo getAppVersion(@RequestParam String appName);
......
...@@ -112,6 +112,9 @@ public interface IApiLogic extends IApiCommon { ...@@ -112,6 +112,9 @@ public interface IApiLogic extends IApiCommon {
@ApiMethod(name = "单点登出", service = "SYS-SERVER") @ApiMethod(name = "单点登出", service = "SYS-SERVER")
ApiResp ssoLogout(ApiForm form); ApiResp ssoLogout(ApiForm form);
@ApiMethod(name = "验证token有效", service = "SYS-SERVER")
ApiResp getVerifyToken(ApiForm form);
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓开放接口↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓开放接口↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
......
...@@ -51,6 +51,11 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic { ...@@ -51,6 +51,11 @@ public class ApiV100Logic extends BaseApiLogic implements IApiLogic {
} }
@Override @Override
public ApiResp getVerifyToken(ApiForm form) {
return ApiUtils.toApiResp(form, sysFeign.getVerifyToken(form.getParamsMap()));
}
@Override
public ApiResp modifyPasswd(ApiForm form) { public ApiResp modifyPasswd(ApiForm form) {
return ApiUtils.toApiResp(form, sysFeign.modifyPasswd(form.getParamsMap())); return ApiUtils.toApiResp(form, sysFeign.modifyPasswd(form.getParamsMap()));
} }
......
...@@ -177,6 +177,11 @@ ...@@ -177,6 +177,11 @@
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
<version>2.12.0</version> <version>2.12.0</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository; ...@@ -6,4 +6,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface SysInfoDao extends BaseMapper<SysInfo> { public interface SysInfoDao extends BaseMapper<SysInfo> {
void updateByappId(SysInfo build);
} }
...@@ -74,6 +74,10 @@ public class User extends BaseEntity implements Serializable { ...@@ -74,6 +74,10 @@ public class User extends BaseEntity implements Serializable {
@ApiModelProperty(value = "用户昵称") @ApiModelProperty(value = "用户昵称")
private String nickName; private String nickName;
@NotBlank
@ApiModelProperty(value = "用户所属区域")
private String userArea;
@Email @Email
//@NotBlank //@NotBlank
@ApiModelProperty(value = "邮箱") @ApiModelProperty(value = "邮箱")
......
...@@ -19,4 +19,14 @@ public class SsoLoginVo { ...@@ -19,4 +19,14 @@ public class SsoLoginVo {
private String uuid = ""; private String uuid = "";
private String loginToken;
private String loginKey;
private String appId;
private String systemName;
private String systemTag;
} }
...@@ -42,6 +42,12 @@ public class SysInfo { ...@@ -42,6 +42,12 @@ public class SysInfo {
@ApiModelProperty("状态 0-禁用 1-启用") @ApiModelProperty("状态 0-禁用 1-启用")
private Integer state; private Integer state;
@ApiModelProperty("生成的token")
private String loginToken;
@ApiModelProperty("生成的key")
private String loginKey;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
private Date createTime; private Date createTime;
......
package com.zq.system.modules.system.rest; package com.zq.system.modules.system.rest;
import cn.hutool.core.lang.tree.TreeUtil;
import com.zq.common.annotation.rest.AnonymousGetMapping; import com.zq.common.annotation.rest.AnonymousGetMapping;
import com.zq.common.annotation.rest.AnonymousPostMapping; import com.zq.common.annotation.rest.AnonymousPostMapping;
import com.zq.common.config.redis.RedisUtils; import com.zq.common.config.redis.RedisUtils;
...@@ -11,6 +12,7 @@ import com.zq.system.exception.BadRequestException; ...@@ -11,6 +12,7 @@ import com.zq.system.exception.BadRequestException;
import com.zq.system.modules.system.domain.User; import com.zq.system.modules.system.domain.User;
import com.zq.system.modules.system.domain.vo.SsoLoginVo; import com.zq.system.modules.system.domain.vo.SsoLoginVo;
import com.zq.system.modules.system.domain.vo.SsoRegisterVo; import com.zq.system.modules.system.domain.vo.SsoRegisterVo;
import com.zq.system.modules.system.entity.AreaCode;
import com.zq.system.modules.system.service.AuthUserDto; import com.zq.system.modules.system.service.AuthUserDto;
import com.zq.system.modules.system.service.SsoService; import com.zq.system.modules.system.service.SsoService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -54,8 +56,8 @@ public class SsoController { ...@@ -54,8 +56,8 @@ public class SsoController {
@ApiOperation("token单点登录") @ApiOperation("token单点登录")
@PostMapping(value = "/tokenLogin") @PostMapping(value = "/tokenLogin")
public ResultVo tokenLogin(HttpServletRequest request, HttpServletResponse response) { public ResultVo tokenLogin(@RequestBody SsoLoginVo vo,HttpServletRequest request, HttpServletResponse response) {
return ResultVo.success(ssoService.tokenLogin(request, response)); return ResultVo.success(ssoService.tokenLogin(vo,request, response));
} }
@ApiOperation("单点登出") @ApiOperation("单点登出")
...@@ -98,6 +100,15 @@ public class SsoController { ...@@ -98,6 +100,15 @@ public class SsoController {
return ResultVo.success(); return ResultVo.success();
} }
@ApiOperation("验证token和key")
@PostMapping(value = "/verifyToken")
public ResultVo verifyToken(@RequestParam String loginToken,String loginKey ,HttpServletRequest request, HttpServletResponse response) {
AssertUtils.notNull(loginToken,"token不为空");
AssertUtils.notNull(loginKey,"key不为空");
return ResultVo.success(ssoService.verifyToken(loginToken,loginKey,request,response));
}
@ApiOperation("用户绑定的系统列表") @ApiOperation("用户绑定的系统列表")
@GetMapping(value = "/getBindSysList") @GetMapping(value = "/getBindSysList")
public ResultVo getBindSysList() { public ResultVo getBindSysList() {
...@@ -127,4 +138,11 @@ public class SsoController { ...@@ -127,4 +138,11 @@ public class SsoController {
AssertUtils.hasText(vo.getPassword(), "缺少密码"); AssertUtils.hasText(vo.getPassword(), "缺少密码");
return ResultVo.success(ssoService.verifyPasswd(vo)); return ResultVo.success(ssoService.verifyPasswd(vo));
} }
@ApiOperation("选择地区")
@AnonymousPostMapping(value = "/selectArea")
public ResultVo selectArea() {
return ResultVo.success(ssoService.selectArea());
}
} }
package com.zq.system.modules.system.service; package com.zq.system.modules.system.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
...@@ -17,6 +18,7 @@ import com.zq.common.vo.ResultVo; ...@@ -17,6 +18,7 @@ import com.zq.common.vo.ResultVo;
import com.zq.system.config.CacheKeys; import com.zq.system.config.CacheKeys;
import com.zq.system.config.RsaProperties; import com.zq.system.config.RsaProperties;
import com.zq.system.config.security.TokenProvider; import com.zq.system.config.security.TokenProvider;
import com.zq.system.modules.system.dao.AreaCodeDao;
import com.zq.system.modules.system.dao.BlindUserInfoDao; import com.zq.system.modules.system.dao.BlindUserInfoDao;
import com.zq.system.modules.system.dao.SysInfoDao; import com.zq.system.modules.system.dao.SysInfoDao;
import com.zq.system.modules.system.domain.Job; import com.zq.system.modules.system.domain.Job;
...@@ -24,6 +26,7 @@ import com.zq.system.modules.system.domain.Role; ...@@ -24,6 +26,7 @@ import com.zq.system.modules.system.domain.Role;
import com.zq.system.modules.system.domain.User; import com.zq.system.modules.system.domain.User;
import com.zq.system.modules.system.domain.vo.SsoLoginVo; import com.zq.system.modules.system.domain.vo.SsoLoginVo;
import com.zq.system.modules.system.domain.vo.SsoRegisterVo; import com.zq.system.modules.system.domain.vo.SsoRegisterVo;
import com.zq.system.modules.system.entity.AreaCode;
import com.zq.system.modules.system.entity.BindUserInfo; import com.zq.system.modules.system.entity.BindUserInfo;
import com.zq.system.modules.system.entity.SysInfo; import com.zq.system.modules.system.entity.SysInfo;
import com.zq.system.modules.system.repository.DeptRepository; import com.zq.system.modules.system.repository.DeptRepository;
...@@ -70,6 +73,7 @@ public class SsoService { ...@@ -70,6 +73,7 @@ public class SsoService {
private final RedisUtils redisUtils; private final RedisUtils redisUtils;
private final AuthenticationManagerBuilder authenticationManagerBuilder; private final AuthenticationManagerBuilder authenticationManagerBuilder;
private final TokenProvider tokenProvider; private final TokenProvider tokenProvider;
private final AreaCodeDao areaCodeDao;
public void register(SsoRegisterVo vo) { public void register(SsoRegisterVo vo) {
String passwd = null; String passwd = null;
...@@ -90,6 +94,7 @@ public class SsoService { ...@@ -90,6 +94,7 @@ public class SsoService {
resources.setNickName(vo.getNickName()); resources.setNickName(vo.getNickName());
resources.setPhone(vo.getPhone()); resources.setPhone(vo.getPhone());
resources.setUsername(vo.getUsername()); resources.setUsername(vo.getUsername());
resources.setUserArea(vo.getUserArea());
List<Role> roleList = roleRepository.findAllById(Collections.singletonList(8L)); List<Role> roleList = roleRepository.findAllById(Collections.singletonList(8L));
resources.setRoles(new HashSet<>(roleList)); resources.setRoles(new HashSet<>(roleList));
...@@ -164,10 +169,6 @@ public class SsoService { ...@@ -164,10 +169,6 @@ public class SsoService {
String toUrl = request.getParameter("service"); String toUrl = request.getParameter("service");
AssertUtils.hasText(toUrl, "跳转地址为空"); AssertUtils.hasText(toUrl, "跳转地址为空");
/* SysInfo sysInfo = sysInfoDao.selectOne(Wrappers.lambdaQuery(SysInfo.builder().appId(appId).build()));
AssertUtils.notNull(sysInfo, "APPID不存在");
AssertUtils.hasText(sysInfo.getHomeUrl(), "业务系统主页地址未配置");*/
String passwd = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, vo.getPasswd()); String passwd = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, vo.getPasswd());
UsernamePasswordAuthenticationToken authenticationToken = UsernamePasswordAuthenticationToken authenticationToken =
...@@ -186,6 +187,20 @@ public class SsoService { ...@@ -186,6 +187,20 @@ public class SsoService {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("toUrl", toUrl + "?" + properties.getHeader() + "=" + token + "&key=" + key); data.put("toUrl", toUrl + "?" + properties.getHeader() + "=" + token + "&key=" + key);
data.put(properties.getHeader(), properties.getTokenStartWith() + token); data.put(properties.getHeader(), properties.getTokenStartWith() + token);
//
// SysInfo sysInfo = sysInfoDao.selectOne(Wrappers.lambdaQuery(SysInfo.builder().appId(vo.getAppId()).build()));
// AssertUtils.hasText(sysInfo.getAppId(), "APPID不存在");
// AssertUtils.hasText(sysInfo.getHomeUrl(), "业务系统主页地址未配置");
// SysInfo build =SysInfo.builder()
// .appId(sysInfo.getAppId())
// .loginKey(key)
// .loginToken(token)
// .systemName(vo.getSystemName())
// .systemTag(vo.getSystemTag())
// .state(1)
// .createTime(DateUtil.date())
// .build();
// sysInfoDao.update(build,Wrappers.lambdaQuery(SysInfo.class));
return data; return data;
// response.sendRedirect(sysInfo.getHomeUrl() + "?" + properties.getHeader() + "=" + token + "&key=" + key); // response.sendRedirect(sysInfo.getHomeUrl() + "?" + properties.getHeader() + "=" + token + "&key=" + key);
} catch (Exception e) { } catch (Exception e) {
...@@ -195,7 +210,7 @@ public class SsoService { ...@@ -195,7 +210,7 @@ public class SsoService {
} }
public Object tokenLogin(HttpServletRequest request, HttpServletResponse response) { public Object tokenLogin(SsoLoginVo vo,HttpServletRequest request, HttpServletResponse response) {
String toUrl = request.getParameter("service"); String toUrl = request.getParameter("service");
AssertUtils.hasText(toUrl, "跳转地址为空"); AssertUtils.hasText(toUrl, "跳转地址为空");
...@@ -209,6 +224,21 @@ public class SsoService { ...@@ -209,6 +224,21 @@ public class SsoService {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("toUrl", toUrl + "?" + properties.getHeader() + "=" + token + "&key=" + key); data.put("toUrl", toUrl + "?" + properties.getHeader() + "=" + token + "&key=" + key);
data.put(properties.getHeader(), properties.getTokenStartWith() + token); data.put(properties.getHeader(), properties.getTokenStartWith() + token);
// if () {
SysInfo sysInfo = sysInfoDao.selectOne(Wrappers.lambdaQuery(SysInfo.builder().appId(vo.getAppId()).build()));
AssertUtils.hasText(sysInfo.getAppId(), "APPID不存在");
AssertUtils.hasText(sysInfo.getHomeUrl(), "业务系统主页地址未配置");
SysInfo build = SysInfo.builder()
.appId(sysInfo.getAppId())
.loginKey(key)
.loginToken(token)
.systemName(vo.getSystemName())
.systemTag(vo.getSystemTag())
.state(1)
.createTime(DateUtil.date())
.build();
sysInfoDao.updateByappId(build);
// }
return data; return data;
// response.sendRedirect(sysInfo.getHomeUrl() + "?" + properties.getHeader() + "=" + token + "&key=" + key); // response.sendRedirect(sysInfo.getHomeUrl() + "?" + properties.getHeader() + "=" + token + "&key=" + key);
} }
...@@ -262,4 +292,18 @@ public class SsoService { ...@@ -262,4 +292,18 @@ public class SsoService {
AssertUtils.isTrue(StringUtils.isNotBlank(cacheCode) && cacheCode.equalsIgnoreCase(code), "验证码错误"); AssertUtils.isTrue(StringUtils.isNotBlank(cacheCode) && cacheCode.equalsIgnoreCase(code), "验证码错误");
redisUtils.deleteStr(CacheKeys.authCodeKey(phone)); redisUtils.deleteStr(CacheKeys.authCodeKey(phone));
} }
public ResultVo verifyToken(String loginToken,String loginKey, HttpServletRequest request, HttpServletResponse response) {
SysInfo sysInfo = sysInfoDao.selectOne(Wrappers.lambdaQuery(SysInfo.builder().loginToken(loginToken).loginKey(loginKey).build()));
if (sysInfo==null){
return ResultVo.success(sysInfo.getAppId());
}else{
return ResultVo.fail("校验失败");
}
}
public Object selectArea() {
return areaCodeDao.selectList(Wrappers.lambdaQuery(AreaCode.builder().admindivLevel("5").build()));
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zq.system.modules.system.dao.SysInfoDao">
<resultMap id="BaseResultMap" type="com.zq.system.modules.system.entity.SysInfo">
<!--@Table DATA_TABLE-->
<result property="id" column="id" jdbcType="OTHER"/>
<result property="appId" column="app_id" jdbcType="OTHER"/>
<result property="systemTag" column="system_tag" jdbcType="OTHER"/>
<result property="systemName" column="system_name" jdbcType="OTHER"/>
<result property="systemLogo" column="system_logo" jdbcType="OTHER"/>
<result property="homeUrl" column="home_url" jdbcType="OTHER"/>
<result property="loginUrl" column="login_url" jdbcType="OTHER"/>
<result property="state" column="state" jdbcType="OTHER"/>
<result property="loginToken" column="login_token" jdbcType="OTHER"/>
<result property="loginKey" column="login_key" jdbcType="OTHER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<update id="updateByappId">
update sys_info
<set>
<if test="appId != null">
app_id = #{appId, jdbcType=OTHER},
</if>
<if test="systemName != null">
system_name = #{systemName, jdbcType=OTHER},
</if>
<if test="systemTag != null">
system_tag = #{systemTag, jdbcType=OTHER},
</if>
<if test="loginToken != null">
login_token = #{loginToken, jdbcType=OTHER},
</if>
<if test="loginKey != null">
login_key = #{loginKey, jdbcType=OTHER},
</if>
<if test="createTime != null">
create_time = #{createTime, jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime, jdbcType=TIMESTAMP},
</if>
</set>
WHERE app_id = #{appId}
</update>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment