Skip to content

Commit

Permalink
Handle missing expire date of API token
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Jun 7, 2023
1 parent 05893ad commit d434b05
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/cloudgene/mapred/util/JSONConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class JSONConverter {

public static final String MESSAGE_EXPIRED_TOKEN = "API Token was created by %s and expired on %s.";

public static final String MESSAGE_INVALID_TOKEN = "API Token was created with a previous version and is therefore invalid. Please recreate.";

public static JSONObject convert(AbstractJob job) {

JsonConfig config = new JsonConfig();
Expand Down Expand Up @@ -233,7 +235,10 @@ public static JSONObject convert(User user) {
boolean hasApiToken = user.getApiToken() != null && !user.getApiToken().isEmpty();
object.put("hasApiToken", hasApiToken);
if (hasApiToken) {
if (user.getApiTokenExpiresOn().getTime() > System.currentTimeMillis()) {
if (user.getApiTokenExpiresOn() == null) {
object.put("apiTokenValid", false);
object.put("apiTokenMessage", MESSAGE_INVALID_TOKEN);
} else if (user.getApiTokenExpiresOn().getTime() > System.currentTimeMillis()) {
object.put("apiTokenValid", true);
object.put("apiTokenMessage",
String.format(MESSAGE_VALID_TOKEN, user.getUsername(), user.getApiTokenExpiresOn()));
Expand Down

0 comments on commit d434b05

Please sign in to comment.