Skip to content

Commit

Permalink
refactor: dingding whitelist (apache#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jifengzhilong authored Feb 5, 2024
2 parents 49bbf86 + 0a57ce3 commit 1cd18d8
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

import javax.annotation.PostConstruct;
import java.util.*;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* @author zhangxiaowei6
Expand Down Expand Up @@ -99,25 +101,32 @@ public void init() throws Exception {
dingCardClient = new com.aliyun.dingtalkcard_1_0.Client(dingConfig);
dingOauthClient = new com.aliyun.dingtalkoauth2_1_0.Client(dingConfig);
//registerDingDingCallBack();
//fill in white list
if (!StringUtils.isBlank(whiteListStr)) {
List<String> whiteList = Arrays.asList(whiteListStr.split(",", -1));
log.info("DingDingService init whiteList is :{}", whiteList);
if (whiteList.size() % 2 != 0) {
log.error("DingDingService sendDingDing whiteList error , because whiteList size is not even");
return;
}
//fill in map
for (int i = 0; i < whiteList.size(); i = i + 2) {
whiteListMap.put(whiteList.get(i), whiteList.get(i + 1));
}
}
//user type judge
if (!dingdingUserType.equals("userId") && !dingdingUserType.equals("unionId")) {
log.error("DingDingService.userType not valid, userType: {}",dingdingUserType);
//set default value
dingdingUserType = "userId";
}
periodicRefreshWhiteList();
}

//2m auto refresh white list
private void periodicRefreshWhiteList() {
new ScheduledThreadPoolExecutor(1).scheduleWithFixedDelay(() -> {
//fill in white list
if (!StringUtils.isBlank(whiteListStr)) {
List<String> whiteList = Arrays.asList(whiteListStr.split(",", -1));
log.info("DingDingService init whiteList is :{}", whiteList);
if (whiteList.size() % 2 != 0) {
log.error("DingDingService sendDingDing whiteList error , because whiteList size is not even");
return;
}
//fill in map
for (int i = 0; i < whiteList.size(); i = i + 2) {
whiteListMap.put(whiteList.get(i), whiteList.get(i + 1));
}
}
}, 0, 120, TimeUnit.SECONDS);
}

private String getAccessToken() {
Expand Down

0 comments on commit 1cd18d8

Please sign in to comment.