Record Class LoginAttemptContext

java.lang.Object
java.lang.Record
com.svenruppert.jsentinel.bruteforce.LoginAttemptContext
Record Components:
username - the username being attempted; may be null if not yet known (e.g. raw form submission)
clientAddress - the remote client address as observed by the adapter; may be null if unavailable
sessionId - session identifier, or null if there is no session yet
timestamp - when the attempt is observed; defaults to "now" via now(String, String, String)

public record LoginAttemptContext(String username, String clientAddress, String sessionId, Instant timestamp) extends Record
Adapter-neutral input to a LoginAttemptPolicy decision.

The username and client address are normalised before throttling — the caller is expected to pass them as-is, the policy does the lower-casing and trimming so identical user / client pairs collapse into the same counter.

  • Constructor Details

    • LoginAttemptContext

      public LoginAttemptContext(String username, String clientAddress, String sessionId, Instant timestamp)
      Creates an instance of a LoginAttemptContext record class.
      Parameters:
      username - the value for the username record component
      clientAddress - the value for the clientAddress record component
      sessionId - the value for the sessionId record component
      timestamp - the value for the timestamp record component
  • Method Details

    • now

      public static LoginAttemptContext now(String username, String clientAddress, String sessionId)
      Factory for the common case — the policy supplies the timestamp.
      Parameters:
      username - attempted username (may be null for anonymous flows; throttling does not apply)
      clientAddress - remote client address (may be null)
      sessionId - bound session id, if available (may be null)
      Returns:
      a context with Instant.now() as the timestamp
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • username

      public String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • clientAddress

      public String clientAddress()
      Returns the value of the clientAddress record component.
      Returns:
      the value of the clientAddress record component
    • sessionId

      public String sessionId()
      Returns the value of the sessionId record component.
      Returns:
      the value of the sessionId record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component