Package org.dspace.eperson
Class AccountServiceImpl
java.lang.Object
org.dspace.eperson.AccountServiceImpl
- All Implemented Interfaces:
AccountService
Methods for handling registration by email and forgotten passwords. When
someone registers as a user, or forgets their password, the
sendRegistrationInfo or sendForgotPasswordInfo methods can be used to send an
email to the user. The email contains a special token, a long string which is
randomly generated and thus hard to guess. When the user presents the token
back to the system, the AccountManager can use the token to determine the
identity of the eperson.
*NEW* now ignores expiration dates so that tokens never expire
- Version:
- $Revision$
- Author:
- Peter Breton
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteToken(Context context, String token) Delete token.booleanexistsAccountFor(Context context, String token) Checks if exists an account related to the token providedbooleanexistsAccountWithEmail(Context context, String email) Checks if exists an account related to the email providedprotected voidfillAndSendEmail(String email, String emailFilename, String specialLink) This method fills out the given email with all the fields and sends out the email.protected voidfillAndSendEmail(Context context, String email, boolean isRegister, RegistrationData rd) Send a DSpace message to the given email address.Return the e-mail address referred to by a token, or null if email address can't be found ignores expiration of tokengetEPerson(Context context, String token) Return the EPerson corresponding to token, where token was emailed to the person by either the sendRegistrationInfo or sendForgotPasswordInfo methods.getUpdateActions(Context context, EPerson eperson, RegistrationData registrationData) This methods tries to fullfill missing values inside theEPersonby taking them directly from theRegistrationData.booleanisTokenValidForCreation(RegistrationData registrationData) Checks if theRegistrationData.tokenis valid.mergeField(String field, RegistrationData registrationData) This method returns a Consumer that will override a givenMetadataValueof theEPersonby taking that directly from theRegistrationData.Merge registration data with an existing EPerson or create a new one.protected BiConsumer<RegistrationData,EPerson> mergeRegistrationMetadata(String field) This method returns aBiConsumerthat can be evaluated on anyRegistrationDataandEPersonin order to replace the value of the metadatafieldplaced on theEPersonby taking the value directly from theRegistrationData.renewRegistrationForEmail(Context context, RegistrationDataPatch registrationDataPatch) This method creates a fresh newRegistrationDatabased on theRegistrationDataPatchrequested by a given user.voidsendForgotPasswordInfo(Context context, String email) Email forgot password info to the given email address.protected RegistrationDatasendInfo(Context context, String email, RegistrationTypeEnum type, boolean send) THIS IS AN INTERNAL METHOD.protected voidsendRegistationLinkByEmail(Context context, RegistrationData rd) Fills out a given email template obtained starting from theRegistrationTypeEnum.voidsendRegistrationInfo(Context context, String email) Email registration info to the given email address.protected voidupdateValuesFromRegistration(Context context, EPerson eperson, RegistrationData registrationData, List<String> overrides) Updates Eperson using the providedRegistrationData.
Tries to replacemetadataalready set inside theEPersonwith the ones listed inside theoverridesfield by taking the value from theRegistrationData.
-
Field Details
-
ePersonService
-
registrationDataService
-
-
Constructor Details
-
AccountServiceImpl
protected AccountServiceImpl()
-
-
Method Details
-
sendRegistrationInfo
public void sendRegistrationInfo(Context context, String email) throws SQLException, IOException, jakarta.mail.MessagingException, AuthorizeException Email registration info to the given email address. Potential error conditions:- Cannot create registration data in database (throws SQLException).
- Error sending email (throws MessagingException).
- Error reading email template (throws IOException).
- Authorization error (throws AuthorizeException).
- Specified by:
sendRegistrationInfoin interfaceAccountService- Parameters:
context- DSpace contextemail- Email address to send the registration email to- Throws:
SQLException- passed through.IOException- passed through.jakarta.mail.MessagingException- passed through.AuthorizeException- passed through.
-
sendForgotPasswordInfo
public void sendForgotPasswordInfo(Context context, String email) throws SQLException, IOException, jakarta.mail.MessagingException, AuthorizeException Email forgot password info to the given email address. Potential error conditions:- No EPerson with that email (returns null).
- Cannot create registration data in database (throws SQLException).
- Error sending email (throws MessagingException).
- Error reading email template (throws IOException).
- Authorization error (throws AuthorizeException).
- Specified by:
sendForgotPasswordInfoin interfaceAccountService- Parameters:
context- DSpace contextemail- Email address to send the forgot-password email to- Throws:
SQLException- passed through.IOException- passed through.jakarta.mail.MessagingException- passed through.AuthorizeException- passed through.
-
existsAccountFor
public boolean existsAccountFor(Context context, String token) throws SQLException, AuthorizeException Checks if exists an account related to the token provided- Specified by:
existsAccountForin interfaceAccountService- Parameters:
context- DSpace contexttoken- Account token- Returns:
- true if exists, false otherwise
- Throws:
SQLExceptionAuthorizeException
-
existsAccountWithEmail
Description copied from interface:AccountServiceChecks if exists an account related to the email provided- Specified by:
existsAccountWithEmailin interfaceAccountService- Parameters:
context- DSpace contextemail- String email to search for- Returns:
- true if exists, false otherwise
- Throws:
SQLException
-
getEPerson
Return the EPerson corresponding to token, where token was emailed to the person by either the sendRegistrationInfo or sendForgotPasswordInfo methods.
If the token is not found return null.
- Specified by:
getEPersonin interfaceAccountService- Parameters:
context- DSpace contexttoken- Account token- Returns:
- The EPerson corresponding to token, or null.
- Throws:
SQLException- If the token or eperson cannot be retrieved from the database.AuthorizeException- passed through.
-
getEmail
Return the e-mail address referred to by a token, or null if email address can't be found ignores expiration of token- Specified by:
getEmailin interfaceAccountService- Parameters:
context- DSpace contexttoken- Account token- Returns:
- The email address corresponding to token, or null.
- Throws:
SQLException- passed through.
-
deleteToken
Delete token.- Specified by:
deleteTokenin interfaceAccountService- Parameters:
context- DSpace contexttoken- The token to delete- Throws:
SQLException- If a database error occurs
-
mergeRegistration
public EPerson mergeRegistration(Context context, UUID personId, String token, List<String> overrides) throws AuthorizeException, SQLException Description copied from interface:AccountServiceMerge registration data with an existing EPerson or create a new one.- Specified by:
mergeRegistrationin interfaceAccountService- Parameters:
context- DSpace contextpersonId- The ID of the EPerson to merge with or createtoken- The token to use for registration dataoverrides- List of fields to override in the EPerson- Returns:
- The merged or created EPerson
- Throws:
AuthorizeException- If the user is not authorized to perform the actionSQLException- If a database error occurs
-
renewRegistrationForEmail
public RegistrationData renewRegistrationForEmail(Context context, RegistrationDataPatch registrationDataPatch) throws AuthorizeException Description copied from interface:AccountServiceThis method creates a fresh newRegistrationDatabased on theRegistrationDataPatchrequested by a given user.- Specified by:
renewRegistrationForEmailin interfaceAccountService- Parameters:
context- - The DSapce ContextregistrationDataPatch- - Details of the patch request coming from the Controller- Returns:
- a newly created
RegistrationData - Throws:
AuthorizeException
-
isTokenValidForCreation
Description copied from interface:AccountServiceChecks if theRegistrationData.tokenis valid.- Specified by:
isTokenValidForCreationin interfaceAccountService- Parameters:
registrationData- that will be checked- Returns:
- true if valid, false otherwise
-
updateValuesFromRegistration
protected void updateValuesFromRegistration(Context context, EPerson eperson, RegistrationData registrationData, List<String> overrides) Updates Eperson using the providedRegistrationData.
Tries to replacemetadataalready set inside theEPersonwith the ones listed inside theoverridesfield by taking the value from theRegistrationData.
Updates the empty values inside theEPersonby taking them directly from theRegistrationData, according to the methodgetUpdateActions(Context, EPerson, RegistrationData)- Parameters:
context- The DSpace contexteperson- The EPerson that should be updatedregistrationData- The RegistrationData related to that EPersonoverrides- List of metadata that will be overwritten inside the EPerson
-
getUpdateActions
protected Stream<Consumer<EPerson>> getUpdateActions(Context context, EPerson eperson, RegistrationData registrationData) This methods tries to fullfill missing values inside theEPersonby taking them directly from theRegistrationData.
Returns aStreamof consumers that will be evaluated on anEPerson, this stream contains the following actions:- Copies
netIdandemailto theEPerson - Copies any
RegistrationData.metadatainsideDSpaceObject.metadataif isn't already set.
- Parameters:
context- DSpace contexteperson- EPerson that will be evaluatedregistrationData- RegistrationData used as a base to copy value from.- Returns:
- a stream of consumers to be evaluated on EPerson.
- Copies
-
mergeField
This method returns a Consumer that will override a givenMetadataValueof theEPersonby taking that directly from theRegistrationData.- Parameters:
field- The metadatafieldregistrationData- The RegistrationData where the metadata wil be taken- Returns:
- a Consumer of the person that will replace that field
-
mergeRegistrationMetadata
This method returns aBiConsumerthat can be evaluated on anyRegistrationDataandEPersonin order to replace the value of the metadatafieldplaced on theEPersonby taking the value directly from theRegistrationData.- Parameters:
field- The metadata that will be overwritten inside theEPerson- Returns:
- a BiConsumer
-
sendInfo
protected RegistrationData sendInfo(Context context, String email, RegistrationTypeEnum type, boolean send) throws SQLException, IOException, jakarta.mail.MessagingException, AuthorizeException THIS IS AN INTERNAL METHOD. THE SEND PARAMETER ALLOWS IT TO BE USED FOR TESTING PURPOSES. Send an info to the EPerson with the given email address. If isRegister is TRUE, this is registration email; otherwise, it is forgot-password email. If send is TRUE, the email is sent; otherwise it is skipped. Potential error conditions:- Parameters:
context- DSpace contextemail- Email address to send the forgot-password email totype- Type of registrationRegistrationTypeEnumsend- If true, send email; otherwise do not send any email- Returns:
- null if no EPerson with that email found
- Throws:
SQLException- Cannot create registration data in databasejakarta.mail.MessagingException- Error sending emailIOException- Error reading email templateAuthorizeException- Authorization error
-
fillAndSendEmail
protected void fillAndSendEmail(Context context, String email, boolean isRegister, RegistrationData rd) throws jakarta.mail.MessagingException, IOException, SQLException Send a DSpace message to the given email address. If isRegister istrue, this is registration email; otherwise, it is a forgot-password email.- Parameters:
context- The relevant DSpace Context.email- The email address to mail toisRegister- If true, this is registration email; otherwise it is forgot-password email.rd- The RDBMS row representing the registration data.- Throws:
jakarta.mail.MessagingException- If an error occurs while sending emailIOException- A general class of exceptions produced by failed or interrupted I/O operations.SQLException- An exception that provides information on a database access error or other errors.
-
sendRegistationLinkByEmail
protected void sendRegistationLinkByEmail(Context context, RegistrationData rd) throws jakarta.mail.MessagingException, IOException Fills out a given email template obtained starting from theRegistrationTypeEnum.- Parameters:
context- The DSpace Contextrd- The RegistrationData that will be used as a registration.- Throws:
jakarta.mail.MessagingExceptionIOException
-
fillAndSendEmail
protected void fillAndSendEmail(String email, String emailFilename, String specialLink) throws IOException, jakarta.mail.MessagingException This method fills out the given email with all the fields and sends out the email.- Parameters:
email- - The recipientemailFilename- The name of the emailspecialLink- - The link that will be set inside the email- Throws:
IOExceptionjakarta.mail.MessagingException
-