Package org.opencms.ui.login
Class CmsTokenValidator
java.lang.Object
org.opencms.ui.login.CmsTokenValidator
Helper class for dealing with authorization tokens for the 'forgot password' functionality.
When a user requests a link to change his password, an authorization token is generated and also stored in the user's additional info (in a slightly different form). When the user opens the 'change password' link sent to him, the authentication token is validated by comparing it to the token in the user's additional info. Additionally, the system checks whether the age of the token stored in the additional infos is older than the maximum age, which can also be configured.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Additional info key to store the authorization data. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clearToken
(CmsObject cms, CmsUser user) Removes an authorization token from the user's additional information.static String
createToken
(CmsObject cms, CmsUser user, long currentTime) Creates a new token for the given user and stores it in the user's additional info.getUser()
Gets the user.validateToken
(CmsObject cms, String token, long maxAgeMillis) Validates the authentication token against the token stored in the user's additional info.
-
Field Details
-
ADDINFO_KEY
Additional info key to store the authorization data.- See Also:
-
-
Constructor Details
-
CmsTokenValidator
public CmsTokenValidator()
-
-
Method Details
-
clearToken
Removes an authorization token from the user's additional information.- Parameters:
cms
- the CMS contextuser
- the user- Throws:
CmsException
- if something goes wrong
-
createToken
Creates a new token for the given user and stores it in the user's additional info.- Parameters:
cms
- the CMS contextuser
- the usercurrentTime
- the current time- Returns:
- the authorization token
- Throws:
CmsException
- if something goes wrong
-
getUser
Gets the user.- Returns:
- the user
-
validateToken
Validates the authentication token against the token stored in the user's additional info.- Parameters:
cms
- the CMS contexttoken
- the authentication tokenmaxAgeMillis
- the maximum token age in milliseconds- Returns:
- null if the validation is succesfull, or a string containing the error message if not
- Throws:
CmsException
- if something goes wrong
-