2
0

fix: 修复omada上云问题

This commit is contained in:
caiyuchao
2025-01-20 11:39:58 +08:00
parent 6c10050fe7
commit d17153ed50
10 changed files with 40 additions and 17 deletions

View File

@@ -32,11 +32,5 @@
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -4,7 +4,6 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.ParameterizedTypeReference;
@@ -27,7 +26,6 @@ import java.util.concurrent.TimeUnit;
* @author: caiyuchao
* @date: 2024-11-21
*/
@Slf4j
@Configuration
public class FeignConfig implements RequestInterceptor {
@@ -85,9 +83,6 @@ public class FeignConfig implements RequestInterceptor {
requestTemplate.uri("/openapi/v1/" + omadaProperties.getOmadacId() + lastUri);
}
log.info("requestTemplate path:{}", requestTemplate.path());
log.info("omadacId:{}", omadaProperties.getOmadacId());
log.info("authorization:{}", authorization);
// 添加授权请求头
requestTemplate.header(AUTHORIZATION, authorization);
}

View File

@@ -57,4 +57,7 @@ public interface RemoteUserService
@PostMapping("/device/settingJob")
public R<Boolean> settingJob();
@PostMapping("/device/testJob")
public R<String> testJob();
}

View File

@@ -52,6 +52,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
public R<Boolean> settingJob() {
return R.fail("oamda setting job error:" + throwable.getMessage());
}
@Override
public R<String> testJob() {
return R.fail("oamda test job error:" + throwable.getMessage());
}
};
}
}

View File

@@ -21,6 +21,8 @@ import org.wfc.gateway.config.properties.IgnoreWhiteProperties;
import io.jsonwebtoken.Claims;
import reactor.core.publisher.Mono;
import java.util.Arrays;
/**
* 网关鉴权
*
@@ -38,6 +40,8 @@ public class AuthFilter implements GlobalFilter, Ordered
@Autowired
private RedisService redisService;
private static final String[] feignOmadaUrls = {"system/dashboard/overview", "system/dashboard/page", "schedule/job/run", "system/client/list"};
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain)
@@ -83,6 +87,10 @@ public class AuthFilter implements GlobalFilter, Ordered
addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid);
addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username);
addHeader(mutate, SecurityConstants.DETAILS_PLATFORM, platform);
// feign omada api 调用处理
if (Arrays.stream(feignOmadaUrls).anyMatch(url::contains)) {
removeHeader(mutate, SecurityConstants.AUTHORIZATION_HEADER);
}
// 内部请求来源参数清除
removeHeader(mutate, SecurityConstants.FROM_SOURCE);
return chain.filter(exchange.mutate().request(mutate.build()).build());

View File

@@ -20,7 +20,6 @@ import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
//import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.job.domain.SysJob;
import org.wfc.job.service.ISysJobService;
@@ -176,9 +175,9 @@ public class SysJobController extends BaseController
{
SysJob sysJob = jobService.selectJobById(job.getJobId());
if (sysJob != null && sysJob.getInvokeTarget().contains("omadaTask")) {
R<Boolean> omadaResult = omadaTask.testOmadaApi();
if (omadaResult.getCode() != 200) {
return error(omadaResult.getMsg());
R<String> omadaResult = omadaTask.testOmadaApi();
if (!"success".equals(omadaResult.getData())) {
return error(omadaResult.getData());
}
}

View File

@@ -30,8 +30,8 @@ public class OmadaTask {
log.info("wifi定时任务执行成功, 耗时:{} 毫秒", endTime - startTime);
}
public R<Boolean> testOmadaApi() {
return remoteUserService.deviceJob();
public R<String> testOmadaApi() {
return remoteUserService.testJob();
}
public R<Boolean> initJob() {

View File

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
@@ -80,4 +81,9 @@ public class SysDeviceController extends BaseController {
public AjaxResult settingJob() {
return toAjax(sysDeviceService.settingJob());
}
@PostMapping("/testJob")
public R<String> testJob() {
return R.ok(sysDeviceService.testJob());
}
}

View File

@@ -16,4 +16,6 @@ public interface ISysDeviceService extends IService<SysDevice> {
boolean deviceJob();
boolean settingJob();
String testJob();
}

View File

@@ -53,8 +53,10 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
private static final String REDIS_ACCESS_TOKEN = "wfc-api-omada:access-token";
private static final String REDIS_REFRESH_TOKEN = "wfc-api-omada:refresh-token";
private static final int OMADA_ERROR_CODE = -44112;
private static final int OMADA_SUCCESS_CODE = 0;
@Transactional(rollbackFor = Exception.class)
@Override
public boolean deviceJob() {
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000);
if (siteList.getBody() == null) {
@@ -92,6 +94,7 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
return true;
}
@Override
public boolean settingJob() {
// 启用Omada历史记录保留
ResponseEntity<OperationResponseHistoryRetentionOpenApiVo> dataRetentionRes = omadaHistoryDataRetentionApi.getDataRetention();
@@ -115,4 +118,12 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
return true;
}
@Override
public String testJob() {
ResponseEntity<OperationResponseGridVoSiteSummaryInfo> siteList = omadaSiteApi.getSiteList(1, 1000);
if (siteList.getBody() != null && siteList.getBody().getErrorCode() == OMADA_SUCCESS_CODE) {
return "success";
}
return siteList.getBody().getMsg();
}
}