Class ProfileServiceRestClient

java.lang.Object
org.craftercms.commons.rest.AbstractRestClientBase
org.craftercms.profile.services.impl.AbstractProfileRestClientBase
org.craftercms.profile.services.impl.ProfileServiceRestClient
All Implemented Interfaces:
ProfileService

public class ProfileServiceRestClient extends AbstractProfileRestClientBase implements ProfileService
REST client implementation of ProfileService.
Author:
avasquez
  • Field Details

    • profileListTypeRef

      public static final org.springframework.core.ParameterizedTypeReference<List<Profile>> profileListTypeRef
    • byteArrayTypeRef

      public static final org.springframework.core.ParameterizedTypeReference<byte[]> byteArrayTypeRef
    • profileAttachmentListTypeRef

      public static final org.springframework.core.ParameterizedTypeReference<List<ProfileAttachment>> profileAttachmentListTypeRef
    • ERROR_KEY_ATTRIBUTES_SERIALIZATION_ERROR

      public static final String ERROR_KEY_ATTRIBUTES_SERIALIZATION_ERROR
      See Also:
    • ERROR_KEY_INVALID_URI_ERROR

      public static final String ERROR_KEY_INVALID_URI_ERROR
      See Also:
    • ERROR_KEY_TMP_COPY_FAILED

      public static final String ERROR_KEY_TMP_COPY_FAILED
      See Also:
  • Constructor Details

    • ProfileServiceRestClient

      public ProfileServiceRestClient(String baseUrl, org.springframework.web.client.RestTemplate restTemplate, AccessTokenIdResolver accessTokenIdResolver, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • createProfile

      public Profile createProfile(String tenantName, String username, String password, String email, boolean enabled, Set<String> roles, Map<String,Object> attributes, String verificationUrl) throws ProfileException
      Description copied from interface: ProfileService
      Creates a new profile for a specific tenant name.
      Specified by:
      createProfile in interface ProfileService
      Parameters:
      tenantName - the name of the tenant to add the profile to
      username - the profile's username
      password - the profile's password
      email - the profile's email
      enabled - if the profile should be enabled or not
      roles - the profile's roles (optional)
      attributes - the additional attributes to add to the profile (optional)
      verificationUrl - the URL (sans token) the user needs to go in case it needs to verify the created profile (verification depends on tenant) (optional).
      Returns:
      the newly created profile
      Throws:
      ProfileException
    • updateProfile

      public Profile updateProfile(String profileId, String username, String password, String email, Boolean enabled, Set<String> roles, Map<String,Object> attributes, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Updates the profile's info.
      Specified by:
      updateProfile in interface ProfileService
      Parameters:
      profileId - the profile's ID
      username - the new username for the profile, or null if it shouldn't be updated
      password - the new password for the profile, or null if it shouldn't be updated
      email - the new email for the profile, or null if it shouldn't be updated
      enabled - if the profile should be enabled or not, or null if it shouldn't be updated
      roles - the new roles for the profile, or null if the roles shouldn't be updated
      attributes - the attributes to update, or null if no attribute should be updated
      attributesToReturn - the names of the attributes to return (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • verifyProfile

      public Profile verifyProfile(String verificationTokenId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Sets the profile as verified if the verification token is valid.
      Specified by:
      verifyProfile in interface ProfileService
      Parameters:
      verificationTokenId - the verification token ID
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile associated to the token
      Throws:
      ProfileException
    • enableProfile

      public Profile enableProfile(String profileId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Enables a profile.
      Specified by:
      enableProfile in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • disableProfile

      public Profile disableProfile(String profileId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Disables a profile.
      Specified by:
      disableProfile in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • addRoles

      public Profile addRoles(String profileId, Collection<String> roles, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Assigns roles to the profile.
      Specified by:
      addRoles in interface ProfileService
      Parameters:
      profileId - the profile's ID
      roles - the roles to assign
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • removeRoles

      public Profile removeRoles(String profileId, Collection<String> roles, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Removes assigned roles from a profile.
      Specified by:
      removeRoles in interface ProfileService
      Parameters:
      profileId - the profile's ID
      roles - the roles to remove
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • getAttributes

      public Map<String,Object> getAttributes(String profileId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the attributes of a profile.
      Specified by:
      getAttributes in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributesToReturn - the names of the attributes to return (null to return all attributes)
      Returns:
      the profile's attributes
      Throws:
      ProfileException
    • updateAttributes

      public Profile updateAttributes(String profileId, Map<String,Object> attributes, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Updates the attributes of a profile, by merging the specified attributes with the existing attributes.
      Specified by:
      updateAttributes in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributes - the new attributes
      attributesToReturn - the names of the attributes to return withe the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • removeAttributes

      public Profile removeAttributes(String profileId, Collection<String> attributeNames, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Removes a list of attributes of a profile.
      Specified by:
      removeAttributes in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributeNames - the names of the attributes to remove
      attributesToReturn - the names of the attributes to return withe the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • deleteProfile

      public void deleteProfile(String profileId) throws ProfileException
      Description copied from interface: ProfileService
      Deletes a profile.
      Specified by:
      deleteProfile in interface ProfileService
      Parameters:
      profileId - the profile's ID
      Throws:
      ProfileException
    • getProfileByQuery

      public Profile getProfileByQuery(String tenantName, String query, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the single profile that matches the specified query
      Specified by:
      getProfileByQuery in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      query - the Mongo query used to search for the profiles. Must not contain the $where operator, the tenant's name (already specified) or any non-readable attribute by the application
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the profile, or null if not found
      Throws:
      ProfileException
    • getProfile

      public Profile getProfile(String profileId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the profile for the specified ID.
      Specified by:
      getProfile in interface ProfileService
      Parameters:
      profileId - the profile's ID
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the profile, or null if not found
      Throws:
      ProfileException
    • getProfileByUsername

      public Profile getProfileByUsername(String tenantName, String username, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the user for the specified tenant and username
      Specified by:
      getProfileByUsername in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      username - the profile's username
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the profile, or null if not found
      Throws:
      ProfileException
    • getProfileByTicket

      public Profile getProfileByTicket(String ticketId, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the profile for the specified ticket.
      Specified by:
      getProfileByTicket in interface ProfileService
      Parameters:
      ticketId - the ID ticket of the authenticated profile
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the profile, or null if not found
      Throws:
      ProfileException
    • getProfileCount

      public long getProfileCount(String tenantName) throws ProfileException
      Description copied from interface: ProfileService
      Returns the number of profiles of the specified tenant.
      Specified by:
      getProfileCount in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      Returns:
      the number of profiles of the specified tenant
      Throws:
      ProfileException
    • getProfileCountByQuery

      public long getProfileCountByQuery(String tenantName, String query) throws ProfileException
      Description copied from interface: ProfileService
      Returns the number of profiles that match the query for the specified tenant.
      Specified by:
      getProfileCountByQuery in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      query - the Mongo query used to search for the profiles. Must not contain the $where operator, the tenant's name (already specified) or any non-readable attribute by the application
      Returns:
      the number of profiles of the specified tenant
      Throws:
      ProfileException
    • getProfilesByQuery

      public List<Profile> getProfilesByQuery(String tenantName, String query, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the profiles that match the specified query.
      Specified by:
      getProfilesByQuery in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      query - the Mongo query used to search for the profiles. Must not contain the $where operator, the tenant's name (already specified) or any non-readable attribute by the application
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      start - from the entire list of results, the position where the actual results should start (useful for pagination) (optional)
      count - the number of profiles to return (optional)
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the list of profiles found, or null if none match the query
      Throws:
      ProfileException
    • getProfilesByIds

      public List<Profile> getProfilesByIds(List<String> profileIds, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns a list of profiles for the specified list of IDs.
      Specified by:
      getProfilesByIds in interface ProfileService
      Parameters:
      profileIds - the IDs of the profiles to look for
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all attributes)
      Returns:
      the list of profiles (can be smaller than the list of ids if some where not found)
      Throws:
      ProfileException
    • getProfileRange

      public List<Profile> getProfileRange(String tenantName, String sortBy, SortOrder sortOrder, Integer start, Integer count, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns a range of profiles for the specified tenant.
      Specified by:
      getProfileRange in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      start - from the entire list of results, the position where the actual results should start (useful for pagination) (optional)
      count - the number of profiles to return (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all attributes)
      Returns:
      the list of profiles
      Throws:
      ProfileException
    • getProfilesByRole

      public List<Profile> getProfilesByRole(String tenantName, String role, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns a list of profiles for a specific role and tenant.
      Specified by:
      getProfilesByRole in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      role - the role's name
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all attributes)
      Returns:
      the list of profiles
      Throws:
      ProfileException
    • getProfilesByExistingAttribute

      public List<Profile> getProfilesByExistingAttribute(String tenantName, String attributeName, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the list of profiles that have the given attribute, with any value
      Specified by:
      getProfilesByExistingAttribute in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      attributeName - the name of the attribute profiles must have
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all attributes)
      Returns:
      the list of profiles
      Throws:
      ProfileException
    • getProfilesByAttributeValue

      public List<Profile> getProfilesByAttributeValue(String tenantName, String attributeName, String attributeValue, String sortBy, SortOrder sortOrder, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Returns the list of profiles that have the given attribute with the given value.
      Specified by:
      getProfilesByAttributeValue in interface ProfileService
      Parameters:
      tenantName - the tenant's name
      attributeName - the name of the attribute profiles must have
      attributeValue - the value of the attribute profiles must have
      sortBy - profile attribute to sort the list by (optional)
      sortOrder - the sort order (either ASC or DESC) (optional)
      attributesToReturn - the names of the attributes to return for each profile (null to return all attributes)
      Returns:
      the list of profiles
      Throws:
      ProfileException
    • resetPassword

      public Profile resetPassword(String profileId, String resetPasswordUrl, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Sends an email to the profile's user to indicate that the password needs to be reset.
      Specified by:
      resetPassword in interface ProfileService
      Parameters:
      profileId - the profile's ID
      resetPasswordUrl - the base URL to use to build the final URL the profile will use to reset their password.
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • changePassword

      public Profile changePassword(String resetTokenId, String newPassword, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Changes a profile's password, after a reset request has been sent.
      Specified by:
      changePassword in interface ProfileService
      Parameters:
      resetTokenId - the reset token ID
      newPassword - the new password
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • createVerificationToken

      public VerificationToken createVerificationToken(String profileId) throws ProfileException
      Description copied from interface: ProfileService
      Creates a token that can be sent to the user in an email as a link. After the user clicks the link, the token then can be passed to ProfileService.verifyProfile(String, String...) or ProfileService.changePassword(String, String, String...) to verify that the user agrees.
      Specified by:
      createVerificationToken in interface ProfileService
      Parameters:
      profileId - the profile ID of the user that needs to be contacted
      Returns:
      the created token
      Throws:
      ProfileException
    • getVerificationToken

      public VerificationToken getVerificationToken(String tokenId) throws ProfileException
      Description copied from interface: ProfileService
      Returns the verification token that corresponds to the given ID.
      Specified by:
      getVerificationToken in interface ProfileService
      Parameters:
      tokenId - the token ID
      Returns:
      the verification token, or null if not found
      Throws:
      ProfileException
    • deleteVerificationToken

      public void deleteVerificationToken(String tokenId) throws ProfileException
      Description copied from interface: ProfileService
      Deletes a verification token when it's not needed anymore (not necessary to call if ProfileService.verifyProfile(String, String...) or ProfileService.changePassword(String, String, String...), since they already delete the token.
      Specified by:
      deleteVerificationToken in interface ProfileService
      Parameters:
      tokenId - the ID of the token to delete
      Throws:
      ProfileException
    • addProfileAttachment

      public ProfileAttachment addProfileAttachment(String profileId, String attachmentName, InputStream file) throws ProfileException
      Description copied from interface: ProfileService
      Saves a Profile Attachment
      Specified by:
      addProfileAttachment in interface ProfileService
      Parameters:
      profileId - Id of the profile owner of the attachment.
      attachmentName - File name of the Attachment;
      file - Actual File to be Attach.
      Returns:
      A Profile Attachment Contains all the information of the Actual Attachment (including the id);
      Throws:
      ProfileException - If attachment can not be saved;
    • getProfileAttachmentInformation

      public ProfileAttachment getProfileAttachmentInformation(String profileId, String attachmentId) throws ProfileException
      Description copied from interface: ProfileService
      Gets Profile attachment Information.
      Specified by:
      getProfileAttachmentInformation in interface ProfileService
      Parameters:
      profileId - Profile owner of the Attachment.
      attachmentId - Attachment Id.
      Returns:
      Null if Attachment Id does not exist or does not belong to the user.
      Throws:
      ProfileException - If Attachment cannot be found.
    • getProfileAttachment

      public InputStream getProfileAttachment(String attachmentId, String profileId) throws ProfileException
      Description copied from interface: ProfileService
      Given the Attachment Id and the Profile Id, gets the Actual Attachment.
      Specified by:
      getProfileAttachment in interface ProfileService
      Parameters:
      attachmentId - Attachment Id to get.
      profileId - Profile Owner of the Attachment.
      Returns:
      Null If Attachment Id does no exist or does not belong to the given profile. InputStream of the actual File.
      Throws:
      ProfileException - If unable to get the Attachment.
    • getProfileAttachments

      public List<ProfileAttachment> getProfileAttachments(String profileId) throws ProfileException
      Description copied from interface: ProfileService
      List all Attachments for the given profile.
      Specified by:
      getProfileAttachments in interface ProfileService
      Parameters:
      profileId - Profile to get all Attachments
      Returns:
      The List of attachments that the profile has ,never null.
      Throws:
      ProfileException - If unable to get Profile attachments.
    • serializeAttributes

      protected String serializeAttributes(Map<String,Object> attributes) throws ProfileException
      Throws:
      ProfileException
    • setLastFailedLogin

      public Profile setLastFailedLogin(String profileId, Date lastFailedLogin, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Sets the date of the last failed login for the profile.
      Specified by:
      setLastFailedLogin in interface ProfileService
      Parameters:
      profileId - the profile's ID
      lastFailedLogin - the date of the last failed login
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • setFailedLoginAttempts

      public Profile setFailedLoginAttempts(String profileId, int failedLoginAttempts, String... attributesToReturn) throws ProfileException
      Description copied from interface: ProfileService
      Sets the number of failed login attempts for the profile.
      Specified by:
      setFailedLoginAttempts in interface ProfileService
      Parameters:
      profileId - the profile's ID
      failedLoginAttempts - the number of failed login attempts
      attributesToReturn - the names of the attributes to return with the profile (null to return all attributes)
      Returns:
      the updated profile
      Throws:
      ProfileException
    • addQueryParams

      protected String addQueryParams(String url, org.springframework.util.MultiValueMap<String,String> params, boolean encodeValues)