feat: support wework oauth login
This commit is contained in:
parent
e93beba0a3
commit
b31015cb36
|
@ -33,6 +33,13 @@ public class LoginAppController {
|
||||||
|
|
||||||
private final OpenAuthHandlers openAuthHandlers;
|
private final OpenAuthHandlers openAuthHandlers;
|
||||||
|
|
||||||
|
@GetMapping(Routes.OAuth2App.LIST_PLATFORMS)
|
||||||
|
@ResponseBody
|
||||||
|
@Operation(summary = "获取支持的 OAuth2 应用列表")
|
||||||
|
public JsonData<List<OAuthAppPlatformResponse>> listPlatforms() {
|
||||||
|
return JsonData.ok(openAuthAppService.listPlatforms());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无需授权
|
* 无需授权
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -154,6 +154,8 @@ public interface Routes {
|
||||||
|
|
||||||
String GET_ONE = BASE + "/oauth2_apps/{id}";
|
String GET_ONE = BASE + "/oauth2_apps/{id}";
|
||||||
|
|
||||||
|
String LIST_PLATFORMS = BASE + "/oauth2_apps/platforms";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DatabaseType {
|
interface DatabaseType {
|
||||||
|
|
|
@ -51,10 +51,11 @@ public class DatabasirOauth2LoginFilter extends AbstractAuthenticationProcessing
|
||||||
Map<String, String[]> params = request.getParameterMap();
|
Map<String, String[]> params = request.getParameterMap();
|
||||||
String registrationId = new AntPathMatcher().extractPathWithinPattern(OAUTH_LOGIN_URI, request.getRequestURI());
|
String registrationId = new AntPathMatcher().extractPathWithinPattern(OAUTH_LOGIN_URI, request.getRequestURI());
|
||||||
UserDetailResponse userDetailResponse = openAuthAppService.oauthCallback(registrationId, params);
|
UserDetailResponse userDetailResponse = openAuthAppService.oauthCallback(registrationId, params);
|
||||||
UserDetails details = databasirUserDetailService.loadUserByUsername(userDetailResponse.getUsername());
|
String username = userDetailResponse.getUsername();
|
||||||
|
UserDetails details = databasirUserDetailService.loadUserByUsername(username, registrationId);
|
||||||
DatabasirOAuth2Authentication authentication = new DatabasirOAuth2Authentication(details);
|
DatabasirOAuth2Authentication authentication = new DatabasirOAuth2Authentication(details);
|
||||||
if (!userDetailResponse.getEnabled()) {
|
if (!userDetailResponse.getEnabled()) {
|
||||||
operationLogService.saveLoginFailedLog(userDetailResponse.getUsername(), "用户被禁用");
|
operationLogService.saveLoginFailedLog(username, registrationId + " 登录", "用户被禁用");
|
||||||
throw new DisabledException("账号已禁用");
|
throw new DisabledException("账号已禁用");
|
||||||
}
|
}
|
||||||
authentication.setAuthenticated(true);
|
authentication.setAuthenticated(true);
|
||||||
|
|
|
@ -36,16 +36,22 @@ public class OAuth2AuthenticationSuccessHandler implements AuthenticationSuccess
|
||||||
HttpServletResponse response,
|
HttpServletResponse response,
|
||||||
Authentication authentication) throws IOException, ServletException {
|
Authentication authentication) throws IOException, ServletException {
|
||||||
DatabasirUserDetails details = (DatabasirUserDetails) authentication.getPrincipal();
|
DatabasirUserDetails details = (DatabasirUserDetails) authentication.getPrincipal();
|
||||||
|
String operationName;
|
||||||
|
if (details.getRegistrationId() != null) {
|
||||||
|
operationName = details.getRegistrationId() + " 登录";
|
||||||
|
} else {
|
||||||
|
operationName = "登录";
|
||||||
|
}
|
||||||
loginService.generate(details.getUser().getId());
|
loginService.generate(details.getUser().getId());
|
||||||
UserLoginResponse data = loginService.getUserLoginData(details.getUser().getId())
|
UserLoginResponse data = loginService.getUserLoginData(details.getUser().getId())
|
||||||
.orElseThrow(() -> {
|
.orElseThrow(() -> {
|
||||||
operationLogService.saveLoginLog(details.getUser(), false, null);
|
operationLogService.saveLoginLog(details.getUser(), false, operationName, null);
|
||||||
return new CredentialsExpiredException("请重新登陆");
|
return new CredentialsExpiredException("请重新登陆");
|
||||||
});
|
});
|
||||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
objectMapper.writeValue(response.getWriter(), JsonData.ok(data));
|
objectMapper.writeValue(response.getWriter(), JsonData.ok(data));
|
||||||
operationLogService.saveLoginLog(details.getUser(), true, null);
|
operationLogService.saveLoginLog(details.getUser(), true, operationName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,17 @@ public class DatabasirUserDetailService implements UserDetailsService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
|
return loadUserByUsername(username, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserDetails loadUserByUsername(String username, String registrationId) throws UsernameNotFoundException {
|
||||||
User user = userDao.selectByEmailOrUsername(username)
|
User user = userDao.selectByEmailOrUsername(username)
|
||||||
.orElseThrow(() -> {
|
.orElseThrow(() -> {
|
||||||
operationLogService.saveLoginFailedLog(username, "用户名不存在");
|
String operationName = registrationId == null ? "登录" : registrationId + " 登录";
|
||||||
|
operationLogService.saveLoginFailedLog(username, operationName, "用户名不存在");
|
||||||
return new UsernameNotFoundException("用户名或密码错误");
|
return new UsernameNotFoundException("用户名或密码错误");
|
||||||
});
|
});
|
||||||
List<UserRole> roles = userRoleDao.selectByUserIds(Collections.singletonList(user.getId()));
|
List<UserRole> roles = userRoleDao.selectByUserIds(Collections.singletonList(user.getId()));
|
||||||
return new DatabasirUserDetails(user, roles);
|
return new DatabasirUserDetails(user, roles, registrationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,9 @@ public class DatabasirUserDetails implements UserDetails {
|
||||||
@Getter
|
@Getter
|
||||||
private final List<UserRole> roles;
|
private final List<UserRole> roles;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String registrationId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
return roles.stream()
|
return roles.stream()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1670752788012" class="icon" viewBox="0 0 1228 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2114" xmlns:xlink="http://www.w3.org/1999/xlink" width="38.375" height="32"><path d="M1045.84 747.027a153.563 153.563 0 0 0-53.156 21.515 129.094 129.094 0 0 1-58.092 35.1c2.953-19.828 12.783-37.926 27.633-51.3a191.186 191.186 0 0 0 26.452-62.142 56.953 56.953 0 1 1 57.164 56.827zM941.639 610.634a190.814 190.814 0 0 0-61.932-26.747 56.953 56.953 0 1 1 56.953-56.953 155.266 155.266 0 0 0 21.263 53.325 129.666 129.666 0 0 1 34.762 58.346 85.978 85.978 0 0 1-50.878-27.97h-0.21z m-93.826-200.728c-17.17-143.817-166.092-256.5-346.274-256.5-191.954 0-348.132 127.744-348.132 284.85a266.33 266.33 0 0 0 124.369 216.169 351.762 351.762 0 0 0 37.969 24.384l-15.44 61.636c5.568 2.616 10.968 5.4 16.663 7.805l77.963-38.981c11.39 2.953 23.372 4.851 35.268 6.876 7.594 1.35 15.188 2.742 22.993 3.67a401.119 401.119 0 0 0 145.547-8.353 281.011 281.011 0 0 0 11.474 62.185 481.153 481.153 0 0 1-108.675 12.698 472.5 472.5 0 0 1-97.621-10.758L262.46 846.21a31.219 31.219 0 0 1-33.877-3.543 31.64 31.64 0 0 1-10.926-32.316l25.312-101.925A330.075 330.075 0 0 1 90.125 438.256c0-192.29 184.19-348.131 411.413-348.131 215.746 0 392.428 140.653 409.64 319.444a276.919 276.919 0 0 0-29.91-2.953c-11.18 0.422-22.36 1.476-33.456 3.248zM716.399 634.47c18.943-3.797 36.957-11.053 53.157-21.515a129.094 129.094 0 0 1 58.134-35.016 86.358 86.358 0 0 1-27.675 51.216c-12.445 18.984-21.389 40.078-26.451 62.184a56.953 56.953 0 1 1-57.165-56.869z m102.6 137.025c18.816 12.614 39.741 21.727 61.763 27a56.953 56.953 0 1 1-56.953 56.953 154.406 154.406 0 0 0-21.094-53.409 129.558 129.558 0 0 1-34.51-58.514 85.888 85.888 0 0 1 50.794 28.308v-0.338z" p-id="2115"></path></svg>
|
After Width: | Height: | Size: 1.9 KiB |
|
@ -1 +1 @@
|
||||||
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.661f96f0.js"></script><script defer="defer" type="module" src="/js/app.9fc48776.js"></script><link href="/css/chunk-vendors.113af7af.css" rel="stylesheet"><link href="/css/app.7cd6f647.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.ed3287b0.js" nomodule></script><script defer="defer" src="/js/app-legacy.35dc6212.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
<!doctype html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir</title><script defer="defer" type="module" src="/js/chunk-vendors.661f96f0.js"></script><script defer="defer" type="module" src="/js/app.484a0d69.js"></script><link href="/css/chunk-vendors.113af7af.css" rel="stylesheet"><link href="/css/app.7cd6f647.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.fc4c9525.js" nomodule></script><script defer="defer" src="/js/app-legacy.781ebf64.js" nomodule></script></head><body><noscript><strong>We're sorry but databasir doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
||||||
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[243],{51243:function(e,t,n){n.r(t),n.d(t,{default:function(){return W}});var r=n(66252),u=(0,r.Uk)(" 系统邮箱设置 "),o=(0,r.Uk)(" : "),l=(0,r.Uk)("保存"),a=(0,r.Uk)("重置");function s(e,t,n,s,i,m){var f=(0,r.up)("box"),d=(0,r.up)("el-icon"),p=(0,r.up)("el-divider"),c=(0,r.up)("el-input"),w=(0,r.up)("el-form-item"),h=(0,r.up)("el-col"),g=(0,r.up)("el-switch"),W=(0,r.up)("el-button"),V=(0,r.up)("el-form"),S=(0,r.up)("el-card"),_=(0,r.up)("el-main"),b=(0,r.up)("el-container");return(0,r.wg)(),(0,r.j4)(b,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(_,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(S,{shadow:"hover",style:{"max-width":"600px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(p,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(d,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(f)]})),_:1}),u]})),_:1}),(0,r.Wm)(V,{model:i.form,"label-position":"top",rules:i.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(w,{label:"邮箱账号",prop:"username"},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.username,"onUpdate:modelValue":t[0]||(t[0]=function(e){return i.form.username=e}),placeholder:"请输入邮箱账号"},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{label:"邮箱密码",prop:"password"},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.password,"onUpdate:modelValue":t[1]||(t[1]=function(e){return i.form.password=e}),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{label:"SMTP",prop:"smtpHost"},{default:(0,r.w5)((function(){return[(0,r.Wm)(h,{span:12},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.smtpHost,"onUpdate:modelValue":t[2]||(t[2]=function(e){return i.form.smtpHost=e}),placeholder:"SMTP Host"},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(h,{span:1,style:{"text-align":"center"}},{default:(0,r.w5)((function(){return[o]})),_:1}),(0,r.Wm)(h,{span:6},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.smtpPort,"onUpdate:modelValue":t[3]||(t[3]=function(e){return i.form.smtpPort=e}),placeholder:"SMTP Port"},null,8,["modelValue"])]})),_:1})]})),_:1}),(0,r.Wm)(w,{label:"启用 SSL",prop:"useSSL"},{default:(0,r.w5)((function(){return[(0,r.Wm)(g,{modelValue:i.form.useSSL,"onUpdate:modelValue":t[4]||(t[4]=function(e){return i.form.useSSL=e})},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{style:{"margin-top":"38px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(W,{type:"primary",onClick:t[5]||(t[5]=function(e){return m.onSubmit("formRef")})},{default:(0,r.w5)((function(){return[l]})),_:1}),(0,r.Wm)(W,{type:"danger",onClick:t[6]||(t[6]=function(e){return m.onReset()})},{default:(0,r.w5)((function(){return[a]})),_:1})]})),_:1})]})),_:1},8,["model","rules"])]})),_:1})]})),_:1})]})),_:1})}var i=n(48534),m=(n(35666),n(63872)),f="/api/v1.0/settings",d=function(){return m.Z.get(f+"/sys_email")},p=function(e){return m.Z.post(f+"/sys_email",e)},c=function(){return m.Z["delete"](f+"/sys_email")},w={data:function(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null,useSSL:!1},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted:function(){this.fetchSysMail()},methods:{requiredInputValidRule:function(e){return{required:!0,message:e,trigger:"blur"}},fetchSysMail:function(){var e=this;return(0,i.Z)(regeneratorRuntime.mark((function t(){var n;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,d().then((function(e){return e.data}));case 2:n=t.sent,n&&(e.form=n);case 4:case"end":return t.stop()}}),t)})))()},onSubmit:function(){var e=this;this.$refs.formRef.validate((function(t){return t?(p(e.form).then((function(t){t.errCode||e.$message.success("更新成功")})),!0):(e.$message.error("请完善表单相关信息!"),!1)}))},onReset:function(){var e=this;this.$confirm("确认重置系统邮件吗?删除后数据将无法恢复","警告",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then((function(){c().then((function(t){t.errCode||(e.form={},e.$message.success("重置成功"))}))}))}}},h=n(83744);const g=(0,h.Z)(w,[["render",s]]);var W=g}}]);
|
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[243],{51243:function(e,t,n){n.r(t),n.d(t,{default:function(){return W}});var r=n(66252),u=(0,r.Uk)(" 系统邮箱设置 "),o=(0,r.Uk)(" : "),l=(0,r.Uk)("保存"),a=(0,r.Uk)("重置");function s(e,t,n,s,i,m){var f=(0,r.up)("box"),d=(0,r.up)("el-icon"),p=(0,r.up)("el-divider"),c=(0,r.up)("el-input"),w=(0,r.up)("el-form-item"),h=(0,r.up)("el-col"),g=(0,r.up)("el-switch"),W=(0,r.up)("el-button"),V=(0,r.up)("el-form"),S=(0,r.up)("el-card"),_=(0,r.up)("el-main"),b=(0,r.up)("el-container");return(0,r.wg)(),(0,r.j4)(b,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(_,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(S,{shadow:"hover",style:{"max-width":"600px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(p,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(d,null,{default:(0,r.w5)((function(){return[(0,r.Wm)(f)]})),_:1}),u]})),_:1}),(0,r.Wm)(V,{model:i.form,"label-position":"top",rules:i.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(w,{label:"邮箱账号",prop:"username"},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.username,"onUpdate:modelValue":t[0]||(t[0]=function(e){return i.form.username=e}),placeholder:"请输入邮箱账号"},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{label:"邮箱密码",prop:"password"},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.password,"onUpdate:modelValue":t[1]||(t[1]=function(e){return i.form.password=e}),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{label:"SMTP",prop:"smtpHost"},{default:(0,r.w5)((function(){return[(0,r.Wm)(h,{span:12},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.smtpHost,"onUpdate:modelValue":t[2]||(t[2]=function(e){return i.form.smtpHost=e}),placeholder:"SMTP Host"},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(h,{span:1,style:{"text-align":"center"}},{default:(0,r.w5)((function(){return[o]})),_:1}),(0,r.Wm)(h,{span:6},{default:(0,r.w5)((function(){return[(0,r.Wm)(c,{modelValue:i.form.smtpPort,"onUpdate:modelValue":t[3]||(t[3]=function(e){return i.form.smtpPort=e}),placeholder:"SMTP Port"},null,8,["modelValue"])]})),_:1})]})),_:1}),(0,r.Wm)(w,{label:"启用 SSL",prop:"useSSL"},{default:(0,r.w5)((function(){return[(0,r.Wm)(g,{modelValue:i.form.useSSL,"onUpdate:modelValue":t[4]||(t[4]=function(e){return i.form.useSSL=e})},null,8,["modelValue"])]})),_:1}),(0,r.Wm)(w,{style:{"margin-top":"38px"}},{default:(0,r.w5)((function(){return[(0,r.Wm)(W,{type:"primary",onClick:t[5]||(t[5]=function(e){return m.onSubmit("formRef")})},{default:(0,r.w5)((function(){return[l]})),_:1}),(0,r.Wm)(W,{type:"danger",onClick:t[6]||(t[6]=function(e){return m.onReset()})},{default:(0,r.w5)((function(){return[a]})),_:1})]})),_:1})]})),_:1},8,["model","rules"])]})),_:1})]})),_:1})]})),_:1})}var i=n(48534),m=(n(35666),n(63872)),f="/api/v1.0/settings",d=function(){return m.Z.get(f+"/sys_email")},p=function(e){return m.Z.post(f+"/sys_email",e)},c=function(){return m.Z["delete"](f+"/sys_email")},w={data:function(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null,useSSL:!1},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted:function(){this.fetchSysMail()},methods:{requiredInputValidRule:function(e){return{required:!0,message:e,trigger:"blur"}},fetchSysMail:function(){var e=this;return(0,i.Z)(regeneratorRuntime.mark((function t(){var n;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,d().then((function(e){return e.data}));case 2:n=t.sent,n&&(e.form=n);case 4:case"end":return t.stop()}}),t)})))()},onSubmit:function(){var e=this;this.$refs.formRef.validate((function(t){return t?(p(e.form).then((function(t){t.errCode||e.$message.success("更新成功")})),!0):(e.$message.error("请完善表单相关信息!"),!1)}))},onReset:function(){var e=this;this.$confirm("确认重置系统邮件吗?删除后数据将无法恢复","警告",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then((function(){c().then((function(t){t.errCode||(e.form={},e.$message.success("重置成功"))}))}))}}},h=n(83744);const g=(0,h.Z)(w,[["render",s]]);var W=g}}]);
|
||||||
//# sourceMappingURL=243-legacy.e002ee9f.js.map
|
//# sourceMappingURL=243-legacy.e96b81cc.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
||||||
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[243],{51243:function(e,l,t){t.r(l),t.d(l,{default:function(){return W}});var a=t(66252);const s=(0,a.Uk)(" 系统邮箱设置 "),r=(0,a.Uk)(" : "),u=(0,a.Uk)("保存"),o=(0,a.Uk)("重置");function m(e,l,t,m,n,d){const p=(0,a.up)("box"),i=(0,a.up)("el-icon"),f=(0,a.up)("el-divider"),c=(0,a.up)("el-input"),h=(0,a.up)("el-form-item"),w=(0,a.up)("el-col"),W=(0,a.up)("el-switch"),V=(0,a.up)("el-button"),g=(0,a.up)("el-form"),S=(0,a.up)("el-card"),_=(0,a.up)("el-main"),b=(0,a.up)("el-container");return(0,a.wg)(),(0,a.j4)(b,null,{default:(0,a.w5)((()=>[(0,a.Wm)(_,null,{default:(0,a.w5)((()=>[(0,a.Wm)(S,{shadow:"hover",style:{"max-width":"600px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(f,null,{default:(0,a.w5)((()=>[(0,a.Wm)(i,null,{default:(0,a.w5)((()=>[(0,a.Wm)(p)])),_:1}),s])),_:1}),(0,a.Wm)(g,{model:n.form,"label-position":"top",rules:n.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(h,{label:"邮箱账号",prop:"username"},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.username,"onUpdate:modelValue":l[0]||(l[0]=e=>n.form.username=e),placeholder:"请输入邮箱账号"},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{label:"邮箱密码",prop:"password"},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.password,"onUpdate:modelValue":l[1]||(l[1]=e=>n.form.password=e),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{label:"SMTP",prop:"smtpHost"},{default:(0,a.w5)((()=>[(0,a.Wm)(w,{span:12},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.smtpHost,"onUpdate:modelValue":l[2]||(l[2]=e=>n.form.smtpHost=e),placeholder:"SMTP Host"},null,8,["modelValue"])])),_:1}),(0,a.Wm)(w,{span:1,style:{"text-align":"center"}},{default:(0,a.w5)((()=>[r])),_:1}),(0,a.Wm)(w,{span:6},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.smtpPort,"onUpdate:modelValue":l[3]||(l[3]=e=>n.form.smtpPort=e),placeholder:"SMTP Port"},null,8,["modelValue"])])),_:1})])),_:1}),(0,a.Wm)(h,{label:"启用 SSL",prop:"useSSL"},{default:(0,a.w5)((()=>[(0,a.Wm)(W,{modelValue:n.form.useSSL,"onUpdate:modelValue":l[4]||(l[4]=e=>n.form.useSSL=e)},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{style:{"margin-top":"38px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(V,{type:"primary",onClick:l[5]||(l[5]=e=>d.onSubmit("formRef"))},{default:(0,a.w5)((()=>[u])),_:1}),(0,a.Wm)(V,{type:"danger",onClick:l[6]||(l[6]=e=>d.onReset())},{default:(0,a.w5)((()=>[o])),_:1})])),_:1})])),_:1},8,["model","rules"])])),_:1})])),_:1})])),_:1})}var n=t(63872);const d="/api/v1.0/settings",p=()=>n.Z.get(d+"/sys_email"),i=e=>n.Z.post(d+"/sys_email",e),f=()=>n.Z["delete"](d+"/sys_email");var c={data(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null,useSSL:!1},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted(){this.fetchSysMail()},methods:{requiredInputValidRule(e){return{required:!0,message:e,trigger:"blur"}},async fetchSysMail(){const e=await p().then((e=>e.data));e&&(this.form=e)},onSubmit(){this.$refs.formRef.validate((e=>e?(i(this.form).then((e=>{e.errCode||this.$message.success("更新成功")})),!0):(this.$message.error("请完善表单相关信息!"),!1)))},onReset(){this.$confirm("确认重置系统邮件吗?删除后数据将无法恢复","警告",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then((()=>{f().then((e=>{e.errCode||(this.form={},this.$message.success("重置成功"))}))}))}}},h=t(83744);const w=(0,h.Z)(c,[["render",m]]);var W=w}}]);
|
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[243],{51243:function(e,l,t){t.r(l),t.d(l,{default:function(){return W}});var a=t(66252);const s=(0,a.Uk)(" 系统邮箱设置 "),r=(0,a.Uk)(" : "),u=(0,a.Uk)("保存"),o=(0,a.Uk)("重置");function m(e,l,t,m,n,d){const p=(0,a.up)("box"),i=(0,a.up)("el-icon"),f=(0,a.up)("el-divider"),c=(0,a.up)("el-input"),h=(0,a.up)("el-form-item"),w=(0,a.up)("el-col"),W=(0,a.up)("el-switch"),V=(0,a.up)("el-button"),g=(0,a.up)("el-form"),S=(0,a.up)("el-card"),_=(0,a.up)("el-main"),b=(0,a.up)("el-container");return(0,a.wg)(),(0,a.j4)(b,null,{default:(0,a.w5)((()=>[(0,a.Wm)(_,null,{default:(0,a.w5)((()=>[(0,a.Wm)(S,{shadow:"hover",style:{"max-width":"600px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(f,null,{default:(0,a.w5)((()=>[(0,a.Wm)(i,null,{default:(0,a.w5)((()=>[(0,a.Wm)(p)])),_:1}),s])),_:1}),(0,a.Wm)(g,{model:n.form,"label-position":"top",rules:n.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(h,{label:"邮箱账号",prop:"username"},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.username,"onUpdate:modelValue":l[0]||(l[0]=e=>n.form.username=e),placeholder:"请输入邮箱账号"},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{label:"邮箱密码",prop:"password"},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.password,"onUpdate:modelValue":l[1]||(l[1]=e=>n.form.password=e),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{label:"SMTP",prop:"smtpHost"},{default:(0,a.w5)((()=>[(0,a.Wm)(w,{span:12},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.smtpHost,"onUpdate:modelValue":l[2]||(l[2]=e=>n.form.smtpHost=e),placeholder:"SMTP Host"},null,8,["modelValue"])])),_:1}),(0,a.Wm)(w,{span:1,style:{"text-align":"center"}},{default:(0,a.w5)((()=>[r])),_:1}),(0,a.Wm)(w,{span:6},{default:(0,a.w5)((()=>[(0,a.Wm)(c,{modelValue:n.form.smtpPort,"onUpdate:modelValue":l[3]||(l[3]=e=>n.form.smtpPort=e),placeholder:"SMTP Port"},null,8,["modelValue"])])),_:1})])),_:1}),(0,a.Wm)(h,{label:"启用 SSL",prop:"useSSL"},{default:(0,a.w5)((()=>[(0,a.Wm)(W,{modelValue:n.form.useSSL,"onUpdate:modelValue":l[4]||(l[4]=e=>n.form.useSSL=e)},null,8,["modelValue"])])),_:1}),(0,a.Wm)(h,{style:{"margin-top":"38px"}},{default:(0,a.w5)((()=>[(0,a.Wm)(V,{type:"primary",onClick:l[5]||(l[5]=e=>d.onSubmit("formRef"))},{default:(0,a.w5)((()=>[u])),_:1}),(0,a.Wm)(V,{type:"danger",onClick:l[6]||(l[6]=e=>d.onReset())},{default:(0,a.w5)((()=>[o])),_:1})])),_:1})])),_:1},8,["model","rules"])])),_:1})])),_:1})])),_:1})}var n=t(63872);const d="/api/v1.0/settings",p=()=>n.Z.get(d+"/sys_email"),i=e=>n.Z.post(d+"/sys_email",e),f=()=>n.Z["delete"](d+"/sys_email");var c={data(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null,useSSL:!1},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted(){this.fetchSysMail()},methods:{requiredInputValidRule(e){return{required:!0,message:e,trigger:"blur"}},async fetchSysMail(){const e=await p().then((e=>e.data));e&&(this.form=e)},onSubmit(){this.$refs.formRef.validate((e=>e?(i(this.form).then((e=>{e.errCode||this.$message.success("更新成功")})),!0):(this.$message.error("请完善表单相关信息!"),!1)))},onReset(){this.$confirm("确认重置系统邮件吗?删除后数据将无法恢复","警告",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}).then((()=>{f().then((e=>{e.errCode||(this.form={},this.$message.success("重置成功"))}))}))}}},h=t(83744);const w=(0,h.Z)(c,[["render",m]]);var W=w}}]);
|
||||||
//# sourceMappingURL=243.321a300e.js.map
|
//# sourceMappingURL=243.becb5f60.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
||||||
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[865],{68865:function(t,n,e){e.r(n),e.d(n,{default:function(){return f}});var i=e(66252),a=e(49963),r=(0,i.Uk)("立即跳转");function o(t,n,e,o,u,l){var s=(0,i.up)("el-button"),c=(0,i.up)("el-result"),d=(0,i.up)("el-main"),f=(0,i.up)("el-container"),g=(0,i.Q2)("loading");return(0,i.wg)(),(0,i.j4)(f,null,{default:(0,i.w5)((function(){return[(0,i.wy)(((0,i.wg)(),(0,i.j4)(d,{class:"login-main"},{default:(0,i.w5)((function(){return[(0,i.wy)((0,i.Wm)(c,{icon:u.icon,title:u.title,"sub-title":u.subTitle},{extra:(0,i.w5)((function(){return[(0,i.Wm)(s,{type:"primary",onClick:n[0]||(n[0]=function(t){return l.toIndexPage()})},{default:(0,i.w5)((function(){return[r]})),_:1})]})),_:1},8,["icon","title","sub-title"]),[[a.F8,!u.loading]])]})),_:1})),[[g,u.loading]])]})),_:1})}var u=e(40152),l=e(51836),s={data:function(){return{registrationId:null,icon:"",title:"",subTitle:"",loading:!0}},created:function(){this.registrationId=this.$route.params.id,this.login()},methods:{login:function(){var t=this,n=window.location.href,e=this.$route.query;e.redirect_uri=n,(0,u.rd)(this.registrationId,e).then((function(n){n.errCode?(t.title=n.errMessage,t.icon="error"):(l.E.saveUserLoginData(n.data),t.$store.commit("userUpdate",{nickname:n.data.nickname,username:n.data.username,email:n.data.email,avatar:n.data.avatar}),t.icon="success",t.$router.push({path:"/groups"})),t.loading=!1})).catch((function(n){console.log("login failed: "+n),t.icon="error",t.title="登陆失败,请重试",t.loading=!1}))},toIndexPage:function(){this.$router.push({path:"/"})}}},c=e(83744);const d=(0,c.Z)(s,[["render",o]]);var f=d}}]);
|
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[865],{68865:function(t,n,e){e.r(n),e.d(n,{default:function(){return f}});var i=e(66252),a=e(49963),r=(0,i.Uk)("立即跳转");function o(t,n,e,o,u,l){var s=(0,i.up)("el-button"),c=(0,i.up)("el-result"),d=(0,i.up)("el-main"),f=(0,i.up)("el-container"),g=(0,i.Q2)("loading");return(0,i.wg)(),(0,i.j4)(f,null,{default:(0,i.w5)((function(){return[(0,i.wy)(((0,i.wg)(),(0,i.j4)(d,{class:"login-main"},{default:(0,i.w5)((function(){return[(0,i.wy)((0,i.Wm)(c,{icon:u.icon,title:u.title,"sub-title":u.subTitle},{extra:(0,i.w5)((function(){return[(0,i.Wm)(s,{type:"primary",onClick:n[0]||(n[0]=function(t){return l.toIndexPage()})},{default:(0,i.w5)((function(){return[r]})),_:1})]})),_:1},8,["icon","title","sub-title"]),[[a.F8,!u.loading]])]})),_:1})),[[g,u.loading]])]})),_:1})}var u=e(40152),l=e(51836),s={data:function(){return{registrationId:null,icon:"",title:"",subTitle:"",loading:!0}},created:function(){this.registrationId=this.$route.params.id,this.login()},methods:{login:function(){var t=this,n=window.location.href,e=this.$route.query;e.redirect_uri=n,(0,u.rd)(this.registrationId,e).then((function(n){n.errCode?(t.title=n.errMessage,t.icon="error"):(l.E.saveUserLoginData(n.data),t.$store.commit("userUpdate",{nickname:n.data.nickname,username:n.data.username,email:n.data.email,avatar:n.data.avatar}),t.icon="success",t.$router.push({path:"/groups"})),t.loading=!1})).catch((function(n){console.log("login failed: "+n),t.icon="error",t.title="登陆失败,请重试",t.loading=!1}))},toIndexPage:function(){this.$router.push({path:"/"})}}},c=e(83744);const d=(0,c.Z)(s,[["render",o]]);var f=d}}]);
|
||||||
//# sourceMappingURL=865-legacy.07ab0cbc.js.map
|
//# sourceMappingURL=865-legacy.28336588.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"js/865-legacy.07ab0cbc.js","mappings":"oMAUiE,Q,qKAT7DA,EAAAA,EAAAA,IAaeC,EAAA,M,kBAZX,iBAWU,uBAXVD,EAAAA,EAAAA,IAWUE,EAAA,CAXmBC,MAAM,cAAY,C,kBAC3C,iBASY,WATZC,EAAAA,EAAAA,IASYC,EAAA,CARPC,KAAMC,EAAAA,KACNC,MAAOD,EAAAA,MACP,YAAWA,EAAAA,UAHhB,CAMeE,OAAK,SAChB,iBAAiE,EAAjEL,EAAAA,EAAAA,IAAiEM,EAAA,CAAtDC,KAAK,UAAWC,QAAK,+BAAEC,EAAAA,iBAAlC,C,kBAAiD,iBAAI,O,eAPzD,wCAIaN,EAAAA,e,OALjB,IAAoBA,EAAAA,e,gCA2B5B,GACIO,KADW,WAEP,MAAO,CACHC,eAAgB,KAChBT,KAAM,GACNE,MAAO,GACPQ,SAAU,GACVC,SAAS,IAIjBC,QAXW,WAYPC,KAAKJ,eAAiBI,KAAKC,OAAOC,OAAOC,GACzCH,KAAKI,SAGTC,QAAS,CACJD,MADI,WACI,WACCE,EAAcC,OAAOC,SAASC,KAC9BP,EAASF,KAAKC,OAAOS,MAC3BR,EAAOS,aAAeL,GACtBM,EAAAA,EAAAA,IAAYZ,KAAKJ,eAAgBM,GAAQW,MAAK,SAAAC,GACrCA,EAAKC,SAWN,EAAK1B,MAAQyB,EAAKE,WAClB,EAAK7B,KAAO,UAXZ8B,EAAAA,EAAAA,kBAAuBH,EAAKnB,MAC5B,EAAKuB,OAAOC,OAAO,aAAc,CAC7BC,SAAUN,EAAKnB,KAAKyB,SACpBC,SAAUP,EAAKnB,KAAK0B,SACpBC,MAAOR,EAAKnB,KAAK2B,MACjBC,OAAQT,EAAKnB,KAAK4B,SAEtB,EAAKpC,KAAK,UACV,EAAKqC,QAAQC,KAAK,CAACC,KAAM,aAK7B,EAAK5B,SAAU,KAChB6B,OAAM,SAAAC,GACLC,QAAQC,IAAI,iBAAiBF,GAC7B,EAAKzC,KAAO,QACZ,EAAKE,MAAQ,WACb,EAAKS,SAAU,MAIvBiC,YA7BK,WA8BD/B,KAAKwB,QAAQC,KAAK,CAACC,KAAM,S,WCpErC,MAAMM,GAA2B,OAAgB,EAAQ,CAAC,CAAC,SAASC,KAEpE","sources":["webpack://databasir/./src/views/OAuth2Login.vue","webpack://databasir/./src/views/OAuth2Login.vue?b6ea"],"sourcesContent":["<template>\r\n <el-container>\r\n <el-main v-loading=\"loading\" class=\"login-main\">\r\n <el-result\r\n :icon=\"icon\"\r\n :title=\"title\"\r\n :sub-title=\"subTitle\"\r\n v-show=\"!loading\"\r\n >\r\n <template #extra>\r\n <el-button type=\"primary\" @click=\"toIndexPage()\">立即跳转</el-button>\r\n </template>\r\n </el-result>\r\n </el-main>\r\n </el-container>\r\n</template>\r\n\r\n<style>\r\n.login-main {\r\n margin: 0 auto;\r\n margin-top: 200px;\r\n}\r\n\r\n</style>\r\n<script>\r\nimport { oauth2Login } from \"../api/Login\"\r\nimport { user } from \"../utils/auth\"\r\n\r\n\r\nexport default {\r\n data() {\r\n return {\r\n registrationId: null,\r\n icon: '',\r\n title: '',\r\n subTitle: '',\r\n loading: true,\r\n }\r\n },\r\n\r\n created() {\r\n this.registrationId = this.$route.params.id\r\n this.login()\r\n },\r\n\r\n methods: {\r\n login() {\r\n const redirectUri = window.location.href\r\n const params = this.$route.query\r\n params.redirect_uri = redirectUri\r\n oauth2Login(this.registrationId, params).then(resp => {\r\n if (!resp.errCode) {\r\n user.saveUserLoginData(resp.data)\r\n this.$store.commit('userUpdate', {\r\n nickname: resp.data.nickname,\r\n username: resp.data.username,\r\n email: resp.data.email,\r\n avatar: resp.data.avatar\r\n })\r\n this.icon='success'\r\n this.$router.push({path: '/groups'})\r\n } else {\r\n this.title = resp.errMessage\r\n this.icon = 'error'\r\n }\r\n this.loading = false\r\n }).catch(err => {\r\n console.log('login failed: '+err)\r\n this.icon = 'error'\r\n this.title = '登陆失败,请重试'\r\n this.loading = false\r\n })\r\n },\r\n\r\n toIndexPage() {\r\n this.$router.push({path: '/'})\r\n }\r\n }\r\n}\r\n</script>","import { render } from \"./OAuth2Login.vue?vue&type=template&id=65bc9922\"\nimport script from \"./OAuth2Login.vue?vue&type=script&lang=js\"\nexport * from \"./OAuth2Login.vue?vue&type=script&lang=js\"\n\nimport \"./OAuth2Login.vue?vue&type=style&index=0&id=65bc9922&lang=css\"\n\nimport exportComponent from \"D:\\\\workspace\\\\github\\\\databasir\\\\databasir-frontend\\\\node_modules\\\\vue-loader\\\\dist\\\\exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__"],"names":["_createBlock","_component_el_container","_component_el_main","class","_createVNode","_component_el_result","icon","$data","title","extra","_component_el_button","type","onClick","$options","data","registrationId","subTitle","loading","created","this","$route","params","id","login","methods","redirectUri","window","location","href","query","redirect_uri","oauth2Login","then","resp","errCode","errMessage","user","$store","commit","nickname","username","email","avatar","$router","push","path","catch","err","console","log","toIndexPage","__exports__","render"],"sourceRoot":""}
|
{"version":3,"file":"js/865-legacy.28336588.js","mappings":"oMAUiE,Q,qKAT7DA,EAAAA,EAAAA,IAaeC,EAAA,M,kBAZX,iBAWU,uBAXVD,EAAAA,EAAAA,IAWUE,EAAA,CAXmBC,MAAM,cAAY,C,kBAC3C,iBASY,WATZC,EAAAA,EAAAA,IASYC,EAAA,CARPC,KAAMC,EAAAA,KACNC,MAAOD,EAAAA,MACP,YAAWA,EAAAA,UAHhB,CAMeE,OAAK,SAChB,iBAAiE,EAAjEL,EAAAA,EAAAA,IAAiEM,EAAA,CAAtDC,KAAK,UAAWC,QAAK,+BAAEC,EAAAA,iBAAlC,C,kBAAiD,iBAAI,O,eAPzD,wCAIaN,EAAAA,e,OALjB,IAAoBA,EAAAA,e,gCA2B5B,GACIO,KADW,WAEP,MAAO,CACHC,eAAgB,KAChBT,KAAM,GACNE,MAAO,GACPQ,SAAU,GACVC,SAAS,IAIjBC,QAXW,WAYPC,KAAKJ,eAAiBI,KAAKC,OAAOC,OAAOC,GACzCH,KAAKI,SAGTC,QAAS,CACJD,MADI,WACI,WACCE,EAAcC,OAAOC,SAASC,KAC9BP,EAASF,KAAKC,OAAOS,MAC3BR,EAAOS,aAAeL,GACtBM,EAAAA,EAAAA,IAAYZ,KAAKJ,eAAgBM,GAAQW,MAAK,SAAAC,GACrCA,EAAKC,SAWN,EAAK1B,MAAQyB,EAAKE,WAClB,EAAK7B,KAAO,UAXZ8B,EAAAA,EAAAA,kBAAuBH,EAAKnB,MAC5B,EAAKuB,OAAOC,OAAO,aAAc,CAC7BC,SAAUN,EAAKnB,KAAKyB,SACpBC,SAAUP,EAAKnB,KAAK0B,SACpBC,MAAOR,EAAKnB,KAAK2B,MACjBC,OAAQT,EAAKnB,KAAK4B,SAEtB,EAAKpC,KAAK,UACV,EAAKqC,QAAQC,KAAK,CAACC,KAAM,aAK7B,EAAK5B,SAAU,KAChB6B,OAAM,SAAAC,GACLC,QAAQC,IAAI,iBAAiBF,GAC7B,EAAKzC,KAAO,QACZ,EAAKE,MAAQ,WACb,EAAKS,SAAU,MAIvBiC,YA7BK,WA8BD/B,KAAKwB,QAAQC,KAAK,CAACC,KAAM,S,WCpErC,MAAMM,GAA2B,OAAgB,EAAQ,CAAC,CAAC,SAASC,KAEpE","sources":["webpack://databasir/./src/views/OAuth2Login.vue","webpack://databasir/./src/views/OAuth2Login.vue?b6ea"],"sourcesContent":["<template>\r\n <el-container>\r\n <el-main v-loading=\"loading\" class=\"login-main\">\r\n <el-result\r\n :icon=\"icon\"\r\n :title=\"title\"\r\n :sub-title=\"subTitle\"\r\n v-show=\"!loading\"\r\n >\r\n <template #extra>\r\n <el-button type=\"primary\" @click=\"toIndexPage()\">立即跳转</el-button>\r\n </template>\r\n </el-result>\r\n </el-main>\r\n </el-container>\r\n</template>\r\n\r\n<style>\r\n.login-main {\r\n margin: 0 auto;\r\n margin-top: 200px;\r\n}\r\n\r\n</style>\r\n<script>\r\nimport { oauth2Login } from \"../api/Login\"\r\nimport { user } from \"../utils/auth\"\r\n\r\n\r\nexport default {\r\n data() {\r\n return {\r\n registrationId: null,\r\n icon: '',\r\n title: '',\r\n subTitle: '',\r\n loading: true,\r\n }\r\n },\r\n\r\n created() {\r\n this.registrationId = this.$route.params.id\r\n this.login()\r\n },\r\n\r\n methods: {\r\n login() {\r\n const redirectUri = window.location.href\r\n const params = this.$route.query\r\n params.redirect_uri = redirectUri\r\n oauth2Login(this.registrationId, params).then(resp => {\r\n if (!resp.errCode) {\r\n user.saveUserLoginData(resp.data)\r\n this.$store.commit('userUpdate', {\r\n nickname: resp.data.nickname,\r\n username: resp.data.username,\r\n email: resp.data.email,\r\n avatar: resp.data.avatar\r\n })\r\n this.icon='success'\r\n this.$router.push({path: '/groups'})\r\n } else {\r\n this.title = resp.errMessage\r\n this.icon = 'error'\r\n }\r\n this.loading = false\r\n }).catch(err => {\r\n console.log('login failed: '+err)\r\n this.icon = 'error'\r\n this.title = '登陆失败,请重试'\r\n this.loading = false\r\n })\r\n },\r\n\r\n toIndexPage() {\r\n this.$router.push({path: '/'})\r\n }\r\n }\r\n}\r\n</script>","import { render } from \"./OAuth2Login.vue?vue&type=template&id=65bc9922\"\nimport script from \"./OAuth2Login.vue?vue&type=script&lang=js\"\nexport * from \"./OAuth2Login.vue?vue&type=script&lang=js\"\n\nimport \"./OAuth2Login.vue?vue&type=style&index=0&id=65bc9922&lang=css\"\n\nimport exportComponent from \"D:\\\\workspace\\\\github\\\\databasir\\\\databasir-frontend\\\\node_modules\\\\vue-loader\\\\dist\\\\exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__"],"names":["_createBlock","_component_el_container","_component_el_main","class","_createVNode","_component_el_result","icon","$data","title","extra","_component_el_button","type","onClick","$options","data","registrationId","subTitle","loading","created","this","$route","params","id","login","methods","redirectUri","window","location","href","query","redirect_uri","oauth2Login","then","resp","errCode","errMessage","user","$store","commit","nickname","username","email","avatar","$router","push","path","catch","err","console","log","toIndexPage","__exports__","render"],"sourceRoot":""}
|
|
@ -1,2 +1,2 @@
|
||||||
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[865],{68865:function(t,e,i){i.r(e),i.d(e,{default:function(){return h}});var a=i(66252),r=i(49963);const n=(0,a.Uk)("立即跳转");function s(t,e,i,s,o,l){const u=(0,a.up)("el-button"),d=(0,a.up)("el-result"),c=(0,a.up)("el-main"),h=(0,a.up)("el-container"),g=(0,a.Q2)("loading");return(0,a.wg)(),(0,a.j4)(h,null,{default:(0,a.w5)((()=>[(0,a.wy)(((0,a.wg)(),(0,a.j4)(c,{class:"login-main"},{default:(0,a.w5)((()=>[(0,a.wy)((0,a.Wm)(d,{icon:o.icon,title:o.title,"sub-title":o.subTitle},{extra:(0,a.w5)((()=>[(0,a.Wm)(u,{type:"primary",onClick:e[0]||(e[0]=t=>l.toIndexPage())},{default:(0,a.w5)((()=>[n])),_:1})])),_:1},8,["icon","title","sub-title"]),[[r.F8,!o.loading]])])),_:1})),[[g,o.loading]])])),_:1})}var o=i(40152),l=i(51836),u={data(){return{registrationId:null,icon:"",title:"",subTitle:"",loading:!0}},created(){this.registrationId=this.$route.params.id,this.login()},methods:{login(){const t=window.location.href,e=this.$route.query;e.redirect_uri=t,(0,o.rd)(this.registrationId,e).then((t=>{t.errCode?(this.title=t.errMessage,this.icon="error"):(l.E.saveUserLoginData(t.data),this.$store.commit("userUpdate",{nickname:t.data.nickname,username:t.data.username,email:t.data.email,avatar:t.data.avatar}),this.icon="success",this.$router.push({path:"/groups"})),this.loading=!1})).catch((t=>{console.log("login failed: "+t),this.icon="error",this.title="登陆失败,请重试",this.loading=!1}))},toIndexPage(){this.$router.push({path:"/"})}}},d=i(83744);const c=(0,d.Z)(u,[["render",s]]);var h=c}}]);
|
"use strict";(self["webpackChunkdatabasir"]=self["webpackChunkdatabasir"]||[]).push([[865],{68865:function(t,e,i){i.r(e),i.d(e,{default:function(){return h}});var a=i(66252),r=i(49963);const n=(0,a.Uk)("立即跳转");function s(t,e,i,s,o,l){const u=(0,a.up)("el-button"),d=(0,a.up)("el-result"),c=(0,a.up)("el-main"),h=(0,a.up)("el-container"),g=(0,a.Q2)("loading");return(0,a.wg)(),(0,a.j4)(h,null,{default:(0,a.w5)((()=>[(0,a.wy)(((0,a.wg)(),(0,a.j4)(c,{class:"login-main"},{default:(0,a.w5)((()=>[(0,a.wy)((0,a.Wm)(d,{icon:o.icon,title:o.title,"sub-title":o.subTitle},{extra:(0,a.w5)((()=>[(0,a.Wm)(u,{type:"primary",onClick:e[0]||(e[0]=t=>l.toIndexPage())},{default:(0,a.w5)((()=>[n])),_:1})])),_:1},8,["icon","title","sub-title"]),[[r.F8,!o.loading]])])),_:1})),[[g,o.loading]])])),_:1})}var o=i(40152),l=i(51836),u={data(){return{registrationId:null,icon:"",title:"",subTitle:"",loading:!0}},created(){this.registrationId=this.$route.params.id,this.login()},methods:{login(){const t=window.location.href,e=this.$route.query;e.redirect_uri=t,(0,o.rd)(this.registrationId,e).then((t=>{t.errCode?(this.title=t.errMessage,this.icon="error"):(l.E.saveUserLoginData(t.data),this.$store.commit("userUpdate",{nickname:t.data.nickname,username:t.data.username,email:t.data.email,avatar:t.data.avatar}),this.icon="success",this.$router.push({path:"/groups"})),this.loading=!1})).catch((t=>{console.log("login failed: "+t),this.icon="error",this.title="登陆失败,请重试",this.loading=!1}))},toIndexPage(){this.$router.push({path:"/"})}}},d=i(83744);const c=(0,d.Z)(u,[["render",s]]);var h=c}}]);
|
||||||
//# sourceMappingURL=865.1902074c.js.map
|
//# sourceMappingURL=865.60ba33fe.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"js/865.1902074c.js","mappings":"0MAUiE,Q,uKAT7DA,EAAAA,EAAAA,IAaeC,EAAA,M,kBAZX,IAWU,uBAXVD,EAAAA,EAAAA,IAWUE,EAAA,CAXmBC,MAAM,cAAY,C,kBAC3C,IASY,WATZC,EAAAA,EAAAA,IASYC,EAAA,CARPC,KAAMC,EAAAA,KACNC,MAAOD,EAAAA,MACP,YAAWA,EAAAA,UAHhB,CAMeE,OAAK,SAChB,IAAiE,EAAjEL,EAAAA,EAAAA,IAAiEM,EAAA,CAAtDC,KAAK,UAAWC,QAAK,eAAEC,EAAAA,gBAAlC,C,kBAAiD,IAAI,M,cAPzD,wCAIaN,EAAAA,c,OALjB,IAAoBA,EAAAA,c,gCA2B5B,GACIO,OACI,MAAO,CACHC,eAAgB,KAChBT,KAAM,GACNE,MAAO,GACPQ,SAAU,GACVC,SAAS,IAIjBC,UACIC,KAAKJ,eAAiBI,KAAKC,OAAOC,OAAOC,GACzCH,KAAKI,SAGTC,QAAS,CACJD,QACG,MAAME,EAAcC,OAAOC,SAASC,KAC9BP,EAASF,KAAKC,OAAOS,MAC3BR,EAAOS,aAAeL,GACtBM,EAAAA,EAAAA,IAAYZ,KAAKJ,eAAgBM,GAAQW,MAAKC,IACrCA,EAAKC,SAWNf,KAAKX,MAAQyB,EAAKE,WAClBhB,KAAKb,KAAO,UAXZ8B,EAAAA,EAAAA,kBAAuBH,EAAKnB,MAC5BK,KAAKkB,OAAOC,OAAO,aAAc,CAC7BC,SAAUN,EAAKnB,KAAKyB,SACpBC,SAAUP,EAAKnB,KAAK0B,SACpBC,MAAOR,EAAKnB,KAAK2B,MACjBC,OAAQT,EAAKnB,KAAK4B,SAEtBvB,KAAKb,KAAK,UACVa,KAAKwB,QAAQC,KAAK,CAACC,KAAM,aAK7B1B,KAAKF,SAAU,KAChB6B,OAAMC,IACLC,QAAQC,IAAI,iBAAiBF,GAC7B5B,KAAKb,KAAO,QACZa,KAAKX,MAAQ,WACbW,KAAKF,SAAU,MAIvBiC,cACI/B,KAAKwB,QAAQC,KAAK,CAACC,KAAM,S,WCpErC,MAAMM,GAA2B,OAAgB,EAAQ,CAAC,CAAC,SAASC,KAEpE","sources":["webpack://databasir/./src/views/OAuth2Login.vue","webpack://databasir/./src/views/OAuth2Login.vue?b6ea"],"sourcesContent":["<template>\r\n <el-container>\r\n <el-main v-loading=\"loading\" class=\"login-main\">\r\n <el-result\r\n :icon=\"icon\"\r\n :title=\"title\"\r\n :sub-title=\"subTitle\"\r\n v-show=\"!loading\"\r\n >\r\n <template #extra>\r\n <el-button type=\"primary\" @click=\"toIndexPage()\">立即跳转</el-button>\r\n </template>\r\n </el-result>\r\n </el-main>\r\n </el-container>\r\n</template>\r\n\r\n<style>\r\n.login-main {\r\n margin: 0 auto;\r\n margin-top: 200px;\r\n}\r\n\r\n</style>\r\n<script>\r\nimport { oauth2Login } from \"../api/Login\"\r\nimport { user } from \"../utils/auth\"\r\n\r\n\r\nexport default {\r\n data() {\r\n return {\r\n registrationId: null,\r\n icon: '',\r\n title: '',\r\n subTitle: '',\r\n loading: true,\r\n }\r\n },\r\n\r\n created() {\r\n this.registrationId = this.$route.params.id\r\n this.login()\r\n },\r\n\r\n methods: {\r\n login() {\r\n const redirectUri = window.location.href\r\n const params = this.$route.query\r\n params.redirect_uri = redirectUri\r\n oauth2Login(this.registrationId, params).then(resp => {\r\n if (!resp.errCode) {\r\n user.saveUserLoginData(resp.data)\r\n this.$store.commit('userUpdate', {\r\n nickname: resp.data.nickname,\r\n username: resp.data.username,\r\n email: resp.data.email,\r\n avatar: resp.data.avatar\r\n })\r\n this.icon='success'\r\n this.$router.push({path: '/groups'})\r\n } else {\r\n this.title = resp.errMessage\r\n this.icon = 'error'\r\n }\r\n this.loading = false\r\n }).catch(err => {\r\n console.log('login failed: '+err)\r\n this.icon = 'error'\r\n this.title = '登陆失败,请重试'\r\n this.loading = false\r\n })\r\n },\r\n\r\n toIndexPage() {\r\n this.$router.push({path: '/'})\r\n }\r\n }\r\n}\r\n</script>","import { render } from \"./OAuth2Login.vue?vue&type=template&id=65bc9922\"\nimport script from \"./OAuth2Login.vue?vue&type=script&lang=js\"\nexport * from \"./OAuth2Login.vue?vue&type=script&lang=js\"\n\nimport \"./OAuth2Login.vue?vue&type=style&index=0&id=65bc9922&lang=css\"\n\nimport exportComponent from \"D:\\\\workspace\\\\github\\\\databasir\\\\databasir-frontend\\\\node_modules\\\\vue-loader\\\\dist\\\\exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__"],"names":["_createBlock","_component_el_container","_component_el_main","class","_createVNode","_component_el_result","icon","$data","title","extra","_component_el_button","type","onClick","$options","data","registrationId","subTitle","loading","created","this","$route","params","id","login","methods","redirectUri","window","location","href","query","redirect_uri","oauth2Login","then","resp","errCode","errMessage","user","$store","commit","nickname","username","email","avatar","$router","push","path","catch","err","console","log","toIndexPage","__exports__","render"],"sourceRoot":""}
|
{"version":3,"file":"js/865.60ba33fe.js","mappings":"0MAUiE,Q,uKAT7DA,EAAAA,EAAAA,IAaeC,EAAA,M,kBAZX,IAWU,uBAXVD,EAAAA,EAAAA,IAWUE,EAAA,CAXmBC,MAAM,cAAY,C,kBAC3C,IASY,WATZC,EAAAA,EAAAA,IASYC,EAAA,CARPC,KAAMC,EAAAA,KACNC,MAAOD,EAAAA,MACP,YAAWA,EAAAA,UAHhB,CAMeE,OAAK,SAChB,IAAiE,EAAjEL,EAAAA,EAAAA,IAAiEM,EAAA,CAAtDC,KAAK,UAAWC,QAAK,eAAEC,EAAAA,gBAAlC,C,kBAAiD,IAAI,M,cAPzD,wCAIaN,EAAAA,c,OALjB,IAAoBA,EAAAA,c,gCA2B5B,GACIO,OACI,MAAO,CACHC,eAAgB,KAChBT,KAAM,GACNE,MAAO,GACPQ,SAAU,GACVC,SAAS,IAIjBC,UACIC,KAAKJ,eAAiBI,KAAKC,OAAOC,OAAOC,GACzCH,KAAKI,SAGTC,QAAS,CACJD,QACG,MAAME,EAAcC,OAAOC,SAASC,KAC9BP,EAASF,KAAKC,OAAOS,MAC3BR,EAAOS,aAAeL,GACtBM,EAAAA,EAAAA,IAAYZ,KAAKJ,eAAgBM,GAAQW,MAAKC,IACrCA,EAAKC,SAWNf,KAAKX,MAAQyB,EAAKE,WAClBhB,KAAKb,KAAO,UAXZ8B,EAAAA,EAAAA,kBAAuBH,EAAKnB,MAC5BK,KAAKkB,OAAOC,OAAO,aAAc,CAC7BC,SAAUN,EAAKnB,KAAKyB,SACpBC,SAAUP,EAAKnB,KAAK0B,SACpBC,MAAOR,EAAKnB,KAAK2B,MACjBC,OAAQT,EAAKnB,KAAK4B,SAEtBvB,KAAKb,KAAK,UACVa,KAAKwB,QAAQC,KAAK,CAACC,KAAM,aAK7B1B,KAAKF,SAAU,KAChB6B,OAAMC,IACLC,QAAQC,IAAI,iBAAiBF,GAC7B5B,KAAKb,KAAO,QACZa,KAAKX,MAAQ,WACbW,KAAKF,SAAU,MAIvBiC,cACI/B,KAAKwB,QAAQC,KAAK,CAACC,KAAM,S,WCpErC,MAAMM,GAA2B,OAAgB,EAAQ,CAAC,CAAC,SAASC,KAEpE","sources":["webpack://databasir/./src/views/OAuth2Login.vue","webpack://databasir/./src/views/OAuth2Login.vue?b6ea"],"sourcesContent":["<template>\r\n <el-container>\r\n <el-main v-loading=\"loading\" class=\"login-main\">\r\n <el-result\r\n :icon=\"icon\"\r\n :title=\"title\"\r\n :sub-title=\"subTitle\"\r\n v-show=\"!loading\"\r\n >\r\n <template #extra>\r\n <el-button type=\"primary\" @click=\"toIndexPage()\">立即跳转</el-button>\r\n </template>\r\n </el-result>\r\n </el-main>\r\n </el-container>\r\n</template>\r\n\r\n<style>\r\n.login-main {\r\n margin: 0 auto;\r\n margin-top: 200px;\r\n}\r\n\r\n</style>\r\n<script>\r\nimport { oauth2Login } from \"../api/Login\"\r\nimport { user } from \"../utils/auth\"\r\n\r\n\r\nexport default {\r\n data() {\r\n return {\r\n registrationId: null,\r\n icon: '',\r\n title: '',\r\n subTitle: '',\r\n loading: true,\r\n }\r\n },\r\n\r\n created() {\r\n this.registrationId = this.$route.params.id\r\n this.login()\r\n },\r\n\r\n methods: {\r\n login() {\r\n const redirectUri = window.location.href\r\n const params = this.$route.query\r\n params.redirect_uri = redirectUri\r\n oauth2Login(this.registrationId, params).then(resp => {\r\n if (!resp.errCode) {\r\n user.saveUserLoginData(resp.data)\r\n this.$store.commit('userUpdate', {\r\n nickname: resp.data.nickname,\r\n username: resp.data.username,\r\n email: resp.data.email,\r\n avatar: resp.data.avatar\r\n })\r\n this.icon='success'\r\n this.$router.push({path: '/groups'})\r\n } else {\r\n this.title = resp.errMessage\r\n this.icon = 'error'\r\n }\r\n this.loading = false\r\n }).catch(err => {\r\n console.log('login failed: '+err)\r\n this.icon = 'error'\r\n this.title = '登陆失败,请重试'\r\n this.loading = false\r\n })\r\n },\r\n\r\n toIndexPage() {\r\n this.$router.push({path: '/'})\r\n }\r\n }\r\n}\r\n</script>","import { render } from \"./OAuth2Login.vue?vue&type=template&id=65bc9922\"\nimport script from \"./OAuth2Login.vue?vue&type=script&lang=js\"\nexport * from \"./OAuth2Login.vue?vue&type=script&lang=js\"\n\nimport \"./OAuth2Login.vue?vue&type=style&index=0&id=65bc9922&lang=css\"\n\nimport exportComponent from \"D:\\\\workspace\\\\github\\\\databasir\\\\databasir-frontend\\\\node_modules\\\\vue-loader\\\\dist\\\\exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__"],"names":["_createBlock","_component_el_container","_component_el_main","class","_createVNode","_component_el_result","icon","$data","title","extra","_component_el_button","type","onClick","$options","data","registrationId","subTitle","loading","created","this","$route","params","id","login","methods","redirectUri","window","location","href","query","redirect_uri","oauth2Login","then","resp","errCode","errMessage","user","$store","commit","nickname","username","email","avatar","$router","push","path","catch","err","console","log","toIndexPage","__exports__","render"],"sourceRoot":""}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,26 +1,33 @@
|
||||||
package com.databasir.core.domain.app;
|
package com.databasir.core.domain.app;
|
||||||
|
|
||||||
import com.databasir.core.domain.DomainErrors;
|
import com.databasir.core.domain.DomainErrors;
|
||||||
import com.databasir.core.domain.app.converter.OauthAppConverter;
|
|
||||||
import com.databasir.core.domain.app.converter.OAuthAppResponseConverter;
|
import com.databasir.core.domain.app.converter.OAuthAppResponseConverter;
|
||||||
|
import com.databasir.core.domain.app.converter.OauthAppConverter;
|
||||||
import com.databasir.core.domain.app.data.*;
|
import com.databasir.core.domain.app.data.*;
|
||||||
import com.databasir.core.domain.app.handler.OAuthProcessResult;
|
import com.databasir.core.domain.app.handler.OAuthProcessResult;
|
||||||
import com.databasir.core.domain.app.handler.OpenAuthHandlers;
|
import com.databasir.core.domain.app.handler.OpenAuthHandlers;
|
||||||
|
import com.databasir.core.domain.app.validator.OauthPropertiesValidator;
|
||||||
import com.databasir.core.domain.user.data.UserCreateRequest;
|
import com.databasir.core.domain.user.data.UserCreateRequest;
|
||||||
import com.databasir.core.domain.user.data.UserDetailResponse;
|
import com.databasir.core.domain.user.data.UserDetailResponse;
|
||||||
import com.databasir.core.domain.user.service.UserService;
|
import com.databasir.core.domain.user.service.UserService;
|
||||||
import com.databasir.dao.impl.OauthAppDao;
|
import com.databasir.dao.impl.OauthAppDao;
|
||||||
|
import com.databasir.dao.impl.OauthAppPropertyDao;
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.io.InputStream;
|
||||||
import java.util.Optional;
|
import java.util.*;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@ -31,12 +38,20 @@ public class OpenAuthAppService {
|
||||||
|
|
||||||
private final OauthAppDao oauthAppDao;
|
private final OauthAppDao oauthAppDao;
|
||||||
|
|
||||||
|
private final OauthAppPropertyDao oauthAppPropertyDao;
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
private final OAuthAppResponseConverter oauthAppResponseConverter;
|
private final OAuthAppResponseConverter oauthAppResponseConverter;
|
||||||
|
|
||||||
private final OauthAppConverter oauthAppConverter;
|
private final OauthAppConverter oauthAppConverter;
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private final OauthPropertiesValidator oauthPropertiesValidator;
|
||||||
|
|
||||||
|
private List<OAuthAppPlatformResponse> platforms = new ArrayList<>();
|
||||||
|
|
||||||
public UserDetailResponse oauthCallback(String registrationId, Map<String, String[]> params) {
|
public UserDetailResponse oauthCallback(String registrationId, Map<String, String[]> params) {
|
||||||
// process by handler
|
// process by handler
|
||||||
OAuthProcessResult result = openAuthHandlers.process(registrationId, params);
|
OAuthProcessResult result = openAuthHandlers.process(registrationId, params);
|
||||||
|
@ -63,25 +78,37 @@ public class OpenAuthAppService {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void deleteById(Integer id) {
|
public void deleteById(Integer id) {
|
||||||
if (oauthAppDao.existsById(id)) {
|
if (oauthAppDao.existsById(id)) {
|
||||||
oauthAppDao.deleteById(id);
|
oauthAppDao.deleteById(id);
|
||||||
|
oauthAppPropertyDao.deleteByOauthAppId(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public void updateById(OAuthAppUpdateRequest request) {
|
public void updateById(OAuthAppUpdateRequest request) {
|
||||||
|
oauthPropertiesValidator.validate(request, listPlatforms());
|
||||||
OauthApp pojo = oauthAppConverter.of(request);
|
OauthApp pojo = oauthAppConverter.of(request);
|
||||||
try {
|
try {
|
||||||
oauthAppDao.updateById(pojo);
|
oauthAppDao.updateById(pojo);
|
||||||
|
oauthAppPropertyDao.deleteByOauthAppId(pojo.getId());
|
||||||
|
List<OauthAppProperty> properties = oauthAppConverter.toProperty(pojo.getId(), request.getProperties());
|
||||||
|
oauthAppPropertyDao.batchInsert(properties);
|
||||||
} catch (DuplicateKeyException e) {
|
} catch (DuplicateKeyException e) {
|
||||||
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
public Integer create(OAuthAppCreateRequest request) {
|
public Integer create(OAuthAppCreateRequest request) {
|
||||||
|
oauthPropertiesValidator.validate(request, listPlatforms());
|
||||||
OauthApp pojo = oauthAppConverter.of(request);
|
OauthApp pojo = oauthAppConverter.of(request);
|
||||||
try {
|
try {
|
||||||
return oauthAppDao.insertAndReturnId(pojo);
|
Integer oauthAppId = oauthAppDao.insertAndReturnId(pojo);
|
||||||
|
List<OauthAppProperty> properties = oauthAppConverter.toProperty(oauthAppId, request.getProperties());
|
||||||
|
oauthAppPropertyDao.batchInsert(properties);
|
||||||
|
return oauthAppId;
|
||||||
} catch (DuplicateKeyException e) {
|
} catch (DuplicateKeyException e) {
|
||||||
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
throw DomainErrors.REGISTRATION_ID_DUPLICATE.exception();
|
||||||
}
|
}
|
||||||
|
@ -92,6 +119,25 @@ public class OpenAuthAppService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<OAuthAppDetailResponse> getOne(Integer id) {
|
public Optional<OAuthAppDetailResponse> getOne(Integer id) {
|
||||||
return oauthAppDao.selectOptionalById(id).map(oauthAppConverter::toDetailResponse);
|
return oauthAppDao.selectOptionalById(id).map(oauthApp -> {
|
||||||
|
List<OauthAppProperty> properties = oauthAppPropertyDao.selectByOauthAppId(id);
|
||||||
|
return oauthAppConverter.toDetailResponse(oauthApp, properties);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OAuthAppPlatformResponse> listPlatforms() {
|
||||||
|
if (platforms == null || platforms.isEmpty()) {
|
||||||
|
String schemaPath = "classpath:/oauth/platform-properties-schema.json";
|
||||||
|
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||||
|
Resource resource = resourceLoader.getResource(schemaPath);
|
||||||
|
try (InputStream inputStream = resource.getInputStream()) {
|
||||||
|
return objectMapper.readValue(inputStream, new TypeReference<List<OAuthAppPlatformResponse>>() {
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return platforms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.databasir.core.domain.app.common;
|
||||||
|
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CommonProperties {
|
||||||
|
|
||||||
|
String AUTH_HOST = "auth_host";
|
||||||
|
|
||||||
|
String RESOURCE_HOST = "resource_host";
|
||||||
|
|
||||||
|
CommonProperties INSTANCE = new CommonProperties() {
|
||||||
|
};
|
||||||
|
|
||||||
|
default String get(List<OauthAppProperty> properties, String key) {
|
||||||
|
return properties.stream()
|
||||||
|
.filter(p -> p.getName().equals(key))
|
||||||
|
.map(OauthAppProperty::getValue)
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
default String getAuthHost(List<OauthAppProperty> properties) {
|
||||||
|
return get(properties, AUTH_HOST);
|
||||||
|
}
|
||||||
|
|
||||||
|
default String getResourceHost(List<OauthAppProperty> properties) {
|
||||||
|
return get(properties, RESOURCE_HOST);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.databasir.core.domain.app.common;
|
||||||
|
|
||||||
|
public interface GithubProperties extends CommonProperties {
|
||||||
|
|
||||||
|
String CLIENT_ID = "client_id";
|
||||||
|
|
||||||
|
String CLIENT_SECRET = "client_secret";
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.databasir.core.domain.app.common;
|
||||||
|
|
||||||
|
public interface GitlabProperties extends CommonProperties {
|
||||||
|
|
||||||
|
String CLIENT_ID = "client_id";
|
||||||
|
|
||||||
|
String CLIENT_SECRET = "client_secret";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.databasir.core.domain.app.common;
|
||||||
|
|
||||||
|
public interface WeWorkProperties extends CommonProperties {
|
||||||
|
|
||||||
|
String APP_ID = "appid";
|
||||||
|
|
||||||
|
String AGENT_ID = "agentid";
|
||||||
|
|
||||||
|
String SECRET = "secret";
|
||||||
|
|
||||||
|
String REDIRECT_URL = "redirect_uri";
|
||||||
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
package com.databasir.core.domain.app.converter;
|
package com.databasir.core.domain.app.converter;
|
||||||
|
|
||||||
import com.databasir.core.domain.app.data.OAuthAppCreateRequest;
|
import com.databasir.core.domain.app.data.*;
|
||||||
import com.databasir.core.domain.app.data.OAuthAppDetailResponse;
|
|
||||||
import com.databasir.core.domain.app.data.OAuthAppPageResponse;
|
|
||||||
import com.databasir.core.domain.app.data.OAuthAppUpdateRequest;
|
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface OauthAppConverter {
|
public interface OauthAppConverter {
|
||||||
|
|
||||||
|
@ -22,5 +24,17 @@ public interface OauthAppConverter {
|
||||||
|
|
||||||
OAuthAppPageResponse toPageResponse(OauthApp pojo);
|
OAuthAppPageResponse toPageResponse(OauthApp pojo);
|
||||||
|
|
||||||
OAuthAppDetailResponse toDetailResponse(OauthApp pojo);
|
OAuthAppDetailResponse toDetailResponse(OauthApp pojo, List<OauthAppProperty> properties);
|
||||||
|
|
||||||
|
@Mapping(target = "createAt", ignore = true)
|
||||||
|
@Mapping(target = "id", ignore = true)
|
||||||
|
OauthAppProperty toProperty(Integer oauthAppId, OauthAppPropertyData property);
|
||||||
|
|
||||||
|
default List<OauthAppProperty> toProperty(Integer oauthAppId, List<OauthAppPropertyData> properties) {
|
||||||
|
if (properties == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return properties.stream().map(prop -> toProperty(oauthAppId, prop)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class OAuthAppCreateRequest {
|
public class OAuthAppCreateRequest {
|
||||||
|
@ -20,17 +22,6 @@ public class OAuthAppCreateRequest {
|
||||||
|
|
||||||
private String appIcon;
|
private String appIcon;
|
||||||
|
|
||||||
@NotBlank
|
private List<OauthAppPropertyData> properties = new ArrayList<>();
|
||||||
private String authUrl;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String resourceUrl;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String clientSecret;
|
|
||||||
|
|
||||||
private String scope;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.databasir.dao.enums.OAuthAppType;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class OAuthAppDetailResponse {
|
public class OAuthAppDetailResponse {
|
||||||
|
@ -18,13 +20,7 @@ public class OAuthAppDetailResponse {
|
||||||
|
|
||||||
private String registrationId;
|
private String registrationId;
|
||||||
|
|
||||||
private String clientId;
|
private List<OauthAppPropertyData> properties = new ArrayList<>();
|
||||||
|
|
||||||
private String clientSecret;
|
|
||||||
|
|
||||||
private String authUrl;
|
|
||||||
|
|
||||||
private String resourceUrl;
|
|
||||||
|
|
||||||
private LocalDateTime updateAt;
|
private LocalDateTime updateAt;
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,6 @@ public class OAuthAppPageResponse {
|
||||||
|
|
||||||
private String registrationId;
|
private String registrationId;
|
||||||
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
private String authUrl;
|
|
||||||
|
|
||||||
private String resourceUrl;
|
|
||||||
|
|
||||||
private LocalDateTime updateAt;
|
private LocalDateTime updateAt;
|
||||||
|
|
||||||
private LocalDateTime createAt;
|
private LocalDateTime createAt;
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.databasir.core.domain.app.data;
|
||||||
|
|
||||||
|
import com.databasir.dao.enums.OAuthAppType;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class OAuthAppPlatformResponse {
|
||||||
|
|
||||||
|
private OAuthAppType authAppType;
|
||||||
|
|
||||||
|
private String authAppName;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private List<OAuthAppPlatformProperty> properties = new ArrayList<>();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class OAuthAppPlatformProperty {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private Boolean required;
|
||||||
|
|
||||||
|
private String defaultValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class OAuthAppUpdateRequest {
|
public class OAuthAppUpdateRequest {
|
||||||
|
@ -23,18 +25,6 @@ public class OAuthAppUpdateRequest {
|
||||||
|
|
||||||
private String appIcon;
|
private String appIcon;
|
||||||
|
|
||||||
@NotBlank
|
private List<OauthAppPropertyData> properties = new ArrayList<>();
|
||||||
private String authUrl;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String resourceUrl;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@NotBlank
|
|
||||||
private String clientSecret;
|
|
||||||
|
|
||||||
private String scope;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.databasir.core.domain.app.data;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class OauthAppPropertyData {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
package com.databasir.core.domain.app.handler;
|
package com.databasir.core.domain.app.handler;
|
||||||
|
|
||||||
import com.databasir.core.domain.DomainErrors;
|
import com.databasir.core.domain.DomainErrors;
|
||||||
|
import com.databasir.core.domain.app.common.CommonProperties;
|
||||||
|
import com.databasir.core.domain.app.common.GithubProperties;
|
||||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||||
import com.databasir.core.infrastructure.remote.github.GithubRemoteService;
|
import com.databasir.core.infrastructure.remote.github.GithubRemoteService;
|
||||||
import com.databasir.dao.enums.OAuthAppType;
|
import com.databasir.dao.enums.OAuthAppType;
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jooq.tools.StringUtils;
|
import org.jooq.tools.StringUtils;
|
||||||
|
@ -12,6 +15,7 @@ import org.springframework.security.authentication.CredentialsExpiredException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -26,13 +30,16 @@ public class GithubOpenAuthHandler implements OpenAuthHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String authorizationUrl(OauthApp app, Map<String, String[]> requestParams) {
|
public String authorizationUrl(OauthApp app,
|
||||||
String authUrl = app.getAuthUrl();
|
List<OauthAppProperty> properties,
|
||||||
String clientId = app.getClientId();
|
Map<String, String[]> requestParams) {
|
||||||
|
String authUrl = CommonProperties.INSTANCE.getAuthHost(properties);
|
||||||
|
String clientId = CommonProperties.INSTANCE.get(properties, GithubProperties.CLIENT_ID);
|
||||||
String authorizeUrl = authUrl + "/login/oauth/authorize";
|
String authorizeUrl = authUrl + "/login/oauth/authorize";
|
||||||
String url = UriComponentsBuilder.fromUriString(authorizeUrl)
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(authorizeUrl)
|
||||||
.queryParam("client_id", clientId)
|
.queryParam("client_id", clientId)
|
||||||
.queryParam("scope", "read:user user:email")
|
.queryParam("scope", "read:user user:email");
|
||||||
|
String url = builder
|
||||||
.encode()
|
.encode()
|
||||||
.build()
|
.build()
|
||||||
.toUriString();
|
.toUriString();
|
||||||
|
@ -40,10 +47,12 @@ public class GithubOpenAuthHandler implements OpenAuthHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuthProcessResult process(OauthApp app, Map<String, String[]> requestParams) {
|
public OAuthProcessResult process(OauthApp app,
|
||||||
String clientId = app.getClientId();
|
List<OauthAppProperty> properties,
|
||||||
String clientSecret = app.getClientSecret();
|
Map<String, String[]> requestParams) {
|
||||||
String authUrl = app.getAuthUrl();
|
String authUrl = CommonProperties.INSTANCE.getAuthHost(properties);
|
||||||
|
String clientId = CommonProperties.INSTANCE.get(properties, GithubProperties.CLIENT_ID);
|
||||||
|
String clientSecret = CommonProperties.INSTANCE.get(properties, GithubProperties.CLIENT_SECRET);
|
||||||
|
|
||||||
String code = requestParams.get("code")[0];
|
String code = requestParams.get("code")[0];
|
||||||
JsonNode tokenNode = githubRemoteService.getToken(authUrl, clientId, clientSecret, code)
|
JsonNode tokenNode = githubRemoteService.getToken(authUrl, clientId, clientSecret, code)
|
||||||
|
@ -55,7 +64,8 @@ public class GithubOpenAuthHandler implements OpenAuthHandler {
|
||||||
if (StringUtils.isBlank(accessToken)) {
|
if (StringUtils.isBlank(accessToken)) {
|
||||||
throw new CredentialsExpiredException("授权失效,请重新登陆");
|
throw new CredentialsExpiredException("授权失效,请重新登陆");
|
||||||
}
|
}
|
||||||
String resourceUrl = app.getResourceUrl();
|
|
||||||
|
String resourceUrl = CommonProperties.INSTANCE.get(properties, GithubProperties.RESOURCE_HOST);
|
||||||
String email = null;
|
String email = null;
|
||||||
for (JsonNode node : githubRemoteService.getEmail(resourceUrl, accessToken)) {
|
for (JsonNode node : githubRemoteService.getEmail(resourceUrl, accessToken)) {
|
||||||
if (node.get("primary").asBoolean()) {
|
if (node.get("primary").asBoolean()) {
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
package com.databasir.core.domain.app.handler;
|
package com.databasir.core.domain.app.handler;
|
||||||
|
|
||||||
import com.databasir.core.domain.DomainErrors;
|
import com.databasir.core.domain.DomainErrors;
|
||||||
|
import com.databasir.core.domain.app.common.CommonProperties;
|
||||||
|
import com.databasir.core.domain.app.common.GitlabProperties;
|
||||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||||
import com.databasir.core.infrastructure.remote.gitlab.GitlabRemoteService;
|
import com.databasir.core.infrastructure.remote.gitlab.GitlabRemoteService;
|
||||||
import com.databasir.dao.enums.OAuthAppType;
|
import com.databasir.dao.enums.OAuthAppType;
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -24,42 +28,52 @@ public class GitlabOpenAuthHandler implements OpenAuthHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String authorizationUrl(OauthApp app, Map<String, String[]> params) {
|
public String authorizationUrl(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> params) {
|
||||||
if (!params.containsKey("redirect_uri")) {
|
if (!params.containsKey("redirect_uri")) {
|
||||||
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception("缺少参数 redirect_uri", null);
|
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception("缺少参数 redirect_uri", null);
|
||||||
}
|
}
|
||||||
String authUrl = app.getAuthUrl();
|
|
||||||
String clientId = app.getClientId();
|
String authUrl = CommonProperties.INSTANCE.getAuthHost(properties);
|
||||||
|
String clientId = CommonProperties.INSTANCE.get(properties, GitlabProperties.CLIENT_ID);
|
||||||
String authorizeUrl = authUrl + "/oauth/authorize";
|
String authorizeUrl = authUrl + "/oauth/authorize";
|
||||||
String redirectUri = params.get("redirect_uri")[0];
|
String redirectUri = params.get("redirect_uri")[0];
|
||||||
String url = UriComponentsBuilder.fromUriString(authorizeUrl)
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(authorizeUrl)
|
||||||
.queryParam("client_id", clientId)
|
.queryParam("client_id", clientId)
|
||||||
.queryParam("redirect_uri", redirectUri)
|
.queryParam("redirect_uri", redirectUri)
|
||||||
.queryParam("response_type", "code")
|
|
||||||
.queryParam("state", redirectUri)
|
.queryParam("state", redirectUri)
|
||||||
.queryParam("scope", "read_user")
|
.queryParam("response_type", "code")
|
||||||
|
.queryParam("scope", "read_user");
|
||||||
|
return builder
|
||||||
.encode()
|
.encode()
|
||||||
.build()
|
.build()
|
||||||
.toUriString();
|
.toUriString();
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuthProcessResult process(OauthApp app, Map<String, String[]> requestParams) {
|
public OAuthProcessResult process(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> requestParams) {
|
||||||
if (!requestParams.containsKey("redirect_uri")) {
|
if (!requestParams.containsKey("redirect_uri")) {
|
||||||
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception("缺少参数 redirect_uri", null);
|
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception("缺少参数 redirect_uri", null);
|
||||||
}
|
}
|
||||||
String url = app.getAuthUrl();
|
|
||||||
|
String url = CommonProperties.INSTANCE.getAuthHost(properties);
|
||||||
String code = requestParams.get("code")[0];
|
String code = requestParams.get("code")[0];
|
||||||
String state = requestParams.get("state")[0];
|
String state = requestParams.get("state")[0];
|
||||||
String redirectUri = requestParams.get("redirect_uri")[0];
|
String redirectUri = requestParams.get("redirect_uri")[0];
|
||||||
|
String clientId = CommonProperties.INSTANCE.get(properties, GitlabProperties.CLIENT_ID);
|
||||||
|
String secret = CommonProperties.INSTANCE.get(properties, GitlabProperties.CLIENT_SECRET);
|
||||||
JsonNode accessTokenData =
|
JsonNode accessTokenData =
|
||||||
gitlabRemoteService.getAccessToken(url, code, app.getClientId(), app.getClientSecret(), redirectUri);
|
gitlabRemoteService.getAccessToken(url, code, clientId, secret, redirectUri);
|
||||||
if (accessTokenData == null) {
|
if (accessTokenData == null) {
|
||||||
throw new DatabasirAuthenticationException(DomainErrors.NETWORK_ERROR.exception());
|
throw new DatabasirAuthenticationException(DomainErrors.NETWORK_ERROR.exception());
|
||||||
}
|
}
|
||||||
String accessToken = accessTokenData.get("access_token").asText();
|
String accessToken = accessTokenData.get("access_token").asText();
|
||||||
JsonNode userData = gitlabRemoteService.getUser(app.getResourceUrl(), accessToken);
|
|
||||||
|
String resourceUrl = CommonProperties.INSTANCE.getResourceHost(properties);
|
||||||
|
JsonNode userData = gitlabRemoteService.getUser(resourceUrl, accessToken);
|
||||||
if (userData == null) {
|
if (userData == null) {
|
||||||
throw new DatabasirAuthenticationException(DomainErrors.NETWORK_ERROR.exception());
|
throw new DatabasirAuthenticationException(DomainErrors.NETWORK_ERROR.exception());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,20 @@ package com.databasir.core.domain.app.handler;
|
||||||
|
|
||||||
import com.databasir.dao.enums.OAuthAppType;
|
import com.databasir.dao.enums.OAuthAppType;
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface OpenAuthHandler {
|
public interface OpenAuthHandler {
|
||||||
|
|
||||||
boolean support(OAuthAppType oauthAppType);
|
boolean support(OAuthAppType oauthAppType);
|
||||||
|
|
||||||
String authorizationUrl(OauthApp app, Map<String, String[]> requestParams);
|
String authorizationUrl(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> requestParams);
|
||||||
|
|
||||||
OAuthProcessResult process(OauthApp app, Map<String, String[]> requestParams);
|
OAuthProcessResult process(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> requestParams);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.databasir.core.domain.app.handler;
|
||||||
|
|
||||||
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
import com.databasir.core.domain.app.exception.DatabasirAuthenticationException;
|
||||||
import com.databasir.dao.impl.OauthAppDao;
|
import com.databasir.dao.impl.OauthAppDao;
|
||||||
|
import com.databasir.dao.impl.OauthAppPropertyDao;
|
||||||
import com.databasir.dao.tables.pojos.OauthApp;
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -19,12 +21,15 @@ public class OpenAuthHandlers {
|
||||||
|
|
||||||
private final OauthAppDao oauthAppDao;
|
private final OauthAppDao oauthAppDao;
|
||||||
|
|
||||||
|
private final OauthAppPropertyDao oauthAppPropertyDao;
|
||||||
|
|
||||||
public String authorizeUrl(String registrationId, Map<String, String[]> parameters) {
|
public String authorizeUrl(String registrationId, Map<String, String[]> parameters) {
|
||||||
OauthApp app = oauthAppDao.selectByRegistrationId(registrationId);
|
OauthApp app = oauthAppDao.selectByRegistrationId(registrationId);
|
||||||
|
List<OauthAppProperty> properties = oauthAppPropertyDao.selectByOauthAppId(app.getId());
|
||||||
return handlers.stream()
|
return handlers.stream()
|
||||||
.filter(handler -> handler.support(app.getAppType()))
|
.filter(handler -> handler.support(app.getAppType()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(handler -> handler.authorizationUrl(app, parameters))
|
.map(handler -> handler.authorizationUrl(app, properties, parameters))
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,10 +39,11 @@ public class OpenAuthHandlers {
|
||||||
var bizErr = REGISTRATION_ID_NOT_FOUND.exception("应用 ID [" + registrationId + "] 不存在");
|
var bizErr = REGISTRATION_ID_NOT_FOUND.exception("应用 ID [" + registrationId + "] 不存在");
|
||||||
return new DatabasirAuthenticationException(bizErr);
|
return new DatabasirAuthenticationException(bizErr);
|
||||||
});
|
});
|
||||||
|
List<OauthAppProperty> properties = oauthAppPropertyDao.selectByOauthAppId(app.getId());
|
||||||
return handlers.stream()
|
return handlers.stream()
|
||||||
.filter(handler -> handler.support(app.getAppType()))
|
.filter(handler -> handler.support(app.getAppType()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(handler -> handler.process(app, parameters))
|
.map(handler -> handler.process(app, properties, parameters))
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.databasir.core.domain.app.handler;
|
||||||
|
|
||||||
|
import com.databasir.core.domain.DomainErrors;
|
||||||
|
import com.databasir.core.domain.app.common.WeWorkProperties;
|
||||||
|
import com.databasir.core.infrastructure.remote.wework.WeWorkRemoteService;
|
||||||
|
import com.databasir.dao.enums.OAuthAppType;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthApp;
|
||||||
|
import com.databasir.dao.tables.pojos.OauthAppProperty;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.databasir.core.domain.app.common.CommonProperties.INSTANCE;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WeWorkOpenAuthHandler implements OpenAuthHandler {
|
||||||
|
|
||||||
|
private final WeWorkRemoteService weWorkRemoteService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean support(OAuthAppType oauthAppType) {
|
||||||
|
return oauthAppType == OAuthAppType.WE_WORK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String authorizationUrl(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> requestParams) {
|
||||||
|
String authUrl = INSTANCE.getAuthHost(properties);
|
||||||
|
String authorizeUrl = authUrl + "/wwopen/sso/qrConnect";
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(authorizeUrl)
|
||||||
|
.queryParam("appid", INSTANCE.get(properties, WeWorkProperties.APP_ID))
|
||||||
|
.queryParam("agentid", INSTANCE.get(properties, WeWorkProperties.AGENT_ID))
|
||||||
|
.queryParam("redirect_uri", INSTANCE.get(properties, WeWorkProperties.REDIRECT_URL));
|
||||||
|
String url = builder
|
||||||
|
.encode()
|
||||||
|
.build()
|
||||||
|
.toUriString();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OAuthProcessResult process(OauthApp app,
|
||||||
|
List<OauthAppProperty> properties,
|
||||||
|
Map<String, String[]> requestParams) {
|
||||||
|
if (!requestParams.containsKey("redirect_uri")) {
|
||||||
|
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception("缺少参数 redirect_uri", null);
|
||||||
|
}
|
||||||
|
String code = requestParams.get("code")[0];
|
||||||
|
|
||||||
|
String resourceUrl = INSTANCE.getResourceHost(properties);
|
||||||
|
String clientId = INSTANCE.get(properties, WeWorkProperties.APP_ID);
|
||||||
|
String secret = INSTANCE.get(properties, WeWorkProperties.SECRET);
|
||||||
|
String tokenUrl = resourceUrl + "/cgi-bin/gettoken";
|
||||||
|
String token = weWorkRemoteService.getToken(tokenUrl, clientId, secret);
|
||||||
|
|
||||||
|
String userIdUrl = resourceUrl + "/cgi-bin/auth/getuserinfo";
|
||||||
|
String userId = weWorkRemoteService.getUserId(userIdUrl, token, code);
|
||||||
|
|
||||||
|
String userInfoUrl = resourceUrl + "/cgi-bin/user/get";
|
||||||
|
JsonNode userInfo = weWorkRemoteService.getUserInfo(userInfoUrl, token, userId);
|
||||||
|
|
||||||
|
OAuthProcessResult result = new OAuthProcessResult();
|
||||||
|
result.setAvatar(userInfo.get("avatar").asText());
|
||||||
|
result.setEmail(userInfo.get("biz_mail").asText());
|
||||||
|
result.setNickname(userInfo.get("name").asText());
|
||||||
|
result.setUsername(userInfo.get("biz_mail").asText());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.databasir.core.domain.app.validator;
|
||||||
|
|
||||||
|
import com.databasir.core.domain.DomainErrors;
|
||||||
|
import com.databasir.core.domain.app.data.OAuthAppCreateRequest;
|
||||||
|
import com.databasir.core.domain.app.data.OAuthAppPlatformResponse;
|
||||||
|
import com.databasir.core.domain.app.data.OAuthAppPlatformResponse.OAuthAppPlatformProperty;
|
||||||
|
import com.databasir.core.domain.app.data.OAuthAppUpdateRequest;
|
||||||
|
import com.databasir.core.domain.app.data.OauthAppPropertyData;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OauthPropertiesValidator {
|
||||||
|
|
||||||
|
public void validate(OAuthAppCreateRequest request, List<OAuthAppPlatformResponse> platforms) {
|
||||||
|
Map<String, OauthAppPropertyData> propertyMapByName = request.getProperties()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(i -> i.getName(), i -> i));
|
||||||
|
platforms.stream()
|
||||||
|
.filter(platform -> platform.getAuthAppType() == request.getAppType())
|
||||||
|
.forEach(platform -> {
|
||||||
|
List<OAuthAppPlatformProperty> properties = platform.getProperties();
|
||||||
|
properties.forEach(property -> {
|
||||||
|
if (Objects.equals(true, property.getRequired())) {
|
||||||
|
if (!propertyMapByName.containsKey(property.getName())) {
|
||||||
|
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception(
|
||||||
|
"参数 " + property.getName() + " 不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void validate(OAuthAppUpdateRequest request, List<OAuthAppPlatformResponse> platforms) {
|
||||||
|
Map<String, OauthAppPropertyData> propertyMapByName = request.getProperties()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(i -> i.getName(), i -> i));
|
||||||
|
platforms.stream()
|
||||||
|
.filter(platform -> platform.getAuthAppType() == request.getAppType())
|
||||||
|
.forEach(platform -> {
|
||||||
|
List<OAuthAppPlatformProperty> properties = platform.getProperties();
|
||||||
|
properties.forEach(property -> {
|
||||||
|
if (Objects.equals(true, property.getRequired())) {
|
||||||
|
if (!propertyMapByName.containsKey(property.getName())) {
|
||||||
|
throw DomainErrors.MISS_REQUIRED_PARAMETERS.exception(
|
||||||
|
"参数 " + property.getName() + " 不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,13 +50,17 @@ public class OperationLogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLoginFailedLog(String username, String msg) {
|
public void saveLoginFailedLog(String username, String msg) {
|
||||||
|
saveLoginFailedLog(username, "登录", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveLoginFailedLog(String username, String name, String msg) {
|
||||||
try {
|
try {
|
||||||
JsonData result = JsonData.error("-1", Objects.requireNonNullElse(msg, "登录失败"));
|
JsonData result = JsonData.error("-1", Objects.requireNonNullElse(msg, "登录失败"));
|
||||||
OperationLogRequest log = OperationLogRequest.builder()
|
OperationLogRequest log = OperationLogRequest.builder()
|
||||||
.isSuccess(false)
|
.isSuccess(false)
|
||||||
.operationCode("login")
|
.operationCode("login")
|
||||||
.operationModule(AuditLog.Modules.LOGIN)
|
.operationModule(AuditLog.Modules.LOGIN)
|
||||||
.operationName("登录")
|
.operationName(name)
|
||||||
.operatorNickname(username)
|
.operatorNickname(username)
|
||||||
.operatorUsername(username)
|
.operatorUsername(username)
|
||||||
.operatorUserId(-1)
|
.operatorUserId(-1)
|
||||||
|
@ -70,6 +74,10 @@ public class OperationLogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLoginLog(User user, Boolean success, String msg) {
|
public void saveLoginLog(User user, Boolean success, String msg) {
|
||||||
|
this.saveLoginLog(user, success, "登录", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveLoginLog(User user, Boolean success, String name, String msg) {
|
||||||
try {
|
try {
|
||||||
JsonData result;
|
JsonData result;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -82,7 +90,7 @@ public class OperationLogService {
|
||||||
.involvedUserId(user.getId())
|
.involvedUserId(user.getId())
|
||||||
.operationCode("login")
|
.operationCode("login")
|
||||||
.operationModule(AuditLog.Modules.LOGIN)
|
.operationModule(AuditLog.Modules.LOGIN)
|
||||||
.operationName("登录")
|
.operationName(name)
|
||||||
.operatorNickname(user.getNickname())
|
.operatorNickname(user.getNickname())
|
||||||
.operatorUsername(user.getUsername())
|
.operatorUsername(user.getUsername())
|
||||||
.operatorUserId(user.getId())
|
.operatorUserId(user.getId())
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.databasir.core.infrastructure.remote;
|
||||||
import com.databasir.core.infrastructure.remote.github.GithubApiClient;
|
import com.databasir.core.infrastructure.remote.github.GithubApiClient;
|
||||||
import com.databasir.core.infrastructure.remote.github.GithubOauthClient;
|
import com.databasir.core.infrastructure.remote.github.GithubOauthClient;
|
||||||
import com.databasir.core.infrastructure.remote.gitlab.GitlabApiClient;
|
import com.databasir.core.infrastructure.remote.gitlab.GitlabApiClient;
|
||||||
|
import com.databasir.core.infrastructure.remote.wework.WeWorkApiClient;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -41,4 +42,13 @@ public class ClientConfig {
|
||||||
.build();
|
.build();
|
||||||
return retrofit.create(GitlabApiClient.class);
|
return retrofit.create(GitlabApiClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public WeWorkApiClient weWorkApiClient() {
|
||||||
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
|
.baseUrl("https://qyapi.weixin.qq.com")
|
||||||
|
.addConverterFactory(JacksonConverterFactory.create())
|
||||||
|
.build();
|
||||||
|
return retrofit.create(WeWorkApiClient.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.databasir.core.infrastructure.remote.wework;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.http.GET;
|
||||||
|
import retrofit2.http.Headers;
|
||||||
|
import retrofit2.http.QueryMap;
|
||||||
|
import retrofit2.http.Url;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface WeWorkApiClient {
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Headers(value = {
|
||||||
|
"Accept: application/json"
|
||||||
|
})
|
||||||
|
Call<JsonNode> getUserInfo(@Url String url, @QueryMap Map<String, String> request);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Headers(value = {
|
||||||
|
"Accept: application/json"
|
||||||
|
})
|
||||||
|
Call<JsonNode> getAccessToken(@Url String url, @QueryMap Map<String, String> request);
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.databasir.core.infrastructure.remote.wework;
|
||||||
|
|
||||||
|
import com.databasir.common.SystemException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WeWorkRemoteService {
|
||||||
|
|
||||||
|
private final WeWorkApiClient weWorkApiClient;
|
||||||
|
|
||||||
|
public String getToken(String url,
|
||||||
|
String corpId,
|
||||||
|
String secret) {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("corpid", corpId);
|
||||||
|
map.put("corpsecret", secret);
|
||||||
|
JsonNode data = execute(weWorkApiClient.getAccessToken(url, map));
|
||||||
|
return data.get("access_token").asText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserId(String url,
|
||||||
|
String accessToken,
|
||||||
|
String code) {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("access_token", accessToken);
|
||||||
|
map.put("code", code);
|
||||||
|
return execute(weWorkApiClient.getUserInfo(url, map)).get("userid").asText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonNode getUserInfo(String url,
|
||||||
|
String accessToken,
|
||||||
|
String userId) {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put("access_token", accessToken);
|
||||||
|
map.put("userid", userId);
|
||||||
|
return execute(weWorkApiClient.getUserInfo(url, map));
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> T execute(Call<T> call) {
|
||||||
|
try {
|
||||||
|
Response<T> response = call.execute();
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
log.error("request error: " + call.request() + ", response = " + response);
|
||||||
|
throw new SystemException("Call Remote Error");
|
||||||
|
} else {
|
||||||
|
log.info("response " + response);
|
||||||
|
T body = response.body();
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SystemException("System Error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"authAppType": "GITLAB",
|
||||||
|
"authAppName": "Gitlab",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "auth_host",
|
||||||
|
"label": "认证服务地址",
|
||||||
|
"description": "用于登录认证",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "resource_host",
|
||||||
|
"label": "资源服务地址",
|
||||||
|
"description": "用于用户信息等资源查询",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "client_id",
|
||||||
|
"label": "Client ID",
|
||||||
|
"description": "",
|
||||||
|
"required": true,
|
||||||
|
"stage": "AUTHORIZATION"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "client_secret",
|
||||||
|
"label": "Client Secret",
|
||||||
|
"description": "",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"authAppType": "GITHUB",
|
||||||
|
"authAppName": "Github",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "auth_host",
|
||||||
|
"label": "认证服务地址",
|
||||||
|
"description": "用于登录认证",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "resource_host",
|
||||||
|
"label": "资源服务地址",
|
||||||
|
"description": "用于用户信息等资源查询",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "client_id",
|
||||||
|
"label": "Client ID",
|
||||||
|
"description": "",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "client_secret",
|
||||||
|
"label": "Client Secret",
|
||||||
|
"description": "",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"authAppType": "WE_WORK",
|
||||||
|
"authAppName": "企业微信",
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "auth_host",
|
||||||
|
"label": "认证服务地址",
|
||||||
|
"description": "用于登录认证",
|
||||||
|
"required": true,
|
||||||
|
"defaultValue": "https://open.work.weixin.qq.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "resource_host",
|
||||||
|
"label": "资源服务地址",
|
||||||
|
"description": "用于用户信息等资源查询",
|
||||||
|
"required": true,
|
||||||
|
"defaultValue": "https://qyapi.weixin.qq.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "redirect_uri",
|
||||||
|
"label": "登录成功回跳地址",
|
||||||
|
"description": "",
|
||||||
|
"defaultValue": "javaScript:window.location.protocol + '//' +window.location.host+'/login/oauth2/'+formData.registrationId",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "appid",
|
||||||
|
"label": "企业 ID",
|
||||||
|
"description": "",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "agentid",
|
||||||
|
"label": "应用 agentID",
|
||||||
|
"description": "",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "secret",
|
||||||
|
"label": "应用 secret",
|
||||||
|
"description": "应用密钥",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2126ecf0691bd77a4c33f628bd8828f89ec46206
|
Subproject commit 41661faad8eceb7d76df84d204d86977dcac5c95
|
Loading…
Reference in New Issue