private UserAccount createUserAccount ( final RegisterUserRequest serviceRequest ) { final ApplicationConfiguration registeredUsersGetAdminConfig = applicationConfigurationService . checkValueOrLoadDefault ( "Registered User All get Role Admin" , "Registered User All get Role Admin" , ConfigurationGroup . AUTHORIZATION , RegisterUserService . class . getSimpleName ( ) , "Register User Service" , "Responsible for create of useraccounts" , "registered.users.get.admin" , "true" ) ; final UserAccount userAccount = new UserAccount ( ) ; userAccount . setCountry ( serviceRequest . getCountry ( ) ) ; userAccount . setEmail ( serviceRequest . getEmail ( ) ) ; userAccount . setUsername ( serviceRequest . getUsername ( ) ) ; userAccount . setUserId ( UUID . randomUUID ( ) . toString ( ) ) ; userAccount . setUserpassword ( passwordEncoder . encode ( userAccount . getUserId ( ) + ".uuid" + serviceRequest . getUserpassword ( ) ) ) ; userAccount . setNumberOfVisits ( 1 ) ; if ( serviceRequest . getUserType ( ) == null ) { userAccount . setUserType ( UserType . PRIVATE ) ; } else { userAccount . setUserType ( serviceRequest . getUserType ( ) ) ; } userAccount . setUserEmailStatus ( UserEmailStatus . UNKNOWN ) ; userAccount . setUserLockStatus ( UserLockStatus . UNLOCKED ) ; userAccount . setCreatedDate ( new Date ( ) ) ; getUserDAO ( ) . persist ( userAccount ) ; final Collection < SimpleGrantedAuthority > authorities = new ArrayList <> ( ) ; if ( "true" . equals ( registeredUsersGetAdminConfig . getPropertyValue ( ) ) ) { userAccount . setUserRole ( UserRole . ADMIN ) ; authorities . add ( new SimpleGrantedAuthority ( "ROLE_ADMIN" ) ) ; } else { userAccount . setUserRole ( UserRole . USER ) ; authorities . add ( new SimpleGrantedAuthority ( "ROLE_USER" ) ) ; } SecurityContextHolder . getContext ( ) . setAuthentication ( new UsernamePasswordAuthenticationToken ( userAccount . getUserId ( ) , "n/a" , authorities ) ) ; return userAccount ; }
Creates the user account .