mirror of
https://github.com/dataease/dataease.git
synced 2026-05-23 22:08:34 +08:00
feat(系统管理-系统参数): 飞书配置
This commit is contained in:
@@ -72,8 +72,8 @@ public interface AuthApi {
|
||||
boolean isOpenDingtalk();
|
||||
|
||||
@ApiOperation("是否开启飞书")
|
||||
@PostMapping("/isOpenFark")
|
||||
boolean isOpenFark();
|
||||
@PostMapping("/isOpenLark")
|
||||
boolean isOpenLark();
|
||||
|
||||
@ApiIgnore
|
||||
@PostMapping("/isPluginLoaded")
|
||||
|
||||
@@ -305,12 +305,12 @@ public class AuthServer implements AuthApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpenFark() {
|
||||
public boolean isOpenLark() {
|
||||
Boolean licValid = PluginUtils.licValid();
|
||||
if (!licValid)
|
||||
return false;
|
||||
|
||||
return authUserService.supportFark();
|
||||
return authUserService.supportLark();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,7 @@ public interface AuthUserService {
|
||||
|
||||
Boolean supportDingtalk();
|
||||
|
||||
Boolean supportFark();
|
||||
Boolean supportLark();
|
||||
|
||||
Boolean pluginLoaded();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.dataease.plugins.config.SpringContextUtil;
|
||||
import io.dataease.plugins.util.PluginUtils;
|
||||
import io.dataease.plugins.xpack.cas.service.CasXpackService;
|
||||
import io.dataease.plugins.xpack.dingtalk.service.DingtalkXpackService;
|
||||
import io.dataease.plugins.xpack.lark.service.LarkXpackService;
|
||||
import io.dataease.plugins.xpack.ldap.service.LdapXpackService;
|
||||
import io.dataease.plugins.xpack.oidc.service.OidcXpackService;
|
||||
|
||||
@@ -187,8 +188,12 @@ public class AuthUserServiceImpl implements AuthUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean supportFark() {
|
||||
return false;
|
||||
public Boolean supportLark() {
|
||||
Map<String, LarkXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarkXpackService.class));
|
||||
if (beansOfType.keySet().size() == 0) return false;
|
||||
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
if (ObjectUtils.isEmpty(larkXpackService)) return false;
|
||||
return larkXpackService.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
filterChainDefinitionMap.put("/api/auth/isOpenOidc", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/isOpenWecom", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/isOpenDingtalk", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/isOpenFark", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/isOpenLark", ANON);
|
||||
filterChainDefinitionMap.put("/api/auth/getPublicKey", ANON);
|
||||
filterChainDefinitionMap.put("/api/pluginCommon/component/*", ANON);
|
||||
filterChainDefinitionMap.put("/api/pluginCommon/staticInfo/**", ANON);
|
||||
@@ -94,8 +94,8 @@ public class ShiroServiceImpl implements ShiroService {
|
||||
filterChainDefinitionMap.put("/plugin/wecom/getQrParam", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/dingtalk/callBack*", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/dingtalk/getQrParam", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/fark/callBack*", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/fark/getQrParam", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/lark/callBack*", ANON);
|
||||
filterChainDefinitionMap.put("/plugin/lark/getQrParam", ANON);
|
||||
filterChainDefinitionMap.put("/cas/reset/**", ANON);
|
||||
|
||||
filterChainDefinitionMap.put("/unauth", ANON);
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package io.dataease.plugins.server;
|
||||
|
||||
import io.dataease.auth.entity.SysUserEntity;
|
||||
import io.dataease.auth.entity.TokenInfo;
|
||||
import io.dataease.auth.service.AuthUserService;
|
||||
import io.dataease.auth.util.JWTUtils;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.DeLogUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.commons.utils.ServletUtils;
|
||||
import io.dataease.plugins.config.SpringContextUtil;
|
||||
|
||||
import io.dataease.plugins.xpack.display.dto.response.SysSettingDto;
|
||||
import io.dataease.plugins.xpack.lark.dto.entity.LarkQrResult;
|
||||
import io.dataease.plugins.xpack.lark.dto.entity.LarkUserInfo;
|
||||
import io.dataease.plugins.xpack.lark.dto.response.LarkInfo;
|
||||
import io.dataease.plugins.xpack.lark.service.LarkXpackService;
|
||||
import io.dataease.service.sys.SysUserService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApiIgnore
|
||||
@RequestMapping("/plugin/lark")
|
||||
@Controller
|
||||
public class XLarkServer {
|
||||
|
||||
|
||||
@Resource
|
||||
private AuthUserService authUserService;
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/info")
|
||||
public LarkInfo getLarkInfo() {
|
||||
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
return larkXpackService.info();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequiresPermissions("sysparam:read")
|
||||
@PostMapping("/save")
|
||||
public void save(@RequestBody List<SysSettingDto> settings) {
|
||||
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
larkXpackService.save(settings);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/testConn")
|
||||
public void testConn(@RequestBody LarkInfo larkInfo) {
|
||||
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
try {
|
||||
larkXpackService.testConn(larkInfo);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/getQrParam")
|
||||
public LarkQrResult getQrParam() {
|
||||
LarkXpackService larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
return larkXpackService.getQrParam();
|
||||
}
|
||||
|
||||
@GetMapping("/callBack")
|
||||
public ModelAndView callBack(@RequestParam("code") String code, @RequestParam("state") String state) {
|
||||
ModelAndView modelAndView = new ModelAndView("redirect:/");
|
||||
HttpServletResponse response = ServletUtils.response();
|
||||
LarkXpackService larkXpackService = null;
|
||||
try {
|
||||
Map<String, LarkXpackService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType((LarkXpackService.class));
|
||||
if (beansOfType.keySet().size() == 0) {
|
||||
DEException.throwException("缺少飞书插件");
|
||||
}
|
||||
larkXpackService = SpringContextUtil.getBean(LarkXpackService.class);
|
||||
Boolean isOpen = larkXpackService.isOpen();
|
||||
if (!isOpen) {
|
||||
DEException.throwException("未开启飞书");
|
||||
}
|
||||
LarkUserInfo larkUserInfo = larkXpackService.userInfo(code, state);
|
||||
String username = larkUserInfo.getUser_id();
|
||||
String sub = larkUserInfo.getSub();
|
||||
SysUserEntity sysUserEntity = authUserService.getUserBySub(sub, 6);
|
||||
if (null == sysUserEntity) {
|
||||
String email = StringUtils.isNotBlank(larkUserInfo.getEmail()) ? larkUserInfo.getEmail() : "demo@lark.work";
|
||||
sysUserService.validateExistUser(username, larkUserInfo.getName(), email);
|
||||
sysUserService.saveLarkCUser(larkUserInfo, email);
|
||||
sysUserEntity = authUserService.getUserBySub(sub, 6);
|
||||
}
|
||||
TokenInfo tokenInfo = TokenInfo.builder().userId(sysUserEntity.getUserId()).username(sysUserEntity.getUsername()).build();
|
||||
String realPwd = sysUserEntity.getPassword();
|
||||
String token = JWTUtils.sign(tokenInfo, realPwd);
|
||||
ServletUtils.setToken(token);
|
||||
|
||||
DeLogUtils.save(SysLogConstants.OPERATE_TYPE.LOGIN, SysLogConstants.SOURCE_TYPE.USER, sysUserEntity.getUserId(), null, null, null);
|
||||
|
||||
Cookie cookie_token = new Cookie("Authorization", token);
|
||||
cookie_token.setPath("/");
|
||||
|
||||
response.addCookie(cookie_token);
|
||||
} catch (Exception e) {
|
||||
|
||||
String msg = e.getMessage();
|
||||
if (null != e.getCause()) {
|
||||
msg = e.getCause().getMessage();
|
||||
}
|
||||
try {
|
||||
msg = URLEncoder.encode(msg, "UTF-8");
|
||||
LogUtil.error(e);
|
||||
Cookie cookie_error = new Cookie("LarkError", msg);
|
||||
cookie_error.setPath("/");
|
||||
|
||||
return modelAndView;
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return modelAndView;
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import io.dataease.plugins.common.base.mapper.SysUserMapper;
|
||||
import io.dataease.plugins.common.base.mapper.SysUsersRolesMapper;
|
||||
import io.dataease.plugins.common.entity.XpackLdapUserEntity;
|
||||
import io.dataease.plugins.xpack.dingtalk.dto.response.DingUserEntity;
|
||||
import io.dataease.plugins.xpack.lark.dto.entity.LarkUserInfo;
|
||||
import io.dataease.plugins.xpack.oidc.dto.SSOUserInfo;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@@ -172,6 +173,28 @@ public class SysUserService {
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void saveLarkCUser(LarkUserInfo larkUserInfo, String email) {
|
||||
long now = System.currentTimeMillis();
|
||||
SysUser sysUser = new SysUser();
|
||||
|
||||
sysUser.setUsername(larkUserInfo.getUser_id());
|
||||
sysUser.setNickName(larkUserInfo.getName());
|
||||
sysUser.setEmail(email);
|
||||
sysUser.setPassword(CodingUtil.md5(DEFAULT_PWD));
|
||||
sysUser.setCreateTime(now);
|
||||
sysUser.setUpdateTime(now);
|
||||
|
||||
sysUser.setEnabled(1L);
|
||||
sysUser.setLanguage("zh_CN");
|
||||
sysUser.setFrom(6);
|
||||
sysUser.setIsAdmin(false);
|
||||
sysUser.setSub(larkUserInfo.getSub());
|
||||
sysUser.setPhone(larkUserInfo.getMobile());
|
||||
sysUserMapper.insert(sysUser);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void saveCASUser(String name, String email) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user