Package com.jalios.jcms.security
Class Throttler
java.lang.Object
com.jalios.jcms.security.Throttler
- Direct Known Subclasses:
AuthenticationThrottleManager
Provides throttling of action that requires it.
- Since:
- jcms-10.0.7 / JCMS-8083
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass used to track information about Action that might be throttled. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEnable throttling or not ?static final StringTime range in seconds during which the threshold is verified.static final StringNumber of action attempts permitted in specified time range.static final StringNumber of seconds before the blocked/throttled can be released. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetRange()Return the period of time during which the threshold applies.protected static StringgetRemoteIp(javax.servlet.http.HttpServletRequest request) Return the remote IP of the specified HttpServletRequestintReturn the maximum number of action attempts permitted in the range period.Return the duration user must wait before the blocked/throttled can be released.voidinit()Initialize this ThrottleManager.voidinit(com.google.common.base.Ticker ticker) Initialize this ThrottleManager with the specified Ticker instance.booleanCheck if throttling is enabled or not ?voidrecordAction(Throttler.Action action) Record a potentially throttled action.voidrecordAction(String userId, javax.servlet.http.HttpServletRequest request) Record a potentially throttled action.booleanthrottleIfNeeded(String userId, javax.servlet.http.HttpServletRequest request) Throttle an action attempt given specified context.
-
Field Details
-
ENABLED_PROP_SUFFIX
Enable throttling or not ?- See Also:
-
RANGE_PROP_SUFFIX
Time range in seconds during which the threshold is verified.- See Also:
-
THRESHOLD_PROP_SUFFIX
Number of action attempts permitted in specified time range.- See Also:
-
THROTTLING_DURATION_PROP_SUFFIX
Number of seconds before the blocked/throttled can be released.- See Also:
-
-
Constructor Details
-
Throttler
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", ... requiredpropertyPrefix- the property prefix to use to load configuration, for example"my-feature.throttling.". requiredlogger- 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
Record a potentially throttled action.- Parameters:
userId- a unique and constant identifier used to track the User/Member for which authentication failedrequest- the HttpServletRequest which triggered this action (optional but highly recommended)- Since:
- jcms-10.0.7 / JCMS-8083
-
recordAction
Record a potentially throttled action.- Parameters:
action- a valid Action- Since:
- jcms-10.0.7 / JCMS-8083
-
throttleIfNeeded
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 attemptedrequest- the ServletRequest for which throttle is verified- Returns:
- true if thottling occurred, false otherwise
- Since:
- jcms-10.0.7 / JCMS-8083
-
getRemoteIp
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
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
Return the duration user must wait before the blocked/throttled can be released.- Returns:
- a duration
-