Class Throttler

java.lang.Object
com.jalios.jcms.security.Throttler
Direct Known Subclasses:
AuthenticationThrottleManager

public class Throttler extends Object
Provides throttling of action that requires it.
Since:
jcms-10.0.7 / JCMS-8083
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Class used to track information about Action that might be throttled.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Enable throttling or not ?
    static final String
    Time range in seconds during which the threshold is verified.
    static final String
    Number of action attempts permitted in specified time range.
    static final String
    Number of seconds before the blocked/throttled can be released.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Throttler(String throttledActionName, String propertyPrefix, org.apache.log4j.Logger logger)
    Construct a new Throttler with all the specified parameter
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the period of time during which the threshold applies.
    protected static String
    getRemoteIp(javax.servlet.http.HttpServletRequest request)
    Return the remote IP of the specified HttpServletRequest
    int
    Return the maximum number of action attempts permitted in the range period.
    Return the duration user must wait before the blocked/throttled can be released.
    void
    Initialize this ThrottleManager.
    void
    init(com.google.common.base.Ticker ticker)
    Initialize this ThrottleManager with the specified Ticker instance.
    boolean
    Check if throttling is enabled or not ?
    void
    Record a potentially throttled action.
    void
    recordAction(String userId, javax.servlet.http.HttpServletRequest request)
    Record a potentially throttled action.
    boolean
    throttleIfNeeded(String userId, javax.servlet.http.HttpServletRequest request)
    Throttle an action attempt given specified context.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ENABLED_PROP_SUFFIX

      public static final String ENABLED_PROP_SUFFIX
      Enable throttling or not ?
      See Also:
    • RANGE_PROP_SUFFIX

      public static final String RANGE_PROP_SUFFIX
      Time range in seconds during which the threshold is verified.
      See Also:
    • THRESHOLD_PROP_SUFFIX

      public static final String THRESHOLD_PROP_SUFFIX
      Number of action attempts permitted in specified time range.
      See Also:
    • THROTTLING_DURATION_PROP_SUFFIX

      public static final String THROTTLING_DURATION_PROP_SUFFIX
      Number of seconds before the blocked/throttled can be released.
      See Also:
  • Constructor Details

    • Throttler

      public Throttler(String throttledActionName, String propertyPrefix, org.apache.log4j.Logger logger)
      Construct a new Throttler with all the specified parameter
      Parameters:
      throttledActionName - name of the action being verified by this throttler, used during logging, for example "Authentication failure", "Password Reset request", ... required
      propertyPrefix - the property prefix to use to load configuration, for example "my-feature.throttling.". required
      logger - the Logger to use, required
  • Method Details

    • init

      public void init()
      Initialize this ThrottleManager.

      This method can be called multiple time during the lifetime of the site, for example on properties change.

    • init

      public void init(com.google.common.base.Ticker ticker)
      Initialize this ThrottleManager with the specified Ticker instance.

      This method can be called multiple time during the lifetime of the site, for example on properties change.

      Parameters:
      ticker - specified a custom ticket during unittest
    • recordAction

      public void recordAction(String userId, javax.servlet.http.HttpServletRequest request)
      Record a potentially throttled action.
      Parameters:
      userId - a unique and constant identifier used to track the User/Member for which authentication failed
      request - the HttpServletRequest which triggered this action (optional but highly recommended)
      Since:
      jcms-10.0.7 / JCMS-8083
    • recordAction

      public void recordAction(Throttler.Action action)
      Record a potentially throttled action.
      Parameters:
      action - a valid Action
      Since:
      jcms-10.0.7 / JCMS-8083
    • throttleIfNeeded

      public boolean throttleIfNeeded(String userId, javax.servlet.http.HttpServletRequest request)
      Throttle an action attempt given specified context.
      Parameters:
      userId - a unique and constant identifier used to track the User/Member for which action is being attempted
      request - the ServletRequest for which throttle is verified
      Returns:
      true if thottling occurred, false otherwise
      Since:
      jcms-10.0.7 / JCMS-8083
    • getRemoteIp

      protected static String getRemoteIp(javax.servlet.http.HttpServletRequest request)
      Return the remote IP of the specified HttpServletRequest
      Parameters:
      request - a request (can be null)
      Returns:
      the remote addr, or empty string if there is no request
    • isThrottleEnabled

      public boolean isThrottleEnabled()
      Check if throttling is enabled or not ?
      Returns:
      true if enabled, false otherwise
    • getRange

      public Duration getRange()
      Return the period of time during which the threshold applies.
      Returns:
      a duration
    • getThreshold

      public int getThreshold()
      Return the maximum number of action attempts permitted in the range period.
      Returns:
      a maximum number of action
    • getThrottleDuration

      public Duration getThrottleDuration()
      Return the duration user must wait before the blocked/throttled can be released.
      Returns:
      a duration