修改单点登录
This commit is contained in:
@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -99,9 +100,19 @@ public class AccessUserController extends LideeBaseController<AccessUserParam, A
|
||||
}
|
||||
|
||||
@PostMapping({"/logincas"})
|
||||
public ResponseBean logincas(@RequestBody @Validated LideeUserDto dto) {
|
||||
public ResponseBean logincas(@RequestBody @Validated LideeUserDto dto) throws IOException {
|
||||
return responseSuccessWithData(accessUserService.logincas(dto));
|
||||
}
|
||||
@PostMapping({"/outlogcas"})
|
||||
public ResponseBean outlogcas(@RequestBody @Validated LideeUserDto dto){
|
||||
|
||||
Boolean data =accessUserService.outlogincas(dto);
|
||||
return responseSuccessWithData(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改自己的密码
|
||||
|
||||
@@ -8,6 +8,7 @@ import top.lidee.taie.business.modules.accessuser.dao.entity.AccessUser;
|
||||
import top.lidee.taie.business.modules.accessuser.controller.param.AccessUserParam;
|
||||
import top.lidee.taie.curd.service.LideeBaseService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,10 @@ public interface AccessUserService extends LideeBaseService<AccessUserParam, Acc
|
||||
*/
|
||||
LideeUserDto login(LideeUserDto lideeUserDto);
|
||||
|
||||
LideeUserDto logincas(LideeUserDto lideeUserDto);
|
||||
LideeUserDto logincas(LideeUserDto lideeUserDto) throws IOException;
|
||||
Boolean outlogincas(LideeUserDto lideeUserDto);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
|
||||
@@ -10,6 +10,7 @@ import top.lidee.taie.exception.BusinessException;
|
||||
import top.lidee.taie.exception.BusinessExceptionBuilder;
|
||||
import top.lidee.taie.curd.mapper.LideeBaseMapper;
|
||||
import top.lidee.taie.holder.UserContentHolder;
|
||||
import top.lidee.taie.http.HttpClientUtils;
|
||||
import top.lidee.taie.utils.LideeUtils;
|
||||
import top.lidee.taie.utils.JwtBean;
|
||||
import top.lidee.taie.business.code.ResponseCode;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -71,6 +73,14 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
@Autowired
|
||||
private CacheHelper cacheHelper;
|
||||
|
||||
@Value("${cas.loginurl:}")
|
||||
private String casLoginUrl;
|
||||
|
||||
@Value("${cas.outlogouturl:}")
|
||||
private String casoutlogouturl;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Map getRoleTree(String loginName, String operator) {
|
||||
Map<String, Object> result = new HashMap<String, Object>();
|
||||
@@ -146,7 +156,7 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
throw BusinessExceptionBuilder.build("用户不存在");
|
||||
}
|
||||
//默认密码
|
||||
accessUser.setPassword(MD5Util.encrypt(MD5Util.encrypt(defaultPassword.concat("lidee@123"))));
|
||||
accessUser.setPassword(MD5Util.encrypt(MD5Util.encrypt(defaultPassword.concat("Lidee@654!"))));
|
||||
accessUserMapper.updateById(accessUser);
|
||||
return true;
|
||||
}
|
||||
@@ -220,20 +230,19 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
|
||||
@Override
|
||||
public LideeUserDto logincas(LideeUserDto lideeUserDto) {
|
||||
String loginName="";
|
||||
String url = casLoginUrl+"?refreshToken="+ lideeUserDto.getLoginName();
|
||||
|
||||
//根据ticker获取用户信息
|
||||
String response = HttpClientUtils.getPost(url, lideeUserDto.getLoginName());
|
||||
|
||||
String loginName = lideeUserDto.getLoginName();
|
||||
JSONObject jsonObject = null;
|
||||
jsonObject= JSONObject.parseObject(response);
|
||||
if(Integer.parseInt(jsonObject.getString("code"))==0)
|
||||
{
|
||||
loginName=jsonObject.getJSONObject("data").getString("username");
|
||||
}
|
||||
|
||||
loginName="admin";
|
||||
// String password = lideeUserDto.getPassword();
|
||||
String password ="Lidee@654!";
|
||||
//将ticket保存到 redis 方便退出使用 key为username_ticket
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 1.判断用户是否存在
|
||||
LambdaQueryWrapper<AccessUser> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(AccessUser::getLoginName, loginName);
|
||||
@@ -290,10 +299,25 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
|
||||
String ldUserStr = JSONObject.toJSONString(lduser);
|
||||
cacheHelper.stringSetExpire(userKey, ldUserStr, 3600);
|
||||
|
||||
cacheHelper.stringSetExpire(loginName+"_cas", lideeUserDto.getLoginName(), 360000);
|
||||
// String ss= cacheHelper.stringGet(loginName+"_cas");
|
||||
return lduser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean outlogincas(LideeUserDto lideeUserDto) {
|
||||
|
||||
String token= cacheHelper.stringGet(lideeUserDto.getLoginName()+"_cas");
|
||||
|
||||
String url = casoutlogouturl+"?refreshToken="+ token;
|
||||
|
||||
String response = HttpClientUtils.getPost(url, token);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
@@ -341,7 +365,7 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
switch (operationEnum) {
|
||||
case INSERT:
|
||||
//lidee是为了和前端加密保持一致
|
||||
entity.setPassword(MD5Util.encrypt(MD5Util.encrypt(defaultPassword.concat("lidee"))));
|
||||
entity.setPassword(MD5Util.encrypt(MD5Util.encrypt(defaultPassword.concat("Lidee@654!"))));
|
||||
break;
|
||||
case UPDATE:
|
||||
//更新用户不允许修改密码
|
||||
@@ -353,4 +377,7 @@ public class AccessUserServiceImpl implements AccessUserService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -145,3 +145,8 @@ customer:
|
||||
##新增用户默认密码
|
||||
default:
|
||||
password: Lidee@654!
|
||||
cas:
|
||||
# loginurl: http://127.0.0.1:48080/admin-api/system/auth/user-info
|
||||
# outlogouturl: http://127.0.0.1:48080/admin-api/system/auth/logout-client
|
||||
loginurl: http://192.168.1.241/admin-api/system/auth/user-info
|
||||
outlogouturl: http://192.168.1.241/admin-api/system/auth/logout-client
|
||||
|
||||
Reference in New Issue
Block a user