接入平台登录
parent
6a4d3f0be9
commit
a542ce39dc
|
|
@ -24,6 +24,6 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||||
.excludePathPatterns("/v3/api-docs**")
|
.excludePathPatterns("/v3/api-docs**")
|
||||||
.excludePathPatterns("/v1/sysuser/doLogin")
|
.excludePathPatterns("/v1/sysuser/doLogin")
|
||||||
.excludePathPatterns("/v1/auth/getToken")
|
.excludePathPatterns("/v1/auth/getToken")
|
||||||
;
|
.excludePathPatterns("/v1/sysuser/registerByToken");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package com.whdc.zhdbaqapi.controller;
|
package com.whdc.zhdbaqapi.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.whdc.zhdbaqapi.model.dto.FindSysUserDto;
|
import com.whdc.zhdbaqapi.model.dto.*;
|
||||||
import com.whdc.zhdbaqapi.model.dto.IdDto;
|
import com.whdc.zhdbaqapi.model.entity.ForeignUserInfo;
|
||||||
import com.whdc.zhdbaqapi.model.dto.LoginDto;
|
|
||||||
import com.whdc.zhdbaqapi.model.entity.SysUser;
|
import com.whdc.zhdbaqapi.model.entity.SysUser;
|
||||||
import com.whdc.zhdbaqapi.model.vo.AuthToken;
|
import com.whdc.zhdbaqapi.model.vo.AuthToken;
|
||||||
import com.whdc.zhdbaqapi.model.vo.LoginVo;
|
import com.whdc.zhdbaqapi.model.vo.LoginVo;
|
||||||
import com.whdc.zhdbaqapi.service.ISysUserService;
|
import com.whdc.zhdbaqapi.service.ISysUserService;
|
||||||
|
import com.whdc.zhdbaqapi.utils.HttpUtil;
|
||||||
import com.whdc.zhdbaqapi.utils.ResultJson;
|
import com.whdc.zhdbaqapi.utils.ResultJson;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
@ -87,4 +89,43 @@ public class SysUserController {
|
||||||
StpUtil.kickout(idDto.getId());
|
StpUtil.kickout(idDto.getId());
|
||||||
return ResultJson.ok("将用户[" + idDto.getId() + "]踢下线");
|
return ResultJson.ok("将用户[" + idDto.getId() + "]踢下线");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "token注册")
|
||||||
|
@PostMapping("registerByToken")
|
||||||
|
public ResultJson<SaTokenInfo> registerByToken(@RequestBody @Validated ForeignTokenDto dto) throws InvocationTargetException, IllegalAccessException {
|
||||||
|
String jstr = HttpUtil.get("http://220.203.2.194:20042/sys/loginByToken?token=" + dto.getToken());
|
||||||
|
System.out.println("=======================");
|
||||||
|
System.out.println(dto.getToken());
|
||||||
|
System.out.println(jstr);
|
||||||
|
ForeignResp resp = JSON.parseObject(jstr, ForeignResp.class);
|
||||||
|
if (resp.getCode() != 200) {
|
||||||
|
return ResultJson.error("登录失败");
|
||||||
|
}
|
||||||
|
ForeignUserInfo userInfo = resp.getResult().getUserInfo();
|
||||||
|
SysUser bean = new SysUser();
|
||||||
|
bean.setName(userInfo.getRealname());
|
||||||
|
bean.setType(9527);
|
||||||
|
bean.setLoginName(userInfo.getUsername());
|
||||||
|
bean.setPassword(null);
|
||||||
|
bean.setForeignId(userInfo.getId());
|
||||||
|
SysUser byForeignId = iSysUserService.getByForeignId(userInfo.getId());
|
||||||
|
if (byForeignId == null) {
|
||||||
|
iSysUserService.save(bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginDto obj = new LoginDto();
|
||||||
|
obj.setLoginName(bean.getLoginName());
|
||||||
|
obj.setPassword(null);
|
||||||
|
LoginVo loginVo = iSysUserService.login(obj);
|
||||||
|
|
||||||
|
if (loginVo == null || loginVo.getId() == null) {
|
||||||
|
return ResultJson.error("登录失败");
|
||||||
|
} else {
|
||||||
|
StpUtil.login(loginVo.getId()); // 使用 user id 登录
|
||||||
|
// 获取 Token 相关参数
|
||||||
|
loginVo.setTokenInfo(new AuthToken(StpUtil.getTokenInfo()));
|
||||||
|
loginVo.setRoleList(StpUtil.getRoleList());
|
||||||
|
return ResultJson.ok(loginVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<SysUser> page(@Param("page") IPage<SysUser> page, @Param("obj") FindSysUserDto findDto);
|
IPage<SysUser> page(@Param("page") IPage<SysUser> page, @Param("obj") FindSysUserDto findDto);
|
||||||
|
|
||||||
|
SysUser findByForeignId(String foreignId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.whdc.zhdbaqapi.model.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true) // chain = true 实现链式调用
|
||||||
|
public class ForeignResp {
|
||||||
|
boolean success;
|
||||||
|
String message;
|
||||||
|
String extMessage;
|
||||||
|
int code;
|
||||||
|
@JsonProperty(value = "result")
|
||||||
|
ForeignResult result;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.whdc.zhdbaqapi.model.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.whdc.zhdbaqapi.model.entity.ForeignUserInfo;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true) // chain = true 实现链式调用
|
||||||
|
public class ForeignResult {
|
||||||
|
int multi_depart;
|
||||||
|
@JsonProperty(value = "userInfo")
|
||||||
|
ForeignUserInfo userInfo;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.whdc.zhdbaqapi.model.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ForeignTokenDto {
|
||||||
|
@ApiParam(value = "token", example = "")
|
||||||
|
@ApiModelProperty(value = "token", dataType = "java.lang.String")
|
||||||
|
@NotBlank(message = "token")
|
||||||
|
private String token;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.whdc.zhdbaqapi.model.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true) // chain = true 实现链式调用
|
||||||
|
public class ForeignOrg {
|
||||||
|
String id;
|
||||||
|
String parentId;
|
||||||
|
String departName;
|
||||||
|
String departNameEn;
|
||||||
|
String departNameAbbr;
|
||||||
|
String departOrder;
|
||||||
|
String description;
|
||||||
|
String orgCategory;
|
||||||
|
String orgType;
|
||||||
|
String orgCode;
|
||||||
|
String departmentContactUsername;
|
||||||
|
String ownerOrgCode;
|
||||||
|
String mobile;
|
||||||
|
String fax;
|
||||||
|
String address;
|
||||||
|
String departNameFn;
|
||||||
|
String addvcd;
|
||||||
|
String municipalUnit;
|
||||||
|
String memo;
|
||||||
|
String status;
|
||||||
|
String delFlag;
|
||||||
|
String qywxIdentifier;
|
||||||
|
String createBy;
|
||||||
|
String createTime;
|
||||||
|
String updateBy;
|
||||||
|
String updateTime;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.whdc.zhdbaqapi.model.entity;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true) // chain = true 实现链式调用
|
||||||
|
public class ForeignUserInfo {
|
||||||
|
String id;
|
||||||
|
String username;
|
||||||
|
String realname;
|
||||||
|
String avatar;
|
||||||
|
String birthday;
|
||||||
|
int sex;
|
||||||
|
String email;
|
||||||
|
String phone;
|
||||||
|
String orgCode;
|
||||||
|
String orgCodeTxt;
|
||||||
|
int orgIsExternal;
|
||||||
|
int status;
|
||||||
|
int delFlag;
|
||||||
|
String workNo;
|
||||||
|
String post;
|
||||||
|
String telephone;
|
||||||
|
String createBy;
|
||||||
|
String createTime;
|
||||||
|
String updateBy;
|
||||||
|
String updateTime;
|
||||||
|
int activitiSync;
|
||||||
|
int userIdentity;
|
||||||
|
String departIds;
|
||||||
|
String relTenantIds;
|
||||||
|
String clientId;
|
||||||
|
@JsonProperty(value = "currentOrg")
|
||||||
|
ForeignOrg currentOrg;
|
||||||
|
@JsonProperty(value = "currentOwnOrg")
|
||||||
|
ForeignOrg currentOwnOrg;
|
||||||
|
String roleCodes;
|
||||||
|
boolean originalPassword;
|
||||||
|
boolean simplePassword;
|
||||||
|
int numberOfErrors;
|
||||||
|
String addvcd;
|
||||||
|
}
|
||||||
|
|
@ -46,4 +46,9 @@ public class SysUser {
|
||||||
@ApiModelProperty(value = "姓名", dataType = "java.lang.String")
|
@ApiModelProperty(value = "姓名", dataType = "java.lang.String")
|
||||||
@TableField("NAME")
|
@TableField("NAME")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ApiParam(value = "外部id", example = "")
|
||||||
|
@ApiModelProperty(value = "外部id", dataType = "java.lang.String")
|
||||||
|
@TableField("FOREIGN_ID")
|
||||||
|
private String foreignId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,4 +36,6 @@ public interface ISysUserService extends IService<SysUser> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Boolean changePwd(ChangePwdDto obj);
|
Boolean changePwd(ChangePwdDto obj);
|
||||||
|
|
||||||
|
SysUser getByForeignId(String foreignId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,4 +95,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
public Boolean changePwd(ChangePwdDto obj) {
|
public Boolean changePwd(ChangePwdDto obj) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SysUser getByForeignId(String foreignId) {
|
||||||
|
return baseMapper.findByForeignId(foreignId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.whdc.zhdbaqapi.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class HttpUtil {
|
||||||
|
public static String get(String _url) {
|
||||||
|
InputStream is = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
String jstr = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(_url);
|
||||||
|
conn = (HttpURLConnection) url.openConnection();
|
||||||
|
conn.setRequestMethod("GET");
|
||||||
|
conn.setConnectTimeout(5000);
|
||||||
|
conn.setReadTimeout(5000);
|
||||||
|
conn.connect();
|
||||||
|
if (conn.getResponseCode() == 200) {
|
||||||
|
is = conn.getInputStream();
|
||||||
|
if (is != null) {
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
String tmp = "";
|
||||||
|
while ((tmp = br.readLine()) != null) {
|
||||||
|
sb.append(tmp);
|
||||||
|
}
|
||||||
|
jstr = sb.toString();
|
||||||
|
return jstr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
} finally {
|
||||||
|
if (br != null) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is != null) {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conn != null) {
|
||||||
|
try {
|
||||||
|
conn.disconnect();
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -13,4 +13,8 @@
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="findByForeignId" resultType="com.whdc.zhdbaqapi.model.entity.SysUser">
|
||||||
|
SELECT ID, NAME, LOGIN_NAME, TYPE FROM SYS_USER
|
||||||
|
WHERE FOREIGN_ID=#{obj.foreignId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue