Package io.meeds.deeds.common.service
Class AuthorizationCodeService
java.lang.Object
io.meeds.deeds.common.service.AuthorizationCodeService
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckValidity(String key, int code) Checks a code validity for a designated key and throws an exception when any verification condition hasn't been met.voidgenerateCode(String key, String email, Object data, String clientIp) Generates a new Verification Code for a designated key and with protecting a data that will be retrieved only after providing a valid code.voidinit()validateAndGetData(String key, int code) Validate the entered code for a designated key and return its associated protected data if valid.
-
Constructor Details
-
AuthorizationCodeService
- Throws:
NoSuchAlgorithmException
-
-
Method Details
-
init
@PostConstruct public void init() -
generateCode
public void generateCode(String key, String email, Object data, String clientIp) throws IllegalAccessException Generates a new Verification Code for a designated key and with protecting a data that will be retrieved only after providing a valid code. The generated code will be held for the designated key until 2 hours at maximum (default value of code valid time). At the period of code valid time, when the user checks more than 'meeds.authorizationCode.maxCodeVerification', then an exception is raised. Same thing, when the user attempts to generate a code more than 'meeds.authorizationCode.maxCodeSending' at the period of code validity, an exception is raised as well to limit the number of emails that a user can send.- Parameters:
key- A key to designate the protected data resource with codeemail- email to send to to verify access to data objectdata- data to cache and protect by email code verification mechanism- Throws:
IllegalAccessException- when maximum code verification sending is reached or maximum code verification has been reached
-
checkValidity
Checks a code validity for a designated key and throws an exception when any verification condition hasn't been met.- Parameters:
key- A key to designate the protected data resource with codecode- the verification code sent by email to protect access to data object- Throws:
IllegalAccessException- when the maximum verification checks has been reached or when the code isn' valid
-
validateAndGetData
Validate the entered code for a designated key and return its associated protected data if valid.- Parameters:
key- A key to designate the protected data resource with codecode- the verification code sent by email to protect access to data object- Returns:
- the protected data object if the provided code is valid
- Throws:
IllegalAccessException- when the maximum verification checks has been reached or when the code isn' valid
-