forked from github/dataease
Merge branch 'dev' of github.com:dataease/dataease into dev
This commit is contained in:
commit
12755fa546
@ -9,6 +9,7 @@ import java.util.stream.Collectors;
|
|||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -21,6 +22,7 @@ import io.dataease.auth.service.AuthUserService;
|
|||||||
import io.dataease.auth.util.JWTUtils;
|
import io.dataease.auth.util.JWTUtils;
|
||||||
import io.dataease.commons.exception.DEException;
|
import io.dataease.commons.exception.DEException;
|
||||||
import io.dataease.commons.utils.CodingUtil;
|
import io.dataease.commons.utils.CodingUtil;
|
||||||
|
import io.dataease.commons.utils.LogUtil;
|
||||||
import io.dataease.commons.utils.ServletUtils;
|
import io.dataease.commons.utils.ServletUtils;
|
||||||
import io.dataease.plugins.config.SpringContextUtil;
|
import io.dataease.plugins.config.SpringContextUtil;
|
||||||
import io.dataease.plugins.xpack.display.dto.response.SysSettingDto;
|
import io.dataease.plugins.xpack.display.dto.response.SysSettingDto;
|
||||||
@ -43,21 +45,27 @@ public class SSOServer {
|
|||||||
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:/");
|
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
||||||
HttpServletResponse response = ServletUtils.response();
|
HttpServletResponse response = ServletUtils.response();
|
||||||
|
OidcXpackService oidcXpackService = null;
|
||||||
|
String idToken = null;
|
||||||
try {
|
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插件");
|
||||||
}
|
}
|
||||||
OidcXpackService oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class);
|
oidcXpackService = SpringContextUtil.getBean(OidcXpackService.class);
|
||||||
Boolean suuportOIDC = oidcXpackService.isSuuportOIDC();
|
Boolean suuportOIDC = oidcXpackService.isSuuportOIDC();
|
||||||
if (!suuportOIDC) {
|
if (!suuportOIDC) {
|
||||||
DEException.throwException("未开启oidc");
|
DEException.throwException("未开启oidc");
|
||||||
}
|
}
|
||||||
Map<String, String> config = config(oidcXpackService);
|
Map<String, String> config = config(oidcXpackService);
|
||||||
SSOToken ssoToken = oidcXpackService.requestSsoToken(config, code, state);
|
SSOToken ssoToken = oidcXpackService.requestSsoToken(config, code, state);
|
||||||
|
idToken = ssoToken.getIdToken();
|
||||||
|
Cookie cookie_id_token = new Cookie("IdToken", ssoToken.getIdToken());cookie_id_token.setPath("/");
|
||||||
|
response.addCookie(cookie_id_token);
|
||||||
|
|
||||||
SSOUserInfo ssoUserInfo = oidcXpackService.requestUserInfo(config, ssoToken.getAccessToken());
|
SSOUserInfo ssoUserInfo = oidcXpackService.requestUserInfo(config, ssoToken.getAccessToken());
|
||||||
|
|
||||||
|
|
||||||
SysUserEntity sysUserEntity = authUserService.getUserBySub(ssoUserInfo.getSub());
|
SysUserEntity sysUserEntity = authUserService.getUserBySub(ssoUserInfo.getSub());
|
||||||
if(null == sysUserEntity){
|
if(null == sysUserEntity){
|
||||||
sysUserService.validateExistUser(ssoUserInfo.getUsername(), ssoUserInfo.getEmail());
|
sysUserService.validateExistUser(ssoUserInfo.getUsername(), ssoUserInfo.getEmail());
|
||||||
@ -71,22 +79,29 @@ public class SSOServer {
|
|||||||
|
|
||||||
|
|
||||||
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_ac_token = new Cookie("AccessToken", ssoToken.getAccessToken());cookie_ac_token.setPath("/");
|
Cookie cookie_ac_token = new Cookie("AccessToken", ssoToken.getAccessToken());cookie_ac_token.setPath("/");
|
||||||
|
|
||||||
response.addCookie(cookie_token);
|
response.addCookie(cookie_token);
|
||||||
response.addCookie(cookie_id_token);
|
|
||||||
response.addCookie(cookie_ac_token);
|
response.addCookie(cookie_ac_token);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
String msg;
|
|
||||||
|
String msg = e.getMessage();
|
||||||
|
if (null != e.getCause()) {
|
||||||
|
msg = e.getCause().getMessage();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
msg = URLEncoder.encode(e.getMessage(), "UTF-8");
|
msg = URLEncoder.encode(msg, "UTF-8");
|
||||||
|
LogUtil.error(e);
|
||||||
Cookie cookie_error = new Cookie("OidcError", msg);
|
Cookie cookie_error = new Cookie("OidcError", msg);
|
||||||
cookie_error.setPath("/");
|
cookie_error.setPath("/");
|
||||||
response.addCookie(cookie_error);
|
response.addCookie(cookie_error);
|
||||||
|
if (ObjectUtils.isNotEmpty(oidcXpackService) && ObjectUtils.isNotEmpty(idToken)) {
|
||||||
|
oidcXpackService.logout(idToken);
|
||||||
|
}
|
||||||
return modelAndView;
|
return modelAndView;
|
||||||
} catch (UnsupportedEncodingException e1) {
|
} catch (UnsupportedEncodingException e1) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ public class SysUserService {
|
|||||||
throw new RuntimeException("用户姓名【"+nickName+"】已存在,请联系管理员");
|
throw new RuntimeException("用户姓名【"+nickName+"】已存在,请联系管理员");
|
||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
example.clear();
|
||||||
if (StringUtils.isNotBlank(email)) {
|
if (StringUtils.isNotBlank(email)) {
|
||||||
example.createCriteria().andEmailEqualTo(email);
|
example.createCriteria().andEmailEqualTo(email);
|
||||||
List<SysUser> users = sysUserMapper.selectByExample(example);
|
List<SysUser> users = sysUserMapper.selectByExample(example);
|
||||||
|
@ -93,7 +93,7 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
msg() {
|
msg() {
|
||||||
return this.$store.state.user.loginMsg || Cookies.get('OidcError')
|
return this.$store.state.user.loginMsg
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -126,8 +126,18 @@ export default {
|
|||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
})
|
})
|
||||||
|
let msg = Cookies.get('OidcError')
|
||||||
|
if (msg) {
|
||||||
|
msg = msg.replace('+', '')
|
||||||
|
this.$error(msg)
|
||||||
|
}
|
||||||
|
this.clearOidcMsg()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
clearOidcMsg() {
|
||||||
|
Cookies.remove('OidcError')
|
||||||
|
Cookies.remove('IdToken')
|
||||||
|
},
|
||||||
showLoginImage() {
|
showLoginImage() {
|
||||||
this.uiInfo = getSysUI()
|
this.uiInfo = getSysUI()
|
||||||
if (this.uiInfo['ui.loginImage'] && this.uiInfo['ui.loginImage'].paramValue) {
|
if (this.uiInfo['ui.loginImage'] && this.uiInfo['ui.loginImage'].paramValue) {
|
||||||
@ -138,7 +148,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleLogin() {
|
handleLogin() {
|
||||||
Cookies.remove('OidcError')
|
this.clearOidcMsg()
|
||||||
this.$refs.loginForm.validate(valid => {
|
this.$refs.loginForm.validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
@ -161,7 +171,7 @@ export default {
|
|||||||
},
|
},
|
||||||
changeLoginType(val) {
|
changeLoginType(val) {
|
||||||
if (val !== 2) return
|
if (val !== 2) return
|
||||||
Cookies.remove('OidcError')
|
this.clearOidcMsg()
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user