diff --git a/pom.xml b/pom.xml
index bc10409..1c987f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -191,6 +191,11 @@
org.springframework.boot
spring-boot-starter-aop
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
diff --git a/src/main/java/io/qyi/e5/config/Start.java b/src/main/java/io/qyi/e5/config/Start.java
index 76a1956..5390ae2 100644
--- a/src/main/java/io/qyi/e5/config/Start.java
+++ b/src/main/java/io/qyi/e5/config/Start.java
@@ -87,6 +87,7 @@ public class Start {
runOutlookList.forEach(outlook -> {
threadPool.execute(new task(outlook,cdl));
});
+
/*等待线程池内的线程执行完毕*/
try {
cdl.await();
diff --git a/src/main/java/io/qyi/e5/config/security/UrlAccessDecisionManager.java b/src/main/java/io/qyi/e5/config/security/UrlAccessDecisionManager.java
index dd6d659..f40ca51 100644
--- a/src/main/java/io/qyi/e5/config/security/UrlAccessDecisionManager.java
+++ b/src/main/java/io/qyi/e5/config/security/UrlAccessDecisionManager.java
@@ -29,7 +29,7 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
if (collection == null) {
return;
}
- log.info("object is a URL. {}", o.toString());
+ log.debug("object is a URL. {}", o.toString());
//所请求的资源拥有的权限(一个资源对多个权限)
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
diff --git a/src/main/java/io/qyi/e5/config/security/UsernamePasswordAuthenticationProvider.java b/src/main/java/io/qyi/e5/config/security/UsernamePasswordAuthenticationProvider.java
index e62f260..eec4e5e 100644
--- a/src/main/java/io/qyi/e5/config/security/UsernamePasswordAuthenticationProvider.java
+++ b/src/main/java/io/qyi/e5/config/security/UsernamePasswordAuthenticationProvider.java
@@ -59,7 +59,7 @@ public class UsernamePasswordAuthenticationProvider implements AuthenticationPro
// 根据用户Token中的用户名查找用户信息,如果有该用户信息,则验证用户密码是否正确
String code = authenticationToken.getCode();
String state = authenticationToken.getState();
- logger.info("认证: code:{} state:{} Token:{}", code, state, authenticationToken.getToken());
+ logger.debug("认证: code:{} state:{} Token:{}", code, state, authenticationToken.getToken());
Map userInfo_redis = new HashMap<>();
if (!redisUtil.hasKey(states + state)) {
diff --git a/src/main/java/io/qyi/e5/controller/auth2/Auth.java b/src/main/java/io/qyi/e5/controller/auth2/Auth.java
index 0652de1..40e7952 100644
--- a/src/main/java/io/qyi/e5/controller/auth2/Auth.java
+++ b/src/main/java/io/qyi/e5/controller/auth2/Auth.java
@@ -37,11 +37,21 @@ public class Auth {
String client_id;
+ @Value("${github.replyUrl}")
+ String replyUrl;
+
+ @Value("${github.replyUrlDebug}")
+ String replyUrlDebug;
+
+ @Value("${isdebug}")
+ boolean isdebug;
+
+
@RequestMapping("/getGithubUrl")
public Result getGithubUrl() {
String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
redisUtil.set(states + state, true, 600);
- return ResultUtil.success("https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state);
+ return ResultUtil.success("https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=" + (isdebug ? replyUrlDebug : replyUrl) + "&state=" + state);
}
/* @RequestMapping("/receive")
diff --git a/src/main/java/io/qyi/e5/controller/web/WebController.java b/src/main/java/io/qyi/e5/controller/web/WebController.java
index 7687d21..1d06998 100644
--- a/src/main/java/io/qyi/e5/controller/web/WebController.java
+++ b/src/main/java/io/qyi/e5/controller/web/WebController.java
@@ -6,16 +6,18 @@ import io.qyi.e5.github.service.IGithubService;
import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.outlook_log.service.IOutlookLogService;
import io.qyi.e5.util.ResultUtil;
+import io.qyi.e5.util.SecurityUtils;
import io.qyi.e5.util.StringUtil;
import io.qyi.e5.util.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.util.DigestUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -41,6 +43,18 @@ public class WebController {
@Autowired
RedisUtil redisUtil;
+ @Value("${outlook.replyUrl}")
+ String replyUrl;
+
+ @Value("${outlook.replyUrlDebug}")
+ String replyUrlDebug;
+
+ @Value("${outlook.authorize.url}")
+ String authorizeUrl;
+
+ @Value("${isdebug}")
+ boolean isDebug;
+
@RequestMapping("/")
public Result index() {
return ResultUtil.error(-1, "This is api server!");
@@ -82,4 +96,17 @@ public class WebController {
return s;
}
+ @RequestMapping("getUserReplyUrlToOutlook")
+ public Result getUserReplyUrlToOutlook() {
+ String userIdMd5 = DigestUtils.md5DigestAsHex(String.valueOf(SecurityUtils.getUserInfo().getGithub_id()).getBytes());
+
+ String reUrl;
+ if (isDebug) {
+ reUrl = String.format(replyUrlDebug, userIdMd5);
+ } else {
+ reUrl = String.format(replyUrl, userIdMd5);
+ }
+ return ResultUtil.success(reUrl);
+ }
+
}
diff --git a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
index 04d0bbd..c724d30 100644
--- a/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
+++ b/src/main/java/io/qyi/e5/outlook/bean/OutlookVo.java
@@ -17,4 +17,6 @@ public class OutlookVo {
private Integer cronTimeRandomEnd;
private Integer step;
private Integer status;
+ private Integer outlookId;
+
}
diff --git a/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java b/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java
index 66d9f46..e00b081 100644
--- a/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java
+++ b/src/main/java/io/qyi/e5/outlook/bean/bo/UpdateBo.java
@@ -2,6 +2,9 @@ package io.qyi.e5.outlook.bean.bo;
import lombok.Data;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
/**
* @program: e5
* @description:
@@ -10,7 +13,15 @@ import lombok.Data;
**/
@Data
public class UpdateBo {
+ @NotEmpty(message = "[客户端]不能为空!")
private String client_id;
+
+ @NotEmpty(message = "[客户端密码]不能为空!")
private String client_secret;
- private int outlook_id;
+
+ @NotEmpty(message = "[租户ID]不能为空!")
+ private String tenant_id;
+
+ @NotNull(message = "[ID]不能为空!")
+ private Integer outlook_id;
}
diff --git a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java
index cc13fac..b1e82eb 100644
--- a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java
+++ b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java
@@ -9,10 +9,15 @@ import io.qyi.e5.outlook.service.IOutlookService;
import io.qyi.e5.service.task.ITask;
import io.qyi.e5.util.EncryptUtil;
import io.qyi.e5.util.ResultUtil;
+import io.qyi.e5.util.SecurityUtils;
import io.qyi.e5.util.redis.RedisUtil;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.util.DigestUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -24,6 +29,7 @@ import java.util.UUID;
* @author: 落叶随风
* @create: 2020-02-24 16:02
**/
+@Slf4j
@RestController
@RequestMapping("/outlook/auth2")
public class AuthController {
@@ -53,13 +59,27 @@ public class AuthController {
@RequestMapping("/receive")
- public Result Receive(String code, String state, String session_state) throws Exception {
+ public void receiveOld() {
+ throw new APIException("程序已更新,请按照教程重新操作。 https://qyi.io/archives/687.html");
+ }
+
+
+ @RequestMapping("/{userId}/receive")
+ public Result Receive(@PathVariable String userId, String code, String state, String session_state) throws Exception {
+ String userIdMd5 = DigestUtils.md5DigestAsHex(String.valueOf(SecurityUtils.getUserInfo().getGithub_id()).getBytes());
+ if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(userIdMd5)) {
+ throw new APIException("用户信息错误");
+ }
+ if (!userIdMd5.equals(userId)) {
+ throw new APIException("你设置的回复Url与你的用户信息不匹配。");
+ }
+
if (!redisUtil.hasKey(states + state)) {
throw new APIException("state已过期,请到用户中心重新授权!");
}
+ int outlookId = (int) redisUtil.get(states + state);
/*这里不应该查询,在进行授权时因该把基础数据丢到redis*/
QueryWrapper outlookQueryWrapper = new QueryWrapper<>();
- int outlookId = (int) redisUtil.get(states + state);
outlookQueryWrapper.eq("id", outlookId);
Outlook outlook = outlookService.getOne(outlookQueryWrapper);
/*删除redis中的此键*/
@@ -69,17 +89,18 @@ public class AuthController {
}
String reUrl = "";
if (isDebug) {
- reUrl = replyUrlDebug;
+ reUrl = String.format(replyUrlDebug, userIdMd5);
} else {
- reUrl = replyUrl;
+ reUrl = String.format(replyUrl, userIdMd5);
}
- boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), reUrl
+
+ boolean authorization_code = outlookService.getTokenAndSave(outlook.getTenantId(), code, outlook.getClientId(), outlook.getClientSecret(), reUrl
, "authorization_code");
if (!authorization_code) {
throw new APIException("clientId 或 clientSecret 填写错误!授权失败!");
}
/*添加此用户进消息队列*/
- Task.updateOutlookExecDateTime(outlook.getGithubId(),outlookId);
+ Task.updateOutlookExecDateTime(outlook.getGithubId(), outlookId);
return ResultUtil.success();
}
@@ -96,17 +117,25 @@ public class AuthController {
if (outlook.getClientId().length() < 1 || outlook.getClientSecret().length() < 1) {
throw new APIException("没有设置key你授权啥呢!!!");
}
+ if (StringUtils.isEmpty(outlook.getTenantId())) {
+ throw new APIException("该应用未设置租户ID,请参考教程进行设置。");
+ }
// 生成随机uuid标识用户
String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
redisUtil.set(states + state, id, 600);
+
+ String userIdMd5 = DigestUtils.md5DigestAsHex(String.valueOf(SecurityUtils.getUserInfo().getGithub_id()).getBytes());
+
String reUrl = "";
if (isDebug) {
- reUrl = replyUrlDebug;
+ reUrl = String.format(replyUrlDebug, userIdMd5);
+ ;
} else {
- reUrl = replyUrl;
+ reUrl = String.format(replyUrl, userIdMd5);
}
- String url = String.format(authorizeUrl, outlook.getClientId(), reUrl, state);
+
+ String url = String.format(authorizeUrl, outlook.getTenantId(), outlook.getClientId(), reUrl, state);
return ResultUtil.success(url);
} else {
throw new APIException("没有此记录");
diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
index 6ed51fa..8956867 100644
--- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
+++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java
@@ -19,6 +19,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
@@ -36,6 +37,7 @@ import java.util.List;
@RestController
@RequestMapping("/outlook/outlook")
@Slf4j
+@Validated
public class OutlookController {
@Autowired
@@ -51,9 +53,9 @@ public class OutlookController {
}
@PostMapping("/save")
- public ResultVO save(@RequestBody UpdateBo bo) {
+ public ResultVO save(@Validated @RequestBody UpdateBo bo) {
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
- if (outlookService.save(bo.getClient_id(), bo.getClient_secret(), bo.getOutlook_id(), authentication.getGithub_id())) {
+ if (outlookService.save(bo, authentication.getGithub_id())) {
return new ResultVO<>();
}
return new ResultVO<>();
@@ -122,10 +124,6 @@ public class OutlookController {
@GetMapping("/getOutlookList")
public Result getOutlookList() {
- log.info("测试MOD");
- log.debug("测试MOD");
- log.warn("测试MOD");
- log.error("测试MOD");
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
int github_id = authentication.getGithub_id();
List outlooklist = outlookService.getOutlooklist(github_id);
diff --git a/src/main/java/io/qyi/e5/outlook/entity/Outlook.java b/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
index 7e2efa5..1e5137a 100644
--- a/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
+++ b/src/main/java/io/qyi/e5/outlook/entity/Outlook.java
@@ -76,4 +76,9 @@ public class Outlook implements Serializable {
/*下次调用时间*/
private Integer nextTime;
+ /**
+ * 租户id
+ */
+ private String tenantId;
+
}
diff --git a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
index e3ea9b6..7654a96 100644
--- a/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
+++ b/src/main/java/io/qyi/e5/outlook/service/IOutlookService.java
@@ -1,6 +1,7 @@
package io.qyi.e5.outlook.service;
import com.baomidou.mybatisplus.extension.service.IService;
+import io.qyi.e5.outlook.bean.bo.UpdateBo;
import io.qyi.e5.outlook.entity.Outlook;
import java.util.List;
@@ -15,11 +16,11 @@ import java.util.List;
*/
public interface IOutlookService extends IService {
- boolean getTokenAndSave(String code, String client_id, String client_secret, String redirect_uri, String grant_type) throws Exception;
+ boolean getTokenAndSave(String tenantId, String code, String client_id, String client_secret, String redirect_uri, String grant_type) throws Exception;
Outlook insertOne(String name, String describe, int github_id);
- boolean save(String client_id, String client_secret, int outlook_id, int github_id);
+ boolean save(UpdateBo updateBo, int github_id);
boolean saveRandomTime(int github_id, int cron_time, int outlook_id, int cron_time_random_start, int cron_time_random_end);
@@ -40,8 +41,6 @@ public interface IOutlookService extends IService {
/**
* 更新数据
*
- * @param github_id: github_id
- * @param outlookId: outlookId
* @param outlook: 更新的数据
* @Author: 落叶随风
* @Date: 2020/12/19 21:29
diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
index 86041a3..0e79cb2 100644
--- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
+++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java
@@ -10,6 +10,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.qyi.e5.config.APiCode;
import io.qyi.e5.config.exception.APIException;
+import io.qyi.e5.outlook.bean.bo.UpdateBo;
import io.qyi.e5.outlook.entity.Outlook;
import io.qyi.e5.outlook.mapper.OutlookMapper;
import io.qyi.e5.outlook.service.IOutlookService;
@@ -49,7 +50,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
// 2020-03-2 10:38 这里需要进行查询判断数据库是否有内容再进行插入。
@Override
- public boolean getTokenAndSave(String code, String client_id, String client_secret, String redirect_uri, String grant_type) throws Exception {
+ public boolean getTokenAndSave(String tenantId, String code, String client_id, String client_secret, String redirect_uri, String grant_type) throws Exception {
Map head = new HashMap<>();
head.put("Content-Type", "application/x-www-form-urlencoded");
Map par = new HashMap<>();
@@ -58,7 +59,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
par.put("code", code);
par.put("redirect_uri", redirect_uri);
par.put("grant_type", grant_type);
- String s = OkHttpClientUtil.doPost("https://login.microsoftonline.com/common/oauth2/v2.0/token", head, par);
+ String s = OkHttpClientUtil.doPost("https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token", head, par);
JSONObject jsonObject = JSON.parseObject(s);
logger.info("请求access_token返回数据:" + s);
if (jsonObject.get("error") != null) {
@@ -91,7 +92,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
* @Author: 落叶随风
* @Date: 2020/12/19 21:25
* @Return: * @return: io.qyi.e5.outlook.entity.Outlook
- */
+ */
@Override
public Outlook insertOne(String name, String describe, int github_id) {
if (StringUtils.isBlank(name)) {
@@ -107,6 +108,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
return outlook;
}
+
/*
* 保存key
* @param client_id:
@@ -116,38 +118,34 @@ public class OutlookServiceImpl extends ServiceImpl impl
* @Author: 落叶随风
* @Date: 2020/12/19 21:24
* @Return: * @return: boolean
- */
+ */
@Override
- public boolean save(String client_id, String client_secret, int outlook_id, int github_id) {
- if (github_id == 0) {
- throw new APIException(APiCode.OUTLOOK_NAME_NOT_NULL);
- }
- if (outlook_id == 0 || StringUtils.isBlank(client_id) || StringUtils.isBlank(client_secret)) {
- throw new APIException("缺少参数!");
- }
+ public boolean save(UpdateBo updateBo, int github_id) {
QueryWrapper queryWrapper = new QueryWrapper<>();
// HashMap sc = new HashMap<>();
// sc.put("github_id", github_id);
// sc.put("id", outlook_id);
// queryWrapper.allEq(sc);
- queryWrapper.eq("github_id", github_id).eq("id", outlook_id);
+ queryWrapper.eq("github_id", github_id).eq("id", updateBo.getOutlook_id());
/*2020-12-10 mybatis plus问题导致会被截断*/
// Outlook outlook1 = baseMapper.selectOne(queryWrapper);
- Outlook outlook1 = baseMapper.selectOutlookOne(outlook_id, github_id);
+ Outlook outlook1 = baseMapper.selectOutlookOne(updateBo.getOutlook_id(), github_id);
if (outlook1 == null) {
throw new APIException("未查询到此条记录!");
}
- outlook1.setClientId(client_id);
- outlook1.setClientSecret(client_secret);
- outlook1.setStep(1)
- .setStatus(8);
+ outlook1.setClientId(updateBo.getClient_id())
+ .setClientSecret(updateBo.getClient_secret())
+ .setStep(1)
+ .setStatus(8)
+ .setTenantId(updateBo.getTenant_id());
;
if (baseMapper.update(outlook1, queryWrapper) != 1) {
throw new APIException("更新记录失败!");
}
return true;
}
+
/*
* 保存随机调用时间
* @param github_id: github_id
@@ -158,7 +156,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
* @Author: 落叶随风
* @Date: 2020/12/19 21:24
* @Return: * @return: boolean
- */
+ */
@Override
public boolean saveRandomTime(int github_id, int cron_time, int outlook_id, int cron_time_random_start, int cron_time_random_end) {
if (github_id == 0 || outlook_id == 0) {
@@ -181,19 +179,20 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
return false;
}
+
/*
* 查询所有列表
* @Author: 落叶随风
* @Date: 2020/12/19 21:23
* @Return: * @return: java.util.List
- */
+ */
@Override
public List findAll() {
return baseMapper.selectList(null);
}
@Override
- public List findRunOutlookList(){
+ public List findRunOutlookList() {
int nowDateTime = (int) (System.currentTimeMillis() / 1000);
List outlooks = baseMapper.selectList(new QueryWrapper().eq("status", 3).lt("next_time", nowDateTime));
return outlooks;
@@ -221,7 +220,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
* @Author: 落叶随风
* @Date: 2020/12/19 21:22
* @Return: * @return: int
- */
+ */
@Override
public int getMailList(Outlook outlook) throws Exception {
String s = MailList(outlook.getAccessToken());
@@ -247,9 +246,9 @@ public class OutlookServiceImpl extends ServiceImpl impl
throw new Exception("无法刷新令牌!code:2,错误消息: " + json.getJSONObject("error").getString("message"));
}
}
- logger.info("邮件列表请求成功!" + s);
+ logger.debug("邮件列表请求成功!" + s);
int mail_count = getMailBody(5, s, outlook.getAccessToken());
- logger.info("读取邮件数量: {}", mail_count);
+ logger.debug("读取邮件数量: {}", mail_count);
return mail_count;
}
@@ -291,13 +290,13 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
/**
+ * @throws
* @title 获取邮件列表,默认5封
* @description
* @author 落叶随风
* @param: access_token
* @updateTime 2020/12/19 21:17
* @return: java.lang.String
- * @throws
*/
public String MailList(String access_token) throws Exception {
Map head = new HashMap<>();
@@ -320,7 +319,7 @@ public class OutlookServiceImpl extends ServiceImpl impl
par.put("grant_type", "refresh_token");
par.put("refresh_token", outlook.getRefreshToken());
String s = null;
- s = OkHttpClientUtil.doPost("https://login.microsoftonline.com/common/oauth2/v2.0/token", head, par);
+ s = OkHttpClientUtil.doPost("https://login.microsoftonline.com/" + outlook.getTenantId() + "/oauth2/v2.0/token", head, par);
logger.info("请求刷新列表返回数据:" + s);
JSONObject jsonObject = JSON.parseObject(s);
if (!jsonObject.containsKey("access_token")) {
@@ -359,17 +358,16 @@ public class OutlookServiceImpl extends ServiceImpl impl
}
/**
+ * @throws
* @title 获取本账号下的outlook 应用列表
* @description
* @author 落叶随风
* @param: github_id
* @updateTime 2020/12/19 21:16
* @return: java.util.List
- * @throws
*/
@Override
public List getOutlooklist(int github_id) {
- log.info("测试MOD service");
QueryWrapper qw = new QueryWrapper().eq("github_id", github_id);
List outlooks = baseMapper.selectList(qw);
return outlooks;
@@ -377,13 +375,14 @@ public class OutlookServiceImpl extends ServiceImpl impl
/**
* 设置暂停状态
+ *
+ * @throws
* @title setPause
* @description
* @author 落叶随风
* @param: github_id
* @param: outlookId
* @updateTime 2020/12/19 21:16
- * @throws
*/
@Override
public void setPause(int github_id, int outlookId) {
@@ -404,13 +403,14 @@ public class OutlookServiceImpl extends ServiceImpl impl
/**
* 设置开始状态
+ *
+ * @throws
* @title setStart
* @description
* @author 落叶随风
* @param: github_id
* @param: outlookId
* @updateTime 2020/12/19 21:16
- * @throws
*/
@Override
public void setStart(int github_id, int outlookId) {
@@ -420,15 +420,17 @@ public class OutlookServiceImpl extends ServiceImpl impl
throw new APIException("更新失败!");
}
}
+
/**
- * 更新数据
- * @param outlook: 更新的数据
+ * 更新数据
+ *
+ * @param outlook: 更新的数据
* @Author: 落叶随风
* @Date: 2020/12/19 21:29
* @Return: * @return: void
- */
+ */
@Override
- public void update( Outlook outlook) {
+ public void update(Outlook outlook) {
UpdateWrapper uw = new UpdateWrapper<>();
uw.eq("id", outlook.getId());
uw.eq("github_id", outlook.getGithubId());
@@ -445,8 +447,9 @@ public class OutlookServiceImpl extends ServiceImpl impl
throw new APIException("删除失败!");
}
}
+
@Override
- public boolean isStatusRun(int github_id, int outlookId){
+ public boolean isStatusRun(int github_id, int outlookId) {
QueryWrapper wp = new QueryWrapper<>();
wp.eq("github_id", github_id);
wp.eq("id", outlookId);
diff --git a/src/main/java/io/qyi/e5/util/SecurityUtils.java b/src/main/java/io/qyi/e5/util/SecurityUtils.java
new file mode 100644
index 0000000..1b57379
--- /dev/null
+++ b/src/main/java/io/qyi/e5/util/SecurityUtils.java
@@ -0,0 +1,36 @@
+package io.qyi.e5.util;
+
+
+import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+public class SecurityUtils {
+
+ /**
+ * 获取当前登录用户
+ * @return
+ */
+ public static String getCurrentLoginUser() {
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+
+ if (authentication == null) {
+ throw new RuntimeException("当前无用户登录");
+ } else {
+ return authentication.getName();
+ }
+ }
+
+ /**
+ * 获取当前登录用户信息
+ * @return
+ */
+ public static UsernamePasswordAuthenticationToken getUserInfo() {
+ UsernamePasswordAuthenticationToken details = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
+ if (details == null) {
+ throw new RuntimeException("当前无用户登录");
+ }
+ return details;
+
+ }
+}
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
index e389c4d..6531f06 100644
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
@@ -84,6 +84,7 @@
+