forked from github/dataease
Merge pull request #2441 from dataease/pr@dev@perf_cas_reset
perf: 重置cas登录方式api增加管理员校验
This commit is contained in:
commit
c65e461fa8
@ -34,5 +34,7 @@ public interface AuthUserService {
|
||||
|
||||
Boolean pluginLoaded();
|
||||
|
||||
void checkAdmin(String uname, String pwd);
|
||||
|
||||
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 "已经切换默认登录方式";
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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=已切换回默认登录方式
|
@ -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=已切換回默認登錄方式
|
Loading…
Reference in New Issue
Block a user