Skip to content

Commit

Permalink
Merge pull request #140 from orchitech/token-max-validity
Browse files Browse the repository at this point in the history
Handle token validity maximum value.
  • Loading branch information
pavelhoral authored Jul 21, 2023
2 parents a5ffb93 + 0ca86f8 commit 0ee1943
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Portions copyright 2022 Wren Security
* Portions copyright 2022-2023 Wren Security
*/
package org.forgerock.openam.cts.api.tokens;

Expand Down Expand Up @@ -59,6 +59,9 @@
@Description(CORE_TOKEN_RESOURCE + "resource.schema." + DESCRIPTION)
public class Token {

// Maximum allowed value of token validity
private static final String MAX_ALLOWED_DATETIME = "99991231235959.000Z";

/**
* Note: This map stores all data for the Token. It is intentionally using a String to Object mapping
* rather than a CoreTokenField based key because this works better with Jackson based JSON
Expand Down Expand Up @@ -315,7 +318,11 @@ private void put(CoreTokenField field, Object value) {
} else if (CoreTokenField.TOKEN_TYPE.equals(field)) {
s = ((TokenType) value).name();
} else if (CoreTokenFieldTypes.isCalendar(field)) {
s = GeneralizedTime.valueOf((Calendar) value).toString();
if (((Calendar) value).get(Calendar.YEAR) > 9999) {
s = MAX_ALLOWED_DATETIME;
} else {
s = GeneralizedTime.valueOf((Calendar) value).toString();
}
} else if (CoreTokenFieldTypes.isByteArray(field)) {
s = Base64.encode((byte[]) value);
} else if (CoreTokenFieldTypes.isInteger(field)) {
Expand Down

0 comments on commit 0ee1943

Please sign in to comment.