From a4965b0ba618882b73a4d02ac570bda1d65e4620 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Thu, 15 Feb 2024 12:52:40 +0200 Subject: [PATCH] Fix scheduler time unit for mail refresh token check --- .../server/service/mail/RefreshTokenExpCheckService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/mail/RefreshTokenExpCheckService.java b/application/src/main/java/org/thingsboard/server/service/mail/RefreshTokenExpCheckService.java index 56f3c4c4c5..9cb3fc01d7 100644 --- a/application/src/main/java/org/thingsboard/server/service/mail/RefreshTokenExpCheckService.java +++ b/application/src/main/java/org/thingsboard/server/service/mail/RefreshTokenExpCheckService.java @@ -35,6 +35,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; import java.io.IOException; import java.time.Duration; import java.time.Instant; +import java.util.concurrent.TimeUnit; import static org.thingsboard.server.common.data.mail.MailOauth2Provider.OFFICE_365; @@ -46,7 +47,9 @@ public class RefreshTokenExpCheckService { public static final int AZURE_DEFAULT_REFRESH_TOKEN_LIFETIME_IN_DAYS = 90; private final AdminSettingsService adminSettingsService; - @Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${mail.oauth2.refreshTokenCheckingInterval})}", fixedDelayString = "${mail.oauth2.refreshTokenCheckingInterval}") + @Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${mail.oauth2.refreshTokenCheckingInterval})}", + fixedDelayString = "${mail.oauth2.refreshTokenCheckingInterval}", + timeUnit = TimeUnit.SECONDS) public void check() throws IOException { AdminSettings settings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail"); if (settings != null && settings.getJsonValue().has("enableOauth2") && settings.getJsonValue().get("enableOauth2").asBoolean()) { @@ -65,8 +68,8 @@ public class RefreshTokenExpCheckService { new GenericUrl(tokenUri), refreshToken) .setClientAuthentication(new ClientParametersAuthentication(clientId, clientSecret)) .execute(); - ((ObjectNode)jsonValue).put("refreshToken", tokenResponse.getRefreshToken()); - ((ObjectNode)jsonValue).put("refreshTokenExpires", Instant.now().plus(Duration.ofDays(AZURE_DEFAULT_REFRESH_TOKEN_LIFETIME_IN_DAYS)).toEpochMilli()); + ((ObjectNode) jsonValue).put("refreshToken", tokenResponse.getRefreshToken()); + ((ObjectNode) jsonValue).put("refreshTokenExpires", Instant.now().plus(Duration.ofDays(AZURE_DEFAULT_REFRESH_TOKEN_LIFETIME_IN_DAYS)).toEpochMilli()); adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, settings); } }