Skip to content

Commit

Permalink
refactor: Refactor cookie expire time calculation with the help of ja…
Browse files Browse the repository at this point in the history
…va.time.Duration class
  • Loading branch information
sumanmaity1234 committed Oct 9, 2023
1 parent 31cef16 commit e21e8ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.Duration;
import java.util.Optional;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -38,9 +39,9 @@ public class GithubAuthenticationSuccessHandler extends SimpleUrlAuthenticationS
private static final String ACCESS_TOKEN = "access_token";
private static final String REFRESH_TOKEN = "refresh_token";

private static final int ONE_DAY = 60 * 60 * 24;
private static final int SEVEN_HOURS = 60 * 60 * 7;
private static final int FIVE_MONTHS = 60 * 60 * 24 * 30 * 5;
private static final int ONE_DAY = Math.toIntExact(Duration.ofDays(1).toSeconds());
private static final int SEVEN_HOURS = Math.toIntExact(Duration.ofHours(7).toSeconds());
private static final int FIVE_MONTHS = Math.toIntExact(Duration.ofDays(150).toSeconds());

private final OAuth2AuthorizedClientService clientService;
private final String contextPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.time.Duration;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -45,9 +46,9 @@ class GithubAuthenticationSuccessHandlerTest {
private static final String ACCESS_TOKEN = "access_token";
private static final String REFRESH_TOKEN = "refresh_token";

private static final int ONE_DAY = 60 * 60 * 24;
private static final int SEVEN_HOURS = 60 * 60 * 7;
private static final int FIVE_MONTHS = 60 * 60 * 24 * 30 * 5;
private static final int ONE_DAY = Math.toIntExact(Duration.ofDays(1).toSeconds());
private static final int SEVEN_HOURS = Math.toIntExact(Duration.ofHours(7).toSeconds());
private static final int FIVE_MONTHS = Math.toIntExact(Duration.ofDays(150).toSeconds());

private GithubAuthenticationSuccessHandler authenticationSuccessHandler;

Expand Down

0 comments on commit e21e8ea

Please sign in to comment.