提交 21939ae1 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

fix: 修复oidc缺失信息报错方式

上级 ddd21356
package io.dataease.plugins.server; package io.dataease.plugins.server;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -39,6 +41,10 @@ public class SSOServer { ...@@ -39,6 +41,10 @@ public class SSOServer {
@GetMapping("/callBack") @GetMapping("/callBack")
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) { public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
ModelAndView modelAndView = new ModelAndView("redirect:/");
HttpServletResponse response = ServletUtils.response();
try {
Map<String, OidcXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((OidcXpackService.class)); Map<String, OidcXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((OidcXpackService.class));
if(beansOfType.keySet().size() == 0) { if(beansOfType.keySet().size() == 0) {
DEException.throwException("缺少oidc插件"); DEException.throwException("缺少oidc插件");
...@@ -62,7 +68,7 @@ public class SSOServer { ...@@ -62,7 +68,7 @@ public class SSOServer {
String realPwd = CodingUtil.md5(sysUserService.defaultPWD()); String realPwd = CodingUtil.md5(sysUserService.defaultPWD());
String token = JWTUtils.sign(tokenInfo, realPwd); String token = JWTUtils.sign(tokenInfo, realPwd);
ServletUtils.setToken(token); ServletUtils.setToken(token);
HttpServletResponse response = ServletUtils.response();
Cookie cookie_token = new Cookie("Authorization", token);cookie_token.setPath("/"); Cookie cookie_token = new Cookie("Authorization", token);cookie_token.setPath("/");
Cookie cookie_id_token = new Cookie("IdToken", ssoToken.getIdToken());cookie_id_token.setPath("/"); Cookie cookie_id_token = new Cookie("IdToken", ssoToken.getIdToken());cookie_id_token.setPath("/");
...@@ -71,7 +77,21 @@ public class SSOServer { ...@@ -71,7 +77,21 @@ public class SSOServer {
response.addCookie(cookie_token); response.addCookie(cookie_token);
response.addCookie(cookie_id_token); response.addCookie(cookie_id_token);
response.addCookie(cookie_ac_token); response.addCookie(cookie_ac_token);
ModelAndView modelAndView = new ModelAndView("redirect:/"); }catch(Exception e) {
String msg;
try {
msg = URLEncoder.encode(e.getMessage(), "UTF-8");
Cookie cookie_error = new Cookie("OidcError", msg);
cookie_error.setPath("/");
response.addCookie(cookie_error);
return modelAndView;
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return modelAndView; return modelAndView;
} }
private Map<String, String> config(OidcXpackService oidcXpackService) { private Map<String, String> config(OidcXpackService oidcXpackService) {
......
...@@ -66,6 +66,7 @@ import { encrypt } from '@/utils/rsaEncrypt' ...@@ -66,6 +66,7 @@ import { encrypt } from '@/utils/rsaEncrypt'
import { ldapStatus, oidcStatus } from '@/api/user' import { ldapStatus, oidcStatus } from '@/api/user'
import { getSysUI } from '@/utils/auth' import { getSysUI } from '@/utils/auth'
import PluginCom from '@/views/system/plugin/PluginCom' import PluginCom from '@/views/system/plugin/PluginCom'
import Cookies from 'js-cookie'
export default { export default {
name: 'Login', name: 'Login',
components: { PluginCom }, components: { PluginCom },
...@@ -92,7 +93,7 @@ export default { ...@@ -92,7 +93,7 @@ export default {
}, },
computed: { computed: {
msg() { msg() {
return this.$store.state.user.loginMsg return this.$store.state.user.loginMsg || Cookies.get('OidcError')
} }
}, },
watch: { watch: {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论