Class CmsLoginManager
Stores invalid login attempts and disables a user account temporarily in case the configured threshold of invalid logins is reached.
The invalid login attempt storage operates on a combination of user name, login remote IP address and user type. This means that a user can be disabled for one remote IP, but still be enabled for another remote IP.
Also allows to temporarily disallow logins (for example in case of maintenance work on the system).
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Default token lifetime.static final int
Default lock time if treshold for bad login attempts is reached.static final boolean
Default setting for the security option.static final String
Separator used for storage keys.protected int
The milliseconds to disable an account if the threshold is reached.protected int
The minutes to disable an account if the threshold is reached.protected boolean
The flag to determine if the security option ahould be enabled on the login dialog.protected int
The number of bad login attempts allowed before an account is temporarily disabled.The storage for the bad login attempts.protected String
The token lifetime.static final int
Default for bad login attempts.Map holding usernames and userdata for user which are currently locked. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addInvalidLogin
(String userName, String remoteAddress) Adds an invalid attempt to login for the given user / IP to the storage.boolean
canLockBecauseOfInactivity
(CmsObject cms, CmsUser user) Checks whether a user account can be locked because of inactivity.boolean
checkInactive
(CmsUser user) Checks whether the given user has been inactive for longer than the configured limit.void
checkInvalidLogins
(String userName, String remoteAddress) Checks if the threshold for the invalid logins has been reached for the given user.void
Checks if a login is currently allowed.Returns the current before login message that is displayed on the login form.int
Returns the minutes an account gets disabled after too many failed login attempts.Returns the current login message that is displayed if a user logs in.Gets the logout URI.int
Returns the number of bad login attempts allowed before an account is temporarily disabled.Gets the max inactivity time.long
Gets the password change interval.Gets the raw password change interval string.long
Gets the authorization token lifetime in milliseconds.Gets the configured token lifetime as a string.long
Gets the user data check interval.Gets the raw user data check interval string.boolean
Returns if the security option ahould be enabled on the login dialog.boolean
isExcludedFromPasswordReset
(CmsObject cms, CmsUser user) Checks if the user should be excluded from password reset.boolean
Returns true if organizational unit selection should be required on login.boolean
isPasswordReset
(CmsObject cms, CmsUser user) Checks if password has to be reset.boolean
isUserLocked
(CmsUser user) Checks if a user is locked due to too many failed logins.boolean
isUserTempDisabled
(String username) Checks if given user it temporarily locked.protected void
removeInvalidLogins
(String userName, String remoteAddress) Removes all invalid attempts to login for the given user / IP.void
Removes the current login message.boolean
requiresPasswordChange
(CmsObject cms, CmsUser user) Checks if a user is required to change his password now.boolean
requiresUserDataCheck
(CmsObject cms, CmsUser user) Checks if a user is required to change his password now.void
resetUserTempDisable
(String username) Resets lock from user.void
setBeforeLoginMessage
(CmsObject cms, CmsLoginMessage message) Sets the before login message to display on the login form.void
setLoginMessage
(CmsObject cms, CmsLoginMessage message) Sets the login message to display if a user logs in.void
unlockUser
(CmsObject cms, CmsUser user) Unlocks a user who has exceeded his number of failed login attempts so that he can try to log in again.
-
Field Details
-
DEFAULT_TOKEN_LIFETIME
Default token lifetime.- See Also:
-
DISABLE_MINUTES_DEFAULT
Default lock time if treshold for bad login attempts is reached.- See Also:
-
ENABLE_SECURITY_DEFAULT
Default setting for the security option.- See Also:
-
KEY_SEPARATOR
Separator used for storage keys.- See Also:
-
MAX_BAD_ATTEMPTS_DEFAULT
Default for bad login attempts.- See Also:
-
TEMP_DISABLED_USER
Map holding usernames and userdata for user which are currently locked. -
m_disableMillis
The milliseconds to disable an account if the threshold is reached. -
m_disableMinutes
The minutes to disable an account if the threshold is reached. -
m_enableSecurity
The flag to determine if the security option ahould be enabled on the login dialog. -
m_maxBadAttempts
The number of bad login attempts allowed before an account is temporarily disabled. -
m_storage
The storage for the bad login attempts. -
m_tokenLifetimeStr
The token lifetime.
-
-
Constructor Details
-
CmsLoginManager
public CmsLoginManager(int disableMinutes, int maxBadAttempts, boolean enableSecurity, String tokenLifetime, String maxInactive, String passwordChangeInterval, String userDataCheckInterval, boolean requireOrgUnit, String logoutUri) Creates a new storage for invalid logins.- Parameters:
disableMinutes
- the minutes to disable an account if the threshold is reachedmaxBadAttempts
- the number of bad login attempts allowed before an account is temporarily disabledenableSecurity
- flag to determine if the security option should be enabled on the login dialogtokenLifetime
- the lifetime of authorization tokens, i.e. the time for which they are validmaxInactive
- maximum inactivity timepasswordChangeInterval
- the password change intervaluserDataCheckInterval
- the user data check intervalrequireOrgUnit
- if true, should require organizational unit selection on loginlogoutUri
- the alternative logout handler URI
-
-
Method Details
-
canLockBecauseOfInactivity
Checks whether a user account can be locked because of inactivity.- Parameters:
cms
- the CMS contextuser
- the user to check- Returns:
- true if the user may be locked after being inactive for too long
-
checkInactive
Checks whether the given user has been inactive for longer than the configured limit.If no max inactivity time is configured, always returns false.
- Parameters:
user
- the user to check- Returns:
- true if the user has been inactive for longer than the configured limit
-
checkInvalidLogins
public void checkInvalidLogins(String userName, String remoteAddress) throws CmsAuthentificationException Checks if the threshold for the invalid logins has been reached for the given user.In case the configured threshold is reached, an Exception is thrown.
- Parameters:
userName
- the name of the userremoteAddress
- the remote address (IP) from which the login attempt was made- Throws:
CmsAuthentificationException
- in case the threshold of invalid login attempts has been reached
-
checkLoginAllowed
Checks if a login is currently allowed.In case no logins are allowed, an Exception is thrown.
- Throws:
CmsAuthentificationException
- in case no logins are allowed
-
getBeforeLoginMessage
Returns the current before login message that is displayed on the login form.if
null
is returned, no login message has been currently set.- Returns:
- the current login message that is displayed if a user logs in
-
getDisableMinutes
Returns the minutes an account gets disabled after too many failed login attempts.- Returns:
- the minutes an account gets disabled after too many failed login attempts
-
getLoginMessage
Returns the current login message that is displayed if a user logs in.if
null
is returned, no login message has been currently set.- Returns:
- the current login message that is displayed if a user logs in
-
getLogoutUri
Gets the logout URI.If this is not null, users will be redirected to this JSP when logging out from the workplace or page editor. The JSP is responsible for invalidating the user's session.
- Returns:
- the logout URI
-
getMaxBadAttempts
Returns the number of bad login attempts allowed before an account is temporarily disabled.- Returns:
- the number of bad login attempts allowed before an account is temporarily disabled
-
getMaxInactive
Gets the max inactivity time.- Returns:
- the max inactivity time
-
getPasswordChangeInterval
Gets the password change interval.- Returns:
- the password change interval
-
getPasswordChangeIntervalStr
Gets the raw password change interval string.- Returns:
- the configured string for the password change interval
-
getTokenLifetime
Gets the authorization token lifetime in milliseconds.- Returns:
- the authorization token lifetime in milliseconds
-
getTokenLifetimeStr
Gets the configured token lifetime as a string.- Returns:
- the configured token lifetime as a string
-
getUserDataCheckInterval
Gets the user data check interval.- Returns:
- the user data check interval
-
getUserDataCheckIntervalStr
Gets the raw user data check interval string.- Returns:
- the configured string for the user data check interval
-
isEnableSecurity
Returns if the security option ahould be enabled on the login dialog.- Returns:
true
if the security option ahould be enabled on the login dialog, otherwisefalse
-
isExcludedFromPasswordReset
Checks if the user should be excluded from password reset.- Parameters:
cms
- the CmsObject to useuser
- the user to check- Returns:
- true if the user should be excluded from password reset
-
isOrgUnitRequired
Returns true if organizational unit selection should be required on login.- Returns:
- true if org unit selection should be required
-
isPasswordReset
Checks if password has to be reset.- Parameters:
cms
- CmsObjectuser
- CmsUser- Returns:
- true if password should be reset
-
isUserLocked
Checks if a user is locked due to too many failed logins.- Parameters:
user
- the user to check- Returns:
- true if the user is locked
-
isUserTempDisabled
Checks if given user it temporarily locked.- Parameters:
username
- to check- Returns:
- true if user is locked
-
removeLoginMessage
Removes the current login message.This operation requires that the current user has role permissions of
.CmsRole.ROOT_ADMIN
- Parameters:
cms
- the current OpenCms user context- Throws:
CmsRoleViolationException
- in case the current user does not have the required role permissions
-
requiresPasswordChange
Checks if a user is required to change his password now.- Parameters:
cms
- the current CMS contextuser
- the user to check- Returns:
- true if the user should be asked to change his password
-
requiresUserDataCheck
Checks if a user is required to change his password now.- Parameters:
cms
- the current CMS contextuser
- the user to check- Returns:
- true if the user should be asked to change his password
-
resetUserTempDisable
Resets lock from user.- Parameters:
username
- to reset lock for
-
setBeforeLoginMessage
public void setBeforeLoginMessage(CmsObject cms, CmsLoginMessage message) throws CmsRoleViolationException Sets the before login message to display on the login form.This operation requires that the current user has role permissions of
.CmsRole.ROOT_ADMIN
- Parameters:
cms
- the current OpenCms user contextmessage
- the message to set- Throws:
CmsRoleViolationException
- in case the current user does not have the required role permissions
-
setLoginMessage
public void setLoginMessage(CmsObject cms, CmsLoginMessage message) throws CmsRoleViolationException Sets the login message to display if a user logs in.This operation requires that the current user has role permissions of
.CmsRole.ROOT_ADMIN
- Parameters:
cms
- the current OpenCms user contextmessage
- the message to set- Throws:
CmsRoleViolationException
- in case the current user does not have the required role permissions
-
unlockUser
Unlocks a user who has exceeded his number of failed login attempts so that he can try to log in again.This requires the "account manager" role.
- Parameters:
cms
- the current CMS contextuser
- the user to unlock- Throws:
CmsRoleViolationException
- if the permission check fails
-
addInvalidLogin
Adds an invalid attempt to login for the given user / IP to the storage.In case the configured threshold is reached, the user is disabled for the configured time.
- Parameters:
userName
- the name of the userremoteAddress
- the remore address (IP) from which the login attempt was made
-
removeInvalidLogins
Removes all invalid attempts to login for the given user / IP.- Parameters:
userName
- the name of the userremoteAddress
- the remore address (IP) from which the login attempt was made
-