Merge branch 'test-sso' of http://192.168.0.56:3000/bonus/devicesmgt into test-sso
This commit is contained in:
commit
ea0bdba097
|
|
@ -3,6 +3,8 @@ package com.bonus.sgzb.auth.controller;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.bonus.sgzb.auth.form.AuthenticationLoginFrom;
|
||||
import com.bonus.sgzb.auth.service.NwUserLoginService;
|
||||
import com.bonus.sgzb.common.core.constant.CacheConstants;
|
||||
import com.bonus.sgzb.common.redis.service.RedisService;
|
||||
import com.bonus.sgzb.system.api.RemoteUserService;
|
||||
|
|
@ -43,6 +45,9 @@ public class TokenController {
|
|||
@Resource
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Resource
|
||||
private NwUserLoginService nwUserLoginService;
|
||||
|
||||
//web端登录
|
||||
@PostMapping("login")
|
||||
public R<?> login(@RequestBody LoginBody form) {
|
||||
|
|
@ -115,4 +120,18 @@ public class TokenController {
|
|||
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@ApiOperation("微服务平台认证接口")
|
||||
@PostMapping(value = "/onlineApprove")
|
||||
public R<?> onlineApprove(@RequestBody AuthenticationLoginFrom loginForm) {
|
||||
if (loginForm == null || StringUtils.isBlank(loginForm.getType())) {
|
||||
return R.fail("参数异常");
|
||||
}
|
||||
try {
|
||||
return nwUserLoginService.onlineApprove(loginForm);
|
||||
} catch (Exception e) {
|
||||
log.error("微服务平台认证登陆 异常: ", e);
|
||||
return R.fail("微服务平台认证失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
package com.bonus.sgzb.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
package com.bonus.sgzb.system.service.impl;
|
||||
package com.bonus.sgzb.auth.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.bonus.sgzb.auth.form.*;
|
||||
import com.bonus.sgzb.auth.utils.HttpUtils;
|
||||
import com.bonus.sgzb.common.core.constant.SecurityConstants;
|
||||
import com.bonus.sgzb.common.core.domain.R;
|
||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||
import com.bonus.sgzb.system.domain.*;
|
||||
import com.bonus.sgzb.system.service.ISysUserService;
|
||||
import com.bonus.sgzb.system.util.HttpUtils;
|
||||
import com.bonus.sgzb.common.security.service.TokenService;
|
||||
import com.bonus.sgzb.system.api.RemoteUserService;
|
||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
|
@ -26,7 +29,10 @@ public class NwUserLoginService {
|
|||
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
private RemoteUserService userService;
|
||||
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
/**
|
||||
* 调用微服务平台认证接口
|
||||
|
|
@ -91,8 +97,8 @@ public class NwUserLoginService {
|
|||
String updateUserName = loginUserInfoRespDTO.getUpdateUserName();
|
||||
String updateTime = loginUserInfoRespDTO.getUpdateTime();*/
|
||||
//根据用户名查询用户
|
||||
SysUser sysUser = userService.selectUserByUserName(userName);
|
||||
if (null == sysUser) {
|
||||
R<LoginUser> userInfo = userService.getUserInfo(userName, SecurityConstants.INNER);
|
||||
if (null == userInfo.getData()) {
|
||||
return R.fail(NwLoginConstants.LOGIN_ERROR_CODE,NwLoginConstants.LOGIN_ERROR_MESSAGE);
|
||||
//未找到该用户,新增该用户
|
||||
/* SysUser user = new SysUser();
|
||||
|
|
@ -115,6 +121,8 @@ public class NwUserLoginService {
|
|||
user.setUpdateBy(updateUserName);
|
||||
user.setUpdateTime(DateUtil.parse(updateTime,"yyyy-MM-dd HH:mm:ss"));*/
|
||||
}
|
||||
return R.ok(sysUser);
|
||||
// return R.ok(userInfo);
|
||||
LoginUser data = userInfo.getData();
|
||||
return R.ok(tokenService.createToken(data));
|
||||
}
|
||||
}
|
||||
|
|
@ -26,8 +26,7 @@ import javax.annotation.Resource;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@Component
|
||||
public class SysLoginService
|
||||
{
|
||||
public class SysLoginService {
|
||||
@Resource
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
|
|
@ -43,25 +42,21 @@ public class SysLoginService
|
|||
/**
|
||||
* 用户名密码登录
|
||||
*/
|
||||
public LoginUser login(String username, String password)
|
||||
{
|
||||
public LoginUser login(String username, String password) {
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password))
|
||||
{
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
}
|
||||
// 密码如果不在指定范围内 错误
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
|
||||
throw new ServiceException("用户密码不在指定范围");
|
||||
}
|
||||
// 用户名不在指定范围内 错误
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
|
||||
throw new ServiceException("用户名不在指定范围");
|
||||
}
|
||||
|
|
@ -94,6 +89,37 @@ public class SysLoginService
|
|||
return userInfo;
|
||||
}
|
||||
|
||||
public LoginUser loginApprove(String username, String password) {
|
||||
|
||||
// IP黑名单校验
|
||||
isBlackIp(username);
|
||||
// 查询用户信息
|
||||
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
|
||||
throw new ServiceException("登录用户:" + username + " 不存在");
|
||||
}
|
||||
|
||||
if (R.FAIL == userResult.getCode()) {
|
||||
throw new ServiceException(userResult.getMsg());
|
||||
}
|
||||
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userResult.getData().getSysUser();
|
||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
||||
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
|
||||
}
|
||||
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
||||
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
||||
}
|
||||
passwordService.validate(user, password);
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手机号验证码登录
|
||||
|
|
@ -161,9 +187,10 @@ public class SysLoginService
|
|||
|
||||
/**
|
||||
* 根据手机号码重置密码,判断Redis中是否有验证码,如果有则通过验证,并删除key
|
||||
* @param phone 手机号码
|
||||
*
|
||||
* @param phone 手机号码
|
||||
* @param password 密码
|
||||
* @param code 验证码
|
||||
* @param code 验证码
|
||||
*/
|
||||
private void resetPassword(String phone, String code, Long userId, String password) {
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
||||
|
|
@ -190,36 +217,30 @@ public class SysLoginService
|
|||
|
||||
private void isBlackIp(String phone) {
|
||||
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
|
||||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
||||
{
|
||||
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) {
|
||||
recordLogService.recordLogininfor(phone, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
||||
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
||||
}
|
||||
}
|
||||
|
||||
public void logout(String loginName)
|
||||
{
|
||||
public void logout(String loginName) {
|
||||
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void register(String username, String password)
|
||||
{
|
||||
public void register(String username, String password) {
|
||||
// 用户名或密码为空 错误
|
||||
if (StringUtils.isAnyBlank(username, password))
|
||||
{
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
throw new ServiceException("用户/密码必须填写");
|
||||
}
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
|
||||
{
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
throw new ServiceException("账户长度必须在2到20个字符之间");
|
||||
}
|
||||
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
|
||||
{
|
||||
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
||||
throw new ServiceException("密码长度必须在5到20个字符之间");
|
||||
}
|
||||
|
||||
|
|
@ -230,8 +251,7 @@ public class SysLoginService
|
|||
sysUser.setPassword(SecurityUtils.encryptPassword(password));
|
||||
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
|
||||
|
||||
if (R.FAIL == registerResult.getCode())
|
||||
{
|
||||
if (R.FAIL == registerResult.getCode()) {
|
||||
throw new ServiceException(registerResult.getMsg());
|
||||
}
|
||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package com.bonus.sgzb.system.util;
|
||||
package com.bonus.sgzb.auth.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.sgzb.auth.form.NwLoginConstants;
|
||||
import com.bonus.sgzb.auth.form.OnlineApprove;
|
||||
import com.bonus.sgzb.auth.form.RespLoginData;
|
||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||
import com.bonus.sgzb.system.domain.NwLoginConstants;
|
||||
import com.bonus.sgzb.system.domain.OnlineApprove;
|
||||
import com.bonus.sgzb.system.domain.RespLoginData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
|
@ -25,3 +25,9 @@ spring:
|
|||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
onlineApprove: /lbcloud-oauth/oauth/token
|
||||
wechatAppId: crhmaxnE
|
||||
wechatAppsecret: 3893e6ed90d325f00e34583dd970a56580c05549
|
||||
getNowPersonDetailData: /lbcloud-user/user/queryLoginUserInfo
|
||||
baseUrl: https://test-sso.csgmall.com.cn
|
||||
|
|
@ -20,10 +20,7 @@ import com.bonus.sgzb.system.api.domain.SysDept;
|
|||
import com.bonus.sgzb.system.api.domain.SysRole;
|
||||
import com.bonus.sgzb.system.api.domain.SysUser;
|
||||
import com.bonus.sgzb.system.api.model.LoginUser;
|
||||
import com.bonus.sgzb.system.domain.AuthenticationLoginFrom;
|
||||
import com.bonus.sgzb.system.service.*;
|
||||
import com.bonus.sgzb.system.service.impl.NwUserLoginService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -72,9 +69,6 @@ public class SysUserController extends BaseController
|
|||
@Resource
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@Resource
|
||||
private NwUserLoginService nwUserLoginService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
*/
|
||||
|
|
@ -395,18 +389,4 @@ public class SysUserController extends BaseController
|
|||
return success(userService.getUserByRoleList(sysUser));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("微服务平台认证接口")
|
||||
@PostMapping(value = "/onlineApprove")
|
||||
public R<?> onlineApprove(@RequestBody AuthenticationLoginFrom loginForm) {
|
||||
if (loginForm == null || StringUtils.isBlank(loginForm.getType())) {
|
||||
return R.fail("参数异常");
|
||||
}
|
||||
try {
|
||||
return nwUserLoginService.onlineApprove(loginForm);
|
||||
} catch (Exception e) {
|
||||
log.error("微服务平台认证登陆 异常: ", e);
|
||||
return R.fail("微服务平台认证失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,121 +0,0 @@
|
|||
package com.bonus.sgzb.system.domain;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caoxianfei
|
||||
* @Version 1.0
|
||||
* @date 2021-08-13 10:07
|
||||
*/
|
||||
public class RespLoginData<T> {
|
||||
|
||||
protected String code;
|
||||
protected String message;
|
||||
protected String msg;
|
||||
protected String status;
|
||||
protected Boolean success;
|
||||
protected List<T> dataList;
|
||||
protected T data;
|
||||
|
||||
public RespLoginData(){
|
||||
}
|
||||
|
||||
public RespLoginData(String str, Class<T> clazz) {
|
||||
if (StringUtils.isNotBlank(str)) {
|
||||
JSONObject json = JSON.parseObject(str);
|
||||
this.code = json.getString("code");
|
||||
this.message = json.getString("message");
|
||||
this.status = json.getString("status");
|
||||
this.msg = json.getString("msg");
|
||||
this.success = Boolean.parseBoolean(json.getString("success"));
|
||||
if (null != clazz) {
|
||||
if (json.get("data") != null && StringUtils.isNotBlank(json.getString("data"))) {
|
||||
try{
|
||||
this.data = JSONObject.parseObject(json.getString("data"), clazz);
|
||||
} catch (Exception e) {
|
||||
|
||||
try {
|
||||
this.dataList = JSONObject.parseArray(json.getString("data"), clazz);
|
||||
} catch (Exception ex) {
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* this.data = (T)JSONObject.parseObject(json.getString("data"), Boolean.class);*/
|
||||
this.data = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RespLoginData(String code, String message, String msg, String status, Boolean success, T data, List<T> dataList) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.msg = msg;
|
||||
this.status = status;
|
||||
this.success = success;
|
||||
this.data = data;
|
||||
this.dataList = dataList;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public List<T> getDataList() {
|
||||
return dataList;
|
||||
}
|
||||
|
||||
public void setDataList(List<T> dataList) {
|
||||
this.dataList = dataList;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -38,8 +38,8 @@ spring:
|
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
|
||||
onlineApprove: /lbcloud-oauth/oauth/token
|
||||
wechatAppId: crhmaxnE
|
||||
wechatAppsecret: 3893e6ed90d325f00e34583dd970a56580c05549
|
||||
getNowPersonDetailData: /lbcloud-user/user/queryLoginUserInfo
|
||||
baseUrl: https://test-sso.csgmall.com.cn
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue