Merge pull request #2441 from dataease/pr@dev@perf_cas_reset

perf: 重置cas登录方式api增加管理员校验
This commit is contained in:
fit2cloud-chenyw 2022-06-17 10:35:46 +08:00 committed by GitHub
commit c65e461fa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 13 deletions

View File

@ -34,5 +34,7 @@ public interface AuthUserService {
Boolean pluginLoaded();
void checkAdmin(String uname, String pwd);
}

View File

@ -2,10 +2,13 @@ package io.dataease.auth.service.impl;
import io.dataease.auth.api.dto.CurrentRoleDto;
import io.dataease.auth.entity.SysUserEntity;
import io.dataease.commons.utils.CodingUtil;
import io.dataease.exception.DataEaseException;
import io.dataease.ext.*;
import io.dataease.auth.service.AuthUserService;
import io.dataease.commons.constants.AuthConstants;
import io.dataease.commons.utils.LogUtil;
import io.dataease.i18n.Translator;
import io.dataease.plugins.common.base.domain.SysUser;
import io.dataease.plugins.common.base.mapper.SysUserMapper;
import io.dataease.plugins.common.service.PluginCommonService;
@ -171,5 +174,20 @@ public class AuthUserServiceImpl implements AuthUserService {
return pluginCommonService.isPluginLoaded();
}
@Override
public void checkAdmin(String uname, String pwd) {
SysUserEntity user = getUserByName(uname);
if (ObjectUtils.isEmpty(user)) {
DataEaseException.throwException(Translator.get("i18n_user_not_exist"));
}
if (!user.getIsAdmin()) {
DataEaseException.throwException(Translator.get("i18n_not_admin_error"));
}
String realPwd = user.getPassword();
pwd = CodingUtil.md5(pwd);
if (!StringUtils.equals(pwd, realPwd)) {
DataEaseException.throwException(Translator.get("i18n_id_or_pwd_error"));
}
}
}

View File

@ -85,7 +85,7 @@ public class ShiroServiceImpl implements ShiroService {
filterChainDefinitionMap.put("/plugin/oidc/authInfo", ANON);
filterChainDefinitionMap.put("/sso/callBack*", ANON);
filterChainDefinitionMap.put("/cas/callBack*", ANON);
filterChainDefinitionMap.put("/cas/reset", ANON);
filterChainDefinitionMap.put("/cas/reset/**", ANON);
filterChainDefinitionMap.put("/unauth", ANON);
filterChainDefinitionMap.put("/display/**", ANON);

View File

@ -9,6 +9,8 @@ import io.dataease.commons.utils.CodingUtil;
import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.ServletUtils;
import io.dataease.controller.ResultHolder;
import io.dataease.i18n.Translator;
import io.dataease.service.sys.SysUserService;
import io.dataease.service.system.SystemParameterService;
import org.apache.commons.lang3.StringUtils;
@ -17,6 +19,7 @@ import org.jasig.cas.client.util.AssertionHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@ -87,17 +90,26 @@ public class CasServer {
return modelAndView;
}
@GetMapping("/reset")
@GetMapping("/reset/{uname}/{pwd}")
@ResponseBody
public String reset() {
systemParameterService.resetCas();
String token = ServletUtils.getToken();
if (StringUtils.isNotBlank(token)) {
Long userId = JWTUtils.tokenInfoByToken(token).getUserId();
authUserService.clearCache(userId);
public ResultHolder reset(@PathVariable(value = "uname", required = true) String uname, @PathVariable(value = "pwd", required = true) String pwd) {
try {
authUserService.checkAdmin(uname, pwd);
systemParameterService.resetCas();
String token = ServletUtils.getToken();
if (StringUtils.isNotBlank(token)) {
Long userId = JWTUtils.tokenInfoByToken(token).getUserId();
authUserService.clearCache(userId);
}
HttpServletRequest request = ServletUtils.request();
request.getSession().invalidate();
ResultHolder success = ResultHolder.success(null);
success.setMessage(Translator.get("i18n_default_login_reset"));
return success;
}catch (Exception e) {
LogUtil.error(e.getMessage(), e);
ResultHolder error = ResultHolder.error(e.getMessage());
return error;
}
HttpServletRequest request = ServletUtils.request();
request.getSession().invalidate();
return "已经切换默认登录方式";
}
}

View File

@ -156,4 +156,10 @@ SOURCE_TYPE_MENU=MENU
I18N_DRIVER_NOT_DELETE=Drivers in use cannot be deleted
I18N_DRIVER_REPEAT_NAME=Driver name cannot be same.
I18N_DRIVER_NOT_FOUND=Cannot find driver.
I18N_DRIVER_NOT_FOUND=Cannot find driver.
i18n_not_admin_error=Not an administrator account
i18n_user_not_exist=user does not exist
i18n_default_login_reset=Switched back to default login mode

View File

@ -160,3 +160,10 @@ I18N_TIME=操作时间
I18N_DRIVER_NOT_DELETE=使用中的驱动不允许删除
I18N_DRIVER_REPEAT_NAME=名称重复
I18N_DRIVER_NOT_FOUND=未找到驱动
i18n_not_admin_error=不是管理员账号
i18n_user_not_exist=用户不存在
i18n_default_login_reset=已切换回默认登录方式

View File

@ -155,4 +155,8 @@ SOURCE_TYPE_MENU=菜單
I18N_DRIVER_NOT_DELETE=使用中的驅動不允許删除
I18N_DRIVER_REPEAT_NAME=名稱重複
I18N_DRIVER_NOT_FOUND=未找到驅動
I18N_DRIVER_NOT_FOUND=未找到驅動
i18n_not_admin_error=不是管理員賬號
i18n_user_not_exist=用戶不存在
i18n_default_login_reset=已切換回默認登錄方式