|
@@ -12,12 +12,9 @@ import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.entity.*;
|
|
import com.qmth.teachcloud.common.entity.*;
|
|
import com.qmth.teachcloud.common.enums.AppSourceEnum;
|
|
import com.qmth.teachcloud.common.enums.AppSourceEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
-import com.qmth.teachcloud.common.util.AuthThirdUtil;
|
|
|
|
-import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
|
-import com.qmth.teachcloud.common.util.Result;
|
|
|
|
-import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
|
-import com.qmth.teachcloud.report.business.bean.params.LoginThirdParam;
|
|
|
|
|
|
+import com.qmth.teachcloud.common.util.*;
|
|
import com.qmth.teachcloud.report.business.cache.ThirdUserAuthCacheUtil;
|
|
import com.qmth.teachcloud.report.business.cache.ThirdUserAuthCacheUtil;
|
|
import com.qmth.teachcloud.report.business.service.ReportCommonService;
|
|
import com.qmth.teachcloud.report.business.service.ReportCommonService;
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
@@ -26,10 +23,12 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
@@ -81,43 +80,45 @@ public class SsoApiController {
|
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
@Aac(auth = BOOL.FALSE)
|
|
@Aac(auth = BOOL.FALSE)
|
|
@Transactional
|
|
@Transactional
|
|
- public void login(@ApiParam(value = "接收登录数据信息", required = true) @RequestBody String result, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
- Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
|
|
|
|
- String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
|
|
|
|
- log.info("login进来了,result:{}", decodeJson);
|
|
|
|
- LoginThirdParam loginThirdParam = JacksonUtil.readJson(decodeJson, LoginThirdParam.class);
|
|
|
|
- Optional.ofNullable(loginThirdParam).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
|
|
|
|
- loginThirdParam.validParams();
|
|
|
|
- BasicSchool basicSchool = AuthThirdUtil.hasPermission();
|
|
|
|
|
|
+ public void login(@ApiParam(value = "登录名", required = true) @RequestParam String loginName,
|
|
|
|
+ @ApiParam(value = "角色", required = true) @RequestParam RoleTypeEnum role,
|
|
|
|
+ @ApiParam(value = "学院名称", required = true) @RequestParam String orgName,
|
|
|
|
+ @ApiParam(value = "真实名", required = false) @RequestParam(required = false) String realName,
|
|
|
|
+ @ApiParam(value = "手机号码", required = false) @RequestParam(required = false) String mobileNumber,
|
|
|
|
+ @ApiParam(value = "是否启用", required = false) @RequestParam(required = false) Boolean enable,
|
|
|
|
+ @ApiParam(value = "返回url", required = true) @RequestParam String returnUrl,
|
|
|
|
+ @ApiParam(value = "时间戳", required = true) @RequestParam Long time,
|
|
|
|
+ @ApiParam(value = "鉴权", required = true) @RequestParam String authorization) throws IOException {
|
|
|
|
+ BasicSchool basicSchool = AuthThirdUtil.hasPermission(time, authorization);
|
|
//插入或者更新用户
|
|
//插入或者更新用户
|
|
//查询用户是否存在
|
|
//查询用户是否存在
|
|
QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
sysUserQueryWrapper.lambda().eq(SysUser::getSchoolId, basicSchool.getId())
|
|
sysUserQueryWrapper.lambda().eq(SysUser::getSchoolId, basicSchool.getId())
|
|
- .eq(SysUser::getLoginName, loginThirdParam.getLoginName())
|
|
|
|
|
|
+ .eq(SysUser::getLoginName, loginName)
|
|
.eq(SysUser::getEnable, true);
|
|
.eq(SysUser::getEnable, true);
|
|
SysUser sysUser = sysUserService.getOne(sysUserQueryWrapper);
|
|
SysUser sysUser = sysUserService.getOne(sysUserQueryWrapper);
|
|
if (Objects.isNull(sysUser)) {//新增
|
|
if (Objects.isNull(sysUser)) {//新增
|
|
sysUser = new SysUser(basicSchool.getId(),
|
|
sysUser = new SysUser(basicSchool.getId(),
|
|
- loginThirdParam.getLoginName(),
|
|
|
|
- Objects.nonNull(loginThirdParam.getRealName()) ? loginThirdParam.getRealName() : loginThirdParam.getLoginName(),
|
|
|
|
- Objects.nonNull(loginThirdParam.getMobileNumber()) ? loginThirdParam.getMobileNumber() : null);
|
|
|
|
|
|
+ loginName,
|
|
|
|
+ Objects.nonNull(realName) ? realName : loginName,
|
|
|
|
+ Objects.nonNull(mobileNumber) ? mobileNumber : null);
|
|
} else {
|
|
} else {
|
|
sysUser.setSchoolId(basicSchool.getId());
|
|
sysUser.setSchoolId(basicSchool.getId());
|
|
- if (Objects.nonNull(loginThirdParam.getRealName())) {
|
|
|
|
- sysUser.setRealName(loginThirdParam.getRealName());
|
|
|
|
|
|
+ if (Objects.nonNull(realName)) {
|
|
|
|
+ sysUser.setRealName(realName);
|
|
}
|
|
}
|
|
- if (Objects.nonNull(loginThirdParam.getMobileNumber())) {
|
|
|
|
- sysUser.setMobileNumber(loginThirdParam.getMobileNumber());
|
|
|
|
|
|
+ if (Objects.nonNull(mobileNumber)) {
|
|
|
|
+ sysUser.setMobileNumber(mobileNumber);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (Objects.nonNull(loginThirdParam.getEnable())) {
|
|
|
|
- sysUser.setEnable(loginThirdParam.getEnable());
|
|
|
|
|
|
+ if (Objects.nonNull(enable)) {
|
|
|
|
+ sysUser.setEnable(enable);
|
|
}
|
|
}
|
|
|
|
|
|
//查询学院id
|
|
//查询学院id
|
|
QueryWrapper<SysOrg> sysOrgQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysOrg> sysOrgQueryWrapper = new QueryWrapper<>();
|
|
sysOrgQueryWrapper.lambda().eq(SysOrg::getSchoolId, basicSchool.getId())
|
|
sysOrgQueryWrapper.lambda().eq(SysOrg::getSchoolId, basicSchool.getId())
|
|
- .eq(SysOrg::getName, loginThirdParam.getOrgName())
|
|
|
|
|
|
+ .eq(SysOrg::getName, orgName)
|
|
.eq(SysOrg::getEnable, true);
|
|
.eq(SysOrg::getEnable, true);
|
|
SysOrg sysOrg = sysOrgService.getOne(sysOrgQueryWrapper);
|
|
SysOrg sysOrg = sysOrgService.getOne(sysOrgQueryWrapper);
|
|
Optional.ofNullable(sysOrg).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学院数据为空"));
|
|
Optional.ofNullable(sysOrg).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学院数据为空"));
|
|
@@ -126,7 +127,7 @@ public class SsoApiController {
|
|
|
|
|
|
//新增用户和角色关系
|
|
//新增用户和角色关系
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
- sysRoleQueryWrapper.lambda().eq(SysRole::getType, loginThirdParam.getRole())
|
|
|
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getType, role)
|
|
.eq(SysRole::getEnable, true);
|
|
.eq(SysRole::getEnable, true);
|
|
SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("角色数据为空"));
|
|
Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("角色数据为空"));
|
|
@@ -139,7 +140,9 @@ public class SsoApiController {
|
|
String pattern = "{0}{1}{2}";
|
|
String pattern = "{0}{1}{2}";
|
|
String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
|
|
String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
|
|
|
|
|
|
- ThirdUserAuthCacheUtil.setAuthReturnUrl(String.valueOf(sysUser.getId()), loginThirdParam.getReturnUrl());
|
|
|
|
|
|
+ ThirdUserAuthCacheUtil.setAuthReturnUrl(String.valueOf(sysUser.getId()), returnUrl);
|
|
|
|
+
|
|
|
|
+ HttpServletResponse response = ServletUtil.getResponse();
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + code + "/" + AppSourceEnum.PRINT_THIRD);
|
|
response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + code + "/" + AppSourceEnum.PRINT_THIRD);
|
|
}
|
|
}
|
|
@@ -148,7 +151,8 @@ public class SsoApiController {
|
|
@RequestMapping(value = "/user/authentication/login", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/user/authentication/login", method = RequestMethod.POST)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = LoginResult.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = LoginResult.class)})
|
|
@Aac(auth = BOOL.FALSE)
|
|
@Aac(auth = BOOL.FALSE)
|
|
- public Result login(@ApiParam(value = "授权码信息", required = true) @RequestParam String code) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
|
|
|
|
|
+ public Result login(@ApiParam(value = "授权码信息", required = true) @RequestParam String code,
|
|
|
|
+ @ApiParam(value = "应用来源", required = true) @RequestParam AppSourceEnum appSource) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
|
String[] values = StringUtils.split(URLDecoder.decode(code, SystemConstant.CHARSET_NAME), SignatureEntityTest.FIELD_JOINER);
|
|
String[] values = StringUtils.split(URLDecoder.decode(code, SystemConstant.CHARSET_NAME), SignatureEntityTest.FIELD_JOINER);
|
|
if (Objects.isNull(values) || values.length != 2) {
|
|
if (Objects.isNull(values) || values.length != 2) {
|
|
throw ExceptionResultEnum.ERROR.exception("临时授权码出错,请重新获取");
|
|
throw ExceptionResultEnum.ERROR.exception("临时授权码出错,请重新获取");
|
|
@@ -168,16 +172,18 @@ public class SsoApiController {
|
|
if (Objects.isNull(userAuthCode) || !Objects.equals(values[1], URLDecoder.decode(SignatureEntityTest.encrypt(userAuthCode), SystemConstant.CHARSET_NAME))) {
|
|
if (Objects.isNull(userAuthCode) || !Objects.equals(values[1], URLDecoder.decode(SignatureEntityTest.encrypt(userAuthCode), SystemConstant.CHARSET_NAME))) {
|
|
throw ExceptionResultEnum.ERROR.exception("临时授权码已过期");
|
|
throw ExceptionResultEnum.ERROR.exception("临时授权码已过期");
|
|
}
|
|
}
|
|
- LoginResult loginResult = teachcloudCommonService.login(sysUser.getPassword(), sysUser, AppSourceEnum.PRINT_THIRD);
|
|
|
|
|
|
+ LoginResult loginResult = teachcloudCommonService.login(sysUser.getPassword(), sysUser, appSource);
|
|
ThirdUserAuthCacheUtil.deleteAuthCode(values[0]);
|
|
ThirdUserAuthCacheUtil.deleteAuthCode(values[0]);
|
|
return ResultUtil.ok(loginResult);
|
|
return ResultUtil.ok(loginResult);
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "用户鉴权退出接口")
|
|
@ApiOperation(value = "用户鉴权退出接口")
|
|
- @RequestMapping(value = "/user/authentication/logout", method = RequestMethod.GET)
|
|
|
|
|
|
+ @RequestMapping(value = "/user/authentication/logout", method = RequestMethod.POST)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
|
|
@Aac(auth = BOOL.FALSE)
|
|
@Aac(auth = BOOL.FALSE)
|
|
- public void authenticationLogout() throws IOException {
|
|
|
|
- reportCommonService.thirdLogout();
|
|
|
|
|
|
+ public void logout(@ApiParam(value = "时间戳", required = true) @RequestParam Long time,
|
|
|
|
+ @ApiParam(value = "鉴权", required = true) @RequestParam String authorization) throws IOException {
|
|
|
|
+ TBSession tbSession = AuthThirdUtil.hasPermissionLogout(time, authorization);
|
|
|
|
+ reportCommonService.thirdLogout(tbSession);
|
|
}
|
|
}
|
|
}
|
|
}
|