2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.asuswrt.internal.api;
15 import static org.openhab.binding.asuswrt.internal.constants.AsuswrtBindingSettings.COOKIE_LIFETIME_S;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * The {@link AsuswrtCookie} is used for storing cookie details.
22 * @author Christian Wild - Initial contribution
25 public class AsuswrtCookie {
26 protected String cookie = "";
27 protected String token = "";
28 protected Long cookieTimeStamp = 0L;
31 * Set and reset functions
37 public void setCookie(String cookie) {
39 cookieTimeStamp = System.currentTimeMillis();
45 public void resetCookie() {
56 * Checks if a cookie is set.
58 public boolean cookieIsSet() {
59 return !cookie.isBlank();
63 * Checks if a cookie is expired.
65 * @return <code>true</code> if cookie is set and expired
67 public boolean cookieIsExpired() {
68 return cookieTimeStamp > 0L && System.currentTimeMillis() > cookieTimeStamp + (COOKIE_LIFETIME_S * 1000);
72 * Checks if a cookie is set and not expired.
74 public boolean isValid() {
75 return !cookieIsExpired() && cookieIsSet();
81 public String getCookie() {