Class AccountServiceImpl

java.lang.Object
org.dspace.eperson.AccountServiceImpl
All Implemented Interfaces:
AccountService

public class AccountServiceImpl extends Object implements 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 Details

  • 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:
      sendRegistrationInfo in interface AccountService
      Parameters:
      context - DSpace context
      email - 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:
      sendForgotPasswordInfo in interface AccountService
      Parameters:
      context - DSpace context
      email - 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:
      existsAccountFor in interface AccountService
      Parameters:
      context - DSpace context
      token - Account token
      Returns:
      true if exists, false otherwise
      Throws:
      SQLException
      AuthorizeException
    • existsAccountWithEmail

      public boolean existsAccountWithEmail(Context context, String email) throws SQLException
      Description copied from interface: AccountService
      Checks if exists an account related to the email provided
      Specified by:
      existsAccountWithEmail in interface AccountService
      Parameters:
      context - DSpace context
      email - String email to search for
      Returns:
      true if exists, false otherwise
      Throws:
      SQLException
    • getEPerson

      public EPerson getEPerson(Context context, String token) throws SQLException, AuthorizeException

      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:
      getEPerson in interface AccountService
      Parameters:
      context - DSpace context
      token - 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

      public String getEmail(Context context, String token) throws SQLException
      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:
      getEmail in interface AccountService
      Parameters:
      context - DSpace context
      token - Account token
      Returns:
      The email address corresponding to token, or null.
      Throws:
      SQLException - passed through.
    • deleteToken

      public void deleteToken(Context context, String token) throws SQLException
      Delete token.
      Specified by:
      deleteToken in interface AccountService
      Parameters:
      context - DSpace context
      token - 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: AccountService
      Merge registration data with an existing EPerson or create a new one.
      Specified by:
      mergeRegistration in interface AccountService
      Parameters:
      context - DSpace context
      personId - The ID of the EPerson to merge with or create
      token - The token to use for registration data
      overrides - 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 action
      SQLException - If a database error occurs
    • renewRegistrationForEmail

      public RegistrationData renewRegistrationForEmail(Context context, RegistrationDataPatch registrationDataPatch) throws AuthorizeException
      Description copied from interface: AccountService
      This method creates a fresh new RegistrationData based on the RegistrationDataPatch requested by a given user.
      Specified by:
      renewRegistrationForEmail in interface AccountService
      Parameters:
      context - - The DSapce Context
      registrationDataPatch - - Details of the patch request coming from the Controller
      Returns:
      a newly created RegistrationData
      Throws:
      AuthorizeException
    • isTokenValidForCreation

      public boolean isTokenValidForCreation(RegistrationData registrationData)
      Description copied from interface: AccountService
      Checks if the RegistrationData.token is valid.
      Specified by:
      isTokenValidForCreation in interface AccountService
      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 provided RegistrationData.
      Tries to replace metadata already set inside the EPerson with the ones listed inside the overrides field by taking the value from the RegistrationData.
      Updates the empty values inside the EPerson by taking them directly from the RegistrationData, according to the method getUpdateActions(Context, EPerson, RegistrationData)
      Parameters:
      context - The DSpace context
      eperson - The EPerson that should be updated
      registrationData - The RegistrationData related to that EPerson
      overrides - 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 the EPerson by taking them directly from the RegistrationData.
      Returns a Stream of consumers that will be evaluated on an EPerson, this stream contains the following actions:
      • Copies netId and email to the EPerson
      • Copies any RegistrationData.metadata inside DSpaceObject.metadata if isn't already set.
      Parameters:
      context - DSpace context
      eperson - EPerson that will be evaluated
      registrationData - RegistrationData used as a base to copy value from.
      Returns:
      a stream of consumers to be evaluated on EPerson.
    • mergeField

      protected Consumer<EPerson> mergeField(String field, RegistrationData registrationData)
      This method returns a Consumer that will override a given MetadataValue of the EPerson by taking that directly from the RegistrationData.
      Parameters:
      field - The metadatafield
      registrationData - The RegistrationData where the metadata wil be taken
      Returns:
      a Consumer of the person that will replace that field
    • mergeRegistrationMetadata

      protected BiConsumer<RegistrationData,EPerson> mergeRegistrationMetadata(String field)
      This method returns a BiConsumer that can be evaluated on any RegistrationData and EPerson in order to replace the value of the metadata field placed on the EPerson by taking the value directly from the RegistrationData.
      Parameters:
      field - The metadata that will be overwritten inside the EPerson
      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 context
      email - Email address to send the forgot-password email to
      type - Type of registration RegistrationTypeEnum
      send - 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 database
      jakarta.mail.MessagingException - Error sending email
      IOException - Error reading email template
      AuthorizeException - 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 is true, this is registration email; otherwise, it is a forgot-password email.
      Parameters:
      context - The relevant DSpace Context.
      email - The email address to mail to
      isRegister - 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 email
      IOException - 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 the RegistrationTypeEnum.
      Parameters:
      context - The DSpace Context
      rd - The RegistrationData that will be used as a registration.
      Throws:
      jakarta.mail.MessagingException
      IOException
    • 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 recipient
      emailFilename - The name of the email
      specialLink - - The link that will be set inside the email
      Throws:
      IOException
      jakarta.mail.MessagingException