Package org.cyclos.impl.users
Class UserValidationServiceImpl
- java.lang.Object
-
- org.cyclos.impl.AbstractServerComponent
-
- org.cyclos.impl.AbstractNetworkedServerComponent
-
- org.cyclos.impl.BaseServiceImpl
-
- org.cyclos.impl.users.UserValidationServiceImpl
-
- All Implemented Interfaces:
UserValidationServiceLocal,Service,UserValidationService
@Service public class UserValidationServiceImpl extends BaseServiceImpl implements UserValidationServiceLocal
Implementation forUserValidationServiceLocal
-
-
Field Summary
-
Fields inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
authHandler, conversionHandler, entityManagerHandler, groupsHandler, productsHandler, restBeanPropertyMapping, userLocatorHandler
-
Fields inherited from class org.cyclos.impl.AbstractServerComponent
accountHandler, configurationHandler, dataTranslationHandler, notificationHandler, transactionHandler, translationHandler
-
-
Constructor Summary
Constructors Constructor Description UserValidationServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNameValidations(Property name, BasicUserDTO dto)As the CRUD service forces a custom handling of the name property, this needs to be in a separate methodvoidaddRegistrationValidations(Validator validator, SimpleBasicUserRegistrationDTO dto, UserRegistration registration, BasicUser basicUser, UserValidationFields fields)Add common validations for registering a user or operatorvoidaddValidations(Validator validator, BasicUserDTO dto, BasicUser user, UserValidationFields fields)Add common validations for saving the profile of a user or operator.UserRegistrationResultbuildRegistrationResult(BasicUser user, Set<PasswordType> generatedPasswordTypes)Builds the registration result for the given user.booleancanViewProfile(BasicUser user)Returns true if the logged user can view the profile of the given user.
NOTE: Take into account that a user can be related to a user but not see its profile, e.g a user can relates to an operator of another user (through thePermission.USER_OPERATORS_PAY) but he can't view the operator profile.voidclearValidationKey(BasicUser user)Removes all user data related to a validation keyList<ProfileField>fillProfileFields(BasicUser user, AbstractViewProfileData data)Fills in the visible profile fields of the given user on the given view profile datavoidfillRegistrationData(SimpleBasicUserRegistrationData data, UserRegistration registration, BasicUser basicUser)Fills with common data for registering users or operatorsMap<PasswordType,String>finishActivation(BasicUser user)Generate the passwords and send the activation e-mail for the given userList<UserPrincipalData>getPrincipalsData(BasicUser basicUser, Channel channel)Returns a list ofUserPrincipalDatafor allPrincipalTypewhere the correspondingProfileFieldis enabled for the user.
Each element of the list contains:
ThePrincipalType. The principal asStringA list ofChannelVOwhere the principal type can be used to access the channel.BasicUsergetUserForForgotPassword(UserLocatorVO locator, String code)Returns the user in the current network with a forgot password request with the given codeBasicUsergetUserForValidationKey(ValidationKeyType type, String validationKey)Returns the user in the current network with the given validation keybooleanisEmailTaken(ConfigurationAccessor configuration, String email)Returns whether there's a non-removed user with this e-mail.booleanisMobileNumberTaken(ConfigurationAccessor configuration, String number)Returns whether there's a non-removed user with this mobile phone number.booleanisNameRequired(BasicUserDTO basicDto)Returns whether we should require the full name when saving the given userbooleanisUsernameTaken(ConfigurationAccessor configuration, String username)Returns whether there's a non-removed user with this username.voidmanuallyValidateEmailChange(UserLocatorVO locator)Makes a pending e-mail change as doneUserValidationResultmanuallyValidateRegistration(UserLocatorVO locator)Makes a pending user to be activevoidpersistAdditionalRegistrationData(BasicUser basicUser, SimpleBasicUserRegistrationDTO dto, List<ProfileField> editableFields)Persists additional data that is saved together with the user, such as phones or addresses<BU extends BasicUser>
BUpreProcessRegistration(SimpleBasicUserRegistrationDTO dto, UserRegistration registration)Returns a pre-populated user for persistingMap<PasswordType,String>processRegistration(BasicUser basicUser, SimpleBasicUserRegistrationDTO dto)Processes a user registration.protected voidregisterNetworkMappings(NetworkPathRegistry networkPathRegistry)Needs to be overridden by subclasses to register the path up to the networkvoidreindex(BasicUser user)Reindex the given user updating its custom field values according to the products and also its display.booleanrequiresEmailChangeValidation(BasicUser basicUser)Returns true if the system requires the user to validate the email upon email modificationvoidresendEmailChangeMail(UserLocatorVO locator)Re-sends the e-mail change e-mail to a uservoidresendRegistrationValidationMail(UserLocatorVO locator)Re-sends the validation mail to a pending uservoidsetEmailChangeValidation(BasicUser user, String originalEmail)Sets the user validation key for e-mail change confirmation, restores the original e-mail (saving the current e-mail in new email) and sends the e-mailList<OutboundSms>setForgotPasswordValidation(BasicUser user, SendMedium sendMedium)Sends the change forgotten password code by the given send medium.booleanshouldCheckConfirmationPassword(BasicUser user, CRUDOperation operation)Controls whether confirmation password should be checked for the given basic user and operation.DBQuery<?>uniqueEmailQuery(Network network, BasicUserDTO dto)Returns a query suited to check the e-mail uniqueness of the given uservoidupdateDisplay(BasicUser user)Updates display fields in the given user according to his/hers current configurationvoidupdateUserActivity(UserActivityType type)Updates user information status according to the given activityLongvalidateEmailChange(String validationKey)Validate an e-mail change for the given validation key, returning the affected user identifierUserValidationResultvalidateRegistration(String validationKey)Validate user registration which was pending e-mail verification, via a provided key-
Methods inherited from class org.cyclos.impl.BaseServiceImpl
initializeNetworkMappings
-
Methods inherited from class org.cyclos.impl.AbstractNetworkedServerComponent
canManage, checkManagesUser, checkPermission, checkRelatesToUser, checkValue, clearAlreadyValidated, getBaseEntityManagerHandler, getConfiguration, getLoggedBasicUser, getLoggedUser, getProducts, getTranslatedName, getTranslatedValue, hasPermission, hasValue, inSameNetwork, inSameNetworkOrGlobal, isAdmin, isAlreadyValidated, isBroker, isGlobalAdmin, isGlobalAdminInNetwork, isGuest, isLoggedIn, isMember, isMemberOnly, isNetworkAdmin, isOperator, isRelatedToUser, isSystem, isUserManager, isUserManagerOf, message, message, permission, permission, permissionOptionalValue, permissionOptionalValue, setAlreadyValidated, toDate, toDateTime, validate
-
Methods inherited from class org.cyclos.impl.AbstractServerComponent
dataTranslationProxy, dataTranslationProxy, delete, detach, doDataTranslationProxy, find, flush, from, getApplicationContext, getFormatter, getFormatter, getFormatter, getLogger, getRemoteAddress, getSessionData, mailContentBuilder, message, message, persist, processBatch, processBatch, refresh, remove, selectFrom, subQuery, update
-
-
-
-
Method Detail
-
addNameValidations
public void addNameValidations(Property name, BasicUserDTO dto) throws FrameworkException
Description copied from interface:UserValidationServiceLocalAs the CRUD service forces a custom handling of the name property, this needs to be in a separate method- Specified by:
addNameValidationsin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
addRegistrationValidations
public void addRegistrationValidations(Validator validator, SimpleBasicUserRegistrationDTO dto, UserRegistration registration, BasicUser basicUser, UserValidationFields fields)
Description copied from interface:UserValidationServiceLocalAdd common validations for registering a user or operator- Specified by:
addRegistrationValidationsin interfaceUserValidationServiceLocal
-
addValidations
public void addValidations(Validator validator, BasicUserDTO dto, BasicUser user, UserValidationFields fields)
Description copied from interface:UserValidationServiceLocalAdd common validations for saving the profile of a user or operator. PRE: in case of a new user registration the user parameter MUST have set the registration type.- Specified by:
addValidationsin interfaceUserValidationServiceLocal
-
buildRegistrationResult
public UserRegistrationResult buildRegistrationResult(BasicUser user, Set<PasswordType> generatedPasswordTypes)
Description copied from interface:UserValidationServiceLocalBuilds the registration result for the given user.- Specified by:
buildRegistrationResultin interfaceUserValidationServiceLocal- Parameters:
user- the already registered usergeneratedPasswordTypes- set of password types for which the passwords were generated.
-
canViewProfile
public boolean canViewProfile(BasicUser user)
Description copied from interface:UserValidationServiceLocalReturns true if the logged user can view the profile of the given user.
NOTE: Take into account that a user can be related to a user but not see its profile, e.g a user can relates to an operator of another user (through thePermission.USER_OPERATORS_PAY) but he can't view the operator profile.- Specified by:
canViewProfilein interfaceUserValidationServiceLocal
-
clearValidationKey
public void clearValidationKey(BasicUser user) throws FrameworkException
Description copied from interface:UserValidationServiceLocalRemoves all user data related to a validation key- Specified by:
clearValidationKeyin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
fillProfileFields
public List<ProfileField> fillProfileFields(BasicUser user, AbstractViewProfileData data)
Description copied from interface:UserValidationServiceLocalFills in the visible profile fields of the given user on the given view profile data- Specified by:
fillProfileFieldsin interfaceUserValidationServiceLocal
-
fillRegistrationData
public void fillRegistrationData(SimpleBasicUserRegistrationData data, UserRegistration registration, BasicUser basicUser)
Description copied from interface:UserValidationServiceLocalFills with common data for registering users or operators- Specified by:
fillRegistrationDatain interfaceUserValidationServiceLocal
-
finishActivation
public Map<PasswordType,String> finishActivation(BasicUser user)
Generate the passwords and send the activation e-mail for the given user- Specified by:
finishActivationin interfaceUserValidationServiceLocal
-
getPrincipalsData
public List<UserPrincipalData> getPrincipalsData(BasicUser basicUser, Channel channel)
Description copied from interface:UserValidationServiceLocalReturns a list ofUserPrincipalDatafor allPrincipalTypewhere the correspondingProfileFieldis enabled for the user.
Each element of the list contains:
- The
PrincipalType. - The principal as
String - A list of
ChannelVOwhere the principal type can be used to access the channel.
- Specified by:
getPrincipalsDatain interfaceUserValidationServiceLocalchannel- create the list for all principal types used to access the channel (if accessible). If null then uses all accessible channels for the given user to get the principals types.
- The
-
getUserForForgotPassword
public BasicUser getUserForForgotPassword(UserLocatorVO locator, String code) throws InvalidForgotPasswordCodeException
Description copied from interface:UserValidationServiceLocalReturns the user in the current network with a forgot password request with the given code- Specified by:
getUserForForgotPasswordin interfaceUserValidationServiceLocal- Throws:
InvalidForgotPasswordCodeException
-
getUserForValidationKey
public BasicUser getUserForValidationKey(ValidationKeyType type, String validationKey) throws FrameworkException
Description copied from interface:UserValidationServiceLocalReturns the user in the current network with the given validation key- Specified by:
getUserForValidationKeyin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
isEmailTaken
public boolean isEmailTaken(ConfigurationAccessor configuration, String email)
Description copied from interface:UserValidationServiceLocalReturns whether there's a non-removed user with this e-mail. Returns false if e-mail is not marked as unique.- Specified by:
isEmailTakenin interfaceUserValidationServiceLocal
-
isMobileNumberTaken
public boolean isMobileNumberTaken(ConfigurationAccessor configuration, String number)
Description copied from interface:UserValidationServiceLocalReturns whether there's a non-removed user with this mobile phone number. Returns false if mobile phone is not marked as unique.- Specified by:
isMobileNumberTakenin interfaceUserValidationServiceLocal
-
isNameRequired
public boolean isNameRequired(BasicUserDTO basicDto) throws FrameworkException
Description copied from interface:UserValidationServiceLocalReturns whether we should require the full name when saving the given user- Specified by:
isNameRequiredin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
isUsernameTaken
public boolean isUsernameTaken(ConfigurationAccessor configuration, String username)
Description copied from interface:UserValidationServiceLocalReturns whether there's a non-removed user with this username. Returns false if username is generated.- Specified by:
isUsernameTakenin interfaceUserValidationServiceLocal
-
manuallyValidateEmailChange
public void manuallyValidateEmailChange(UserLocatorVO locator) throws FrameworkException
Description copied from interface:UserValidationServiceMakes a pending e-mail change as done- Specified by:
manuallyValidateEmailChangein interfaceUserValidationService- Throws:
FrameworkException
-
manuallyValidateRegistration
public UserValidationResult manuallyValidateRegistration(UserLocatorVO locator) throws FrameworkException
Description copied from interface:UserValidationServiceMakes a pending user to be active- Specified by:
manuallyValidateRegistrationin interfaceUserValidationService- Throws:
FrameworkException
-
persistAdditionalRegistrationData
public void persistAdditionalRegistrationData(BasicUser basicUser, SimpleBasicUserRegistrationDTO dto, List<ProfileField> editableFields)
Description copied from interface:UserValidationServiceLocalPersists additional data that is saved together with the user, such as phones or addresses- Specified by:
persistAdditionalRegistrationDatain interfaceUserValidationServiceLocal
-
preProcessRegistration
public <BU extends BasicUser> BU preProcessRegistration(SimpleBasicUserRegistrationDTO dto, UserRegistration registration) throws FrameworkException
Description copied from interface:UserValidationServiceLocalReturns a pre-populated user for persisting- Specified by:
preProcessRegistrationin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
processRegistration
public Map<PasswordType,String> processRegistration(BasicUser basicUser, SimpleBasicUserRegistrationDTO dto)
Description copied from interface:UserValidationServiceLocalProcesses a user registration. If the user must validate the e-mail then sets the user validation key for user registration confirmation and sends the e-mail. Otherwise, if the dto is anBasicUserRegistrationDTOthen generates the passwords marked at registration and sends the activation or pending e-mail according to the user's status.- Specified by:
processRegistrationin interfaceUserValidationServiceLocal- Parameters:
basicUser- the user to be registered, it must have set theUserRegistration- Returns:
- a
Mapwith the generated passwords only if the user doesn't need to validate the e-mail. Otherwise returns an empty map.
-
reindex
public void reindex(BasicUser user) throws FrameworkException
Description copied from interface:UserValidationServiceLocalReindex the given user updating its custom field values according to the products and also its display.- Specified by:
reindexin interfaceUserValidationServiceLocal- Throws:
FrameworkException
-
requiresEmailChangeValidation
public boolean requiresEmailChangeValidation(BasicUser basicUser)
Description copied from interface:UserValidationServiceLocalReturns true if the system requires the user to validate the email upon email modification- Specified by:
requiresEmailChangeValidationin interfaceUserValidationServiceLocal
-
resendEmailChangeMail
public void resendEmailChangeMail(UserLocatorVO locator) throws FrameworkException
Description copied from interface:UserValidationServiceRe-sends the e-mail change e-mail to a user- Specified by:
resendEmailChangeMailin interfaceUserValidationService- Throws:
FrameworkException
-
resendRegistrationValidationMail
public void resendRegistrationValidationMail(UserLocatorVO locator)
Description copied from interface:UserValidationServiceRe-sends the validation mail to a pending user- Specified by:
resendRegistrationValidationMailin interfaceUserValidationService
-
setEmailChangeValidation
public void setEmailChangeValidation(BasicUser user, String originalEmail)
Description copied from interface:UserValidationServiceLocalSets the user validation key for e-mail change confirmation, restores the original e-mail (saving the current e-mail in new email) and sends the e-mail- Specified by:
setEmailChangeValidationin interfaceUserValidationServiceLocal
-
setForgotPasswordValidation
public List<OutboundSms> setForgotPasswordValidation(BasicUser user, SendMedium sendMedium)
Description copied from interface:UserValidationServiceLocalSends the change forgotten password code by the given send medium.- Specified by:
setForgotPasswordValidationin interfaceUserValidationServiceLocal
-
shouldCheckConfirmationPassword
public boolean shouldCheckConfirmationPassword(BasicUser user, CRUDOperation operation)
Description copied from interface:UserValidationServiceLocalControls whether confirmation password should be checked for the given basic user and operation.- Specified by:
shouldCheckConfirmationPasswordin interfaceUserValidationServiceLocal
-
uniqueEmailQuery
public DBQuery<?> uniqueEmailQuery(Network network, BasicUserDTO dto)
Returns a query suited to check the e-mail uniqueness of the given user- Specified by:
uniqueEmailQueryin interfaceUserValidationServiceLocal
-
updateDisplay
public void updateDisplay(BasicUser user)
Description copied from interface:UserValidationServiceLocalUpdates display fields in the given user according to his/hers current configuration- Specified by:
updateDisplayin interfaceUserValidationServiceLocal
-
updateUserActivity
public void updateUserActivity(UserActivityType type)
Description copied from interface:UserValidationServiceUpdates user information status according to the given activity- Specified by:
updateUserActivityin interfaceUserValidationService
-
validateEmailChange
public Long validateEmailChange(String validationKey) throws FrameworkException
Description copied from interface:UserValidationServiceValidate an e-mail change for the given validation key, returning the affected user identifier- Specified by:
validateEmailChangein interfaceUserValidationService- Throws:
FrameworkException
-
validateRegistration
public UserValidationResult validateRegistration(String validationKey)
Description copied from interface:UserValidationServiceValidate user registration which was pending e-mail verification, via a provided key- Specified by:
validateRegistrationin interfaceUserValidationService
-
registerNetworkMappings
protected void registerNetworkMappings(NetworkPathRegistry networkPathRegistry)
Description copied from class:BaseServiceImplNeeds to be overridden by subclasses to register the path up to the network- Specified by:
registerNetworkMappingsin classBaseServiceImpl
-
-