Record Class KeyExpirationWarning
java.lang.Object
java.lang.Record
co.ankatech.ankasecure.sdk.model.warning.KeyExpirationWarning
- Record Components:
daysRemaining- number of days until key expires (must be positive)
- All Implemented Interfaces:
CryptoWarning
Warning indicating that a cryptographic key is approaching expiration.
Severity automatically escalates based on days remaining, allowing applications to implement tiered response strategies (alerting, automated rotation, etc.).
Severity escalation thresholds:
- CRITICAL - 7 days or less (immediate action required)
- WARNING - 8-14 days (plan rotation this week)
- NOTICE - 15-30 days (schedule rotation soon)
- INFO - More than 30 days (awareness only)
Example - Severity-based handling:
for (CryptoWarning w : result.getWarnings()) {
if (w instanceof KeyExpirationWarning kew) {
switch (kew.severity()) {
case CRITICAL -> {
logger.error("URGENT: {}", kew.message());
triggerEmergencyRotation(result.getKeyRequested());
}
case WARNING ->
scheduleRotationThisWeek(kew.daysRemaining());
case NOTICE ->
planRotation(kew.daysRemaining());
case INFO ->
logger.info("{}", kew.message());
}
}
}
Example - Pattern matching with guard:
switch (warning) {
case KeyExpirationWarning kew when kew.daysRemaining() <= 3 ->
sendPagerDutyAlert("Key expires in " + kew.daysRemaining() + " days!");
case KeyExpirationWarning kew ->
logger.warn("{} - {}", kew.message(), kew.recommendedAction());
}
- Since:
- 3.0.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionKeyExpirationWarning(int daysRemaining) Creates an instance of aKeyExpirationWarningrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the value of thedaysRemainingrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.message()Returns a human-readable warning message.Returns the recommended action to address this warning.severity()Returns the severity level of this warning.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
KeyExpirationWarning
public KeyExpirationWarning(int daysRemaining) Creates an instance of aKeyExpirationWarningrecord class.- Parameters:
daysRemaining- the value for thedaysRemainingrecord component
-
-
Method Details
-
severity
Description copied from interface:CryptoWarningReturns the severity level of this warning.- Specified by:
severityin interfaceCryptoWarning- Returns:
- warning severity (INFO, NOTICE, WARNING, or CRITICAL)
-
message
Description copied from interface:CryptoWarningReturns a human-readable warning message.- Specified by:
messagein interfaceCryptoWarning- Returns:
- descriptive message
-
recommendedAction
Description copied from interface:CryptoWarningReturns the recommended action to address this warning.- Specified by:
recommendedActionin interfaceCryptoWarning- Returns:
- actionable guidance for the user
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
daysRemaining
public int daysRemaining()Returns the value of thedaysRemainingrecord component.- Returns:
- the value of the
daysRemainingrecord component
-