diff --git a/src/main/kotlin/com/faforever/userservice/backend/domain/DomainBlacklist.kt b/src/main/kotlin/com/faforever/userservice/backend/domain/DomainBlacklist.kt index 150230da..c17d2c35 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/domain/DomainBlacklist.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/domain/DomainBlacklist.kt @@ -8,7 +8,7 @@ import jakarta.persistence.Id @Entity(name = "email_domain_blacklist") data class DomainBlacklist( @Id - val domain: String + val domain: String, ) @ApplicationScoped diff --git a/src/main/kotlin/com/faforever/userservice/backend/domain/NameRecord.kt b/src/main/kotlin/com/faforever/userservice/backend/domain/NameRecord.kt index b06ea3bc..9c7aeb60 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/domain/NameRecord.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/domain/NameRecord.kt @@ -39,6 +39,6 @@ class NameRecordRepository : PanacheRepositoryBase { "previousName = ?1 and changeTime >= ?2 and userId != ?3", previousName, changeTime, - userId + userId, ) > 0 } diff --git a/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt b/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt index 02fd9b8f..233e2592 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/email/EmailService.kt @@ -4,15 +4,12 @@ import com.faforever.userservice.backend.domain.DomainBlacklistRepository import com.faforever.userservice.backend.domain.User import com.faforever.userservice.backend.domain.UserRepository import com.faforever.userservice.config.FafProperties -import io.quarkus.mailer.Mail -import io.quarkus.mailer.Mailer import jakarta.enterprise.context.ApplicationScoped import jakarta.transaction.Transactional import org.slf4j.Logger import org.slf4j.LoggerFactory import java.util.regex.Pattern - @ApplicationScoped class EmailService( private val userRepository: UserRepository, @@ -30,7 +27,7 @@ class EmailService( enum class ValidationResult { VALID, INVALID, - BLACKLISTED + BLACKLISTED, } fun changeUserEmail(newEmail: String, user: User) { @@ -49,7 +46,7 @@ class EmailService( !EMAIL_PATTERN.matcher(email).matches() -> ValidationResult.INVALID domainBlacklistRepository.existsByDomain( - email.substring(email.lastIndexOf('@') + 1) + email.substring(email.lastIndexOf('@') + 1), ) -> ValidationResult.BLACKLISTED else -> ValidationResult.VALID @@ -76,4 +73,3 @@ class EmailService( ) } } - diff --git a/src/main/kotlin/com/faforever/userservice/backend/email/MailBodyBuilder.kt b/src/main/kotlin/com/faforever/userservice/backend/email/MailBodyBuilder.kt index 301a9074..ab57f173 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/email/MailBodyBuilder.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/email/MailBodyBuilder.kt @@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory import java.nio.file.Files import java.nio.file.Path - @Startup @Singleton class MailBodyBuilder(private val properties: FafProperties) { @@ -22,7 +21,8 @@ class MailBodyBuilder(private val properties: FafProperties) { enum class Template(vararg variables: String) { ACCOUNT_ACTIVATION("username", "activationUrl"), WELCOME_TO_FAF("username"), - PASSWORD_RESET("username", "passwordResetUrl"); + PASSWORD_RESET("username", "passwordResetUrl"), + ; val variables: Set @@ -102,25 +102,27 @@ class MailBodyBuilder(private val properties: FafProperties) { fun buildAccountActivationBody(username: String, activationUrl: String) = populate( - Template.ACCOUNT_ACTIVATION, mapOf( + Template.ACCOUNT_ACTIVATION, + mapOf( "username" to username, - "activationUrl" to activationUrl - ) + "activationUrl" to activationUrl, + ), ) fun buildWelcomeToFafBody(username: String) = populate( - Template.WELCOME_TO_FAF, mapOf( - "username" to username - ) + Template.WELCOME_TO_FAF, + mapOf( + "username" to username, + ), ) - fun buildPasswordResetBody(username: String, passwordResetUrl: String)= - populate( - Template.PASSWORD_RESET, mapOf( + fun buildPasswordResetBody(username: String, passwordResetUrl: String) = + populate( + Template.PASSWORD_RESET, + mapOf( "username" to username, - "passwordResetUrl" to passwordResetUrl - ) + "passwordResetUrl" to passwordResetUrl, + ), ) } - diff --git a/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt b/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt index b7cf7c98..f2a2930a 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/email/MailSender.kt @@ -7,10 +7,10 @@ import jakarta.enterprise.context.ApplicationScoped @ApplicationScoped class MailSender( private val mailer: Mailer, -) { +) { fun sendMail(toEmail: String, subject: String, content: String) { mailer.send( - Mail.withText(toEmail, subject, content) + Mail.withText(toEmail, subject, content), ) } } diff --git a/src/main/kotlin/com/faforever/userservice/backend/metrics/MetricHelper.kt b/src/main/kotlin/com/faforever/userservice/backend/metrics/MetricHelper.kt index 044ea3de..cfb036c9 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/metrics/MetricHelper.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/metrics/MetricHelper.kt @@ -16,23 +16,28 @@ class MetricHelper(meterRegistry: MeterRegistry) { // User Registration Counters val userRegistrationCounter: Counter = meterRegistry.counter( USER_REGISTRATIONS_COUNT, - STEP_TAG, "registration" + STEP_TAG, + "registration", ) val userActivationCounter: Counter = meterRegistry.counter( USER_REGISTRATIONS_COUNT, - STEP_TAG, "activation" + STEP_TAG, + "activation", ) val userSteamLinkRequestedCounter: Counter = meterRegistry.counter( USER_REGISTRATIONS_COUNT, - STEP_TAG, "steamLinkRequested" + STEP_TAG, + "steamLinkRequested", ) val userSteamLinkDoneCounter: Counter = meterRegistry.counter( USER_REGISTRATIONS_COUNT, - STEP_TAG, "steamLinkDone" + STEP_TAG, + "steamLinkDone", ) val userSteamLinkFailedCounter: Counter = meterRegistry.counter( USER_REGISTRATIONS_COUNT, - STEP_TAG, "steamLinkFailed" + STEP_TAG, + "steamLinkFailed", ) // Username Change Counters @@ -41,32 +46,44 @@ class MetricHelper(meterRegistry: MeterRegistry) { // Password Reset Counters val userPasswordResetRequestCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "request", - MODE_TAG, "email" + STEP_TAG, + "request", + MODE_TAG, + "email", ) val userPasswordResetViaSteamRequestCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "request", - MODE_TAG, "steam" + STEP_TAG, + "request", + MODE_TAG, + "steam", ) val userPasswordResetDoneCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "done", - MODE_TAG, "email" + STEP_TAG, + "done", + MODE_TAG, + "email", ) val userPasswordResetFailedCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "failed", - MODE_TAG, "email" + STEP_TAG, + "failed", + MODE_TAG, + "email", ) val userPasswordResetDoneViaSteamCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "done", - MODE_TAG, "steam" + STEP_TAG, + "done", + MODE_TAG, + "steam", ) val userPasswordResetFailedViaSteamCounter: Counter = meterRegistry.counter( USER_PASSWORD_RESET_COUNT, - STEP_TAG, "failed", - MODE_TAG, "steam" + STEP_TAG, + "failed", + MODE_TAG, + "steam", ) } diff --git a/src/main/kotlin/com/faforever/userservice/backend/recaptcha/RecaptchaService.kt b/src/main/kotlin/com/faforever/userservice/backend/recaptcha/RecaptchaService.kt index 1d5eddf6..1142bb31 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/recaptcha/RecaptchaService.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/recaptcha/RecaptchaService.kt @@ -18,8 +18,10 @@ interface RecaptchaClient { @POST @Path("/siteverify") - fun validateResponse(@QueryParam("secret") secret: String, @QueryParam("response") response: String?): VerifyResponse - + fun validateResponse( + @QueryParam("secret") secret: String, + @QueryParam("response") response: String?, + ): VerifyResponse } @ApplicationScoped @@ -54,5 +56,5 @@ data class VerifyResponse( val success: Boolean, val challengeTs: OffsetDateTime?, val hostname: String, - @JsonProperty("error-codes") val errorCodes: List? + @JsonProperty("error-codes") val errorCodes: List?, ) diff --git a/src/main/kotlin/com/faforever/userservice/backend/registration/RegistrationService.kt b/src/main/kotlin/com/faforever/userservice/backend/registration/RegistrationService.kt index a9166a23..6c02f242 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/registration/RegistrationService.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/registration/RegistrationService.kt @@ -28,7 +28,7 @@ enum class EmailStatus { data class RegisteredUser( val username: String, - val email: String + val email: String, ) @ApplicationScoped @@ -61,8 +61,9 @@ class RegistrationService( FafTokenType.REGISTRATION, Duration.ofSeconds(fafProperties.account().registration().linkExpirationSeconds()), mapOf( - KEY_USERNAME to username, KEY_EMAIL to email - ) + KEY_USERNAME to username, + KEY_EMAIL to email, + ), ) val activationUrl = fafProperties.account().registration().activationUrlFormat().format(token) emailService.sendActivationMail(username, email, activationUrl) @@ -78,8 +79,8 @@ class RegistrationService( FafTokenType.REGISTRATION, Duration.ofSeconds(fafProperties.account().passwordReset().linkExpirationSeconds()), mapOf( - KEY_USER_ID to user.id.toString() - ) + KEY_USER_ID to user.id.toString(), + ), ) val passwordResetUrl = fafProperties.account().passwordReset().passwordResetUrlFormat().format(token) emailService.sendPasswordResetMail(user.username, user.email, passwordResetUrl) @@ -94,7 +95,7 @@ class RegistrationService( val reserved = nameRecordRepository.existsByPreviousNameAndChangeTimeAfter( username, - OffsetDateTime.now().minusMonths(fafProperties.account().username().usernameReservationTimeInMonths()) + OffsetDateTime.now().minusMonths(fafProperties.account().username().usernameReservationTimeInMonths()), ) return if (reserved) UsernameStatus.USERNAME_RESERVED else UsernameStatus.USERNAME_AVAILABLE @@ -115,7 +116,7 @@ class RegistrationService( val claims: Map try { claims = fafTokenService.getTokenClaims(FafTokenType.REGISTRATION, registrationToken) - } catch (exception : Exception) { + } catch (exception: Exception) { LOG.error("Unable to extract claims", exception) throw InvalidRegistrationException() } diff --git a/src/main/kotlin/com/faforever/userservice/backend/security/FafTokenService.kt b/src/main/kotlin/com/faforever/userservice/backend/security/FafTokenService.kt index 1c882bc9..823ccaf4 100644 --- a/src/main/kotlin/com/faforever/userservice/backend/security/FafTokenService.kt +++ b/src/main/kotlin/com/faforever/userservice/backend/security/FafTokenService.kt @@ -52,7 +52,9 @@ class FafTokenService( fun createToken(fafTokenType: FafTokenType, lifetime: TemporalAmount, attributes: Map): String { if (attributes.containsKey(KEY_ACTION)) { - throw IllegalArgumentException(MessageFormat.format("'{0}' is a protected attributed and must not be used", KEY_ACTION)) + throw IllegalArgumentException( + MessageFormat.format("'{0}' is a protected attributed and must not be used", KEY_ACTION), + ) } val jwtBuilder = JWTClaimsSet.Builder() diff --git a/src/main/kotlin/com/faforever/userservice/ui/view/exception/InvalidRegistrationExceptionView.kt b/src/main/kotlin/com/faforever/userservice/ui/view/exception/InvalidRegistrationExceptionView.kt index 571be6c9..45908d0f 100644 --- a/src/main/kotlin/com/faforever/userservice/ui/view/exception/InvalidRegistrationExceptionView.kt +++ b/src/main/kotlin/com/faforever/userservice/ui/view/exception/InvalidRegistrationExceptionView.kt @@ -45,8 +45,10 @@ class InvalidRegistrationExceptionView : CompactVerticalLayout(), HasErrorParame add(errorLayout) } - override fun setErrorParameter(event: BeforeEnterEvent?, parameter: ErrorParameter?): Int { + override fun setErrorParameter( + event: BeforeEnterEvent?, + parameter: ErrorParameter?, + ): Int { return HttpServletResponse.SC_INTERNAL_SERVER_ERROR } - -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/faforever/userservice/ui/view/oauth2/LoginView.kt b/src/main/kotlin/com/faforever/userservice/ui/view/oauth2/LoginView.kt index 3deb777c..ec761313 100644 --- a/src/main/kotlin/com/faforever/userservice/ui/view/oauth2/LoginView.kt +++ b/src/main/kotlin/com/faforever/userservice/ui/view/oauth2/LoginView.kt @@ -118,7 +118,8 @@ class LoginView(private val hydraService: HydraService, private val fafPropertie when (loginError) { is LoginResult.UserNoGameOwnership -> { header.setTitle(getTranslation("verification.title")) - errorMessage.text = getTranslation("verification.reason") + " " + fafProperties.account().accountLinkUrl() + errorMessage.text = getTranslation("verification.reason") + " " + + fafProperties.account().accountLinkUrl() } is LoginResult.TechnicalError -> { diff --git a/src/main/kotlin/com/faforever/userservice/ui/view/registration/ActivateView.kt b/src/main/kotlin/com/faforever/userservice/ui/view/registration/ActivateView.kt index 5013e7b6..a0e57955 100644 --- a/src/main/kotlin/com/faforever/userservice/ui/view/registration/ActivateView.kt +++ b/src/main/kotlin/com/faforever/userservice/ui/view/registration/ActivateView.kt @@ -85,11 +85,12 @@ class ActivateView(private val registrationService: RegistrationService, fafProp .bind("password") binder.forField(confirmedPassword) - .withValidator({ confirmedPassword -> confirmedPassword == password.value }, getTranslation("register.password.match") + .withValidator( + { confirmedPassword -> confirmedPassword == password.value }, + getTranslation("register.password.match"), ).bind("confirmedPassword") binder.addStatusChangeListener { submit.isEnabled = it.binder.isValid } - } private fun activate() { @@ -98,7 +99,7 @@ class ActivateView(private val registrationService: RegistrationService, fafProp return } - val ipAddress = IpAddress(VaadinSession.getCurrent().browser.address); + val ipAddress = IpAddress(VaadinSession.getCurrent().browser.address) registrationService.activate(registeredUser, ipAddress, password.value) @@ -120,4 +121,4 @@ class ActivateView(private val registrationService: RegistrationService, fafProp throw InvalidRegistrationException() } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/faforever/userservice/ui/view/registration/RegisterView.kt b/src/main/kotlin/com/faforever/userservice/ui/view/registration/RegisterView.kt index 00bee10d..eee31fbc 100644 --- a/src/main/kotlin/com/faforever/userservice/ui/view/registration/RegisterView.kt +++ b/src/main/kotlin/com/faforever/userservice/ui/view/registration/RegisterView.kt @@ -68,19 +68,24 @@ class RegisterView(private val registrationService: RegistrationService, fafProp val readAndAgree = getTranslation("register.readAndAgree") + " " val termsOfServiceLayout = HorizontalLayout( - termsOfService, Text(readAndAgree), Anchor( - fafProperties.account().registration().termsOfServiceUrl(), getTranslation("register.termsOfService") - ) + termsOfService, + Text(readAndAgree), + Anchor( + fafProperties.account().registration().termsOfServiceUrl(), + getTranslation("register.termsOfService"), + ), ) val privacyPolicyLayout = HorizontalLayout( - privacyPolicy, Text( - readAndAgree - ), Anchor(fafProperties.account().registration().privacyStatementUrl(), getTranslation("register.privacy")) + privacyPolicy, + Text( + readAndAgree, + ), + Anchor(fafProperties.account().registration().privacyStatementUrl(), getTranslation("register.privacy")), ) val rulesLayout = HorizontalLayout( rules, Text(readAndAgree), - Anchor(fafProperties.account().registration().rulesUrl(), getTranslation("register.rules")) + Anchor(fafProperties.account().registration().rulesUrl(), getTranslation("register.rules")), ) add(username, email, termsOfServiceLayout, privacyPolicyLayout, rulesLayout, submit) @@ -97,15 +102,17 @@ class RegisterView(private val registrationService: RegistrationService, fafProp .withValidator({ username -> username.length in 3..15 }, getTranslation("register.username.size")) .withValidator( { username -> !Regex("[^A-Za-z0-9_-]").containsMatchIn(username) }, - getTranslation("register.username.alphanumeric") + getTranslation("register.username.alphanumeric"), ).withValidator( { username -> registrationService.usernameAvailable(username) == UsernameStatus.USERNAME_AVAILABLE }, - getTranslation("register.username.taken") + getTranslation("register.username.taken"), ).bind("username") binder.forField(email) .withValidator(EmailValidator(getTranslation("register.email.invalid"))) - .withValidator({ email -> registrationService.emailAvailable(email) == EmailStatus.EMAIL_AVAILABLE }, getTranslation("register.email.taken") + .withValidator( + { email -> registrationService.emailAvailable(email) == EmailStatus.EMAIL_AVAILABLE }, + getTranslation("register.email.taken"), ).bind("email") binder.forField(termsOfService).asRequired(getTranslation("register.acknowledge.terms")).bind("termsOfService") @@ -115,7 +122,6 @@ class RegisterView(private val registrationService: RegistrationService, fafProp binder.forField(rules).asRequired(getTranslation("register.acknowledge.rules")).bind("rules") binder.addStatusChangeListener { submit.isEnabled = it.binder.isValid } - } private fun register() { @@ -133,4 +139,4 @@ class RegisterView(private val registrationService: RegistrationService, fafProp binder.readBean(null) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/faforever/userservice/backend/registration/RegistrationServiceTest.kt b/src/test/kotlin/com/faforever/userservice/backend/registration/RegistrationServiceTest.kt index 335ff626..a5238d4d 100644 --- a/src/test/kotlin/com/faforever/userservice/backend/registration/RegistrationServiceTest.kt +++ b/src/test/kotlin/com/faforever/userservice/backend/registration/RegistrationServiceTest.kt @@ -22,7 +22,6 @@ import org.mockito.kotlin.any import org.mockito.kotlin.verify import org.mockito.kotlin.whenever - @QuarkusTest class RegistrationServiceTest { @@ -103,34 +102,42 @@ class RegistrationServiceTest { fun activateSuccess() { registrationService.activate(RegisteredUser(username, email), ipAddress, password) - verify(userRepository).persist(any()) + verify(userRepository).persist(any()) } @Test fun activateUsernameTaken() { whenever(userRepository.existsByUsername(anyString())).thenReturn(true) - assertThrows { registrationService.activate(RegisteredUser(username, email), ipAddress, password) } + assertThrows { + registrationService.activate(RegisteredUser(username, email), ipAddress, password) + } } @Test fun activateUsernameReserved() { whenever(nameRecordRepository.existsByPreviousNameAndChangeTimeAfter(anyString(), any())).thenReturn(true) - assertThrows { registrationService.activate(RegisteredUser(username, email), ipAddress, password) } + assertThrows { + registrationService.activate(RegisteredUser(username, email), ipAddress, password) + } } @Test fun activateEmailTaken() { whenever(userRepository.existsByEmail(anyString())).thenReturn(true) - assertThrows { registrationService.activate(RegisteredUser(username, email), ipAddress, password) } + assertThrows { + registrationService.activate(RegisteredUser(username, email), ipAddress, password) + } } @Test fun activateEmailBlacklisted() { whenever(domainBlacklistRepository.existsByDomain(anyString())).thenReturn(true) - assertThrows { registrationService.activate(RegisteredUser(username, email), ipAddress, password) } + assertThrows { + registrationService.activate(RegisteredUser(username, email), ipAddress, password) + } } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/faforever/userservice/backend/security/FAFTokenServiceTest.kt b/src/test/kotlin/com/faforever/userservice/backend/security/FAFTokenServiceTest.kt index 7d155d2b..19bf9579 100644 --- a/src/test/kotlin/com/faforever/userservice/backend/security/FAFTokenServiceTest.kt +++ b/src/test/kotlin/com/faforever/userservice/backend/security/FAFTokenServiceTest.kt @@ -30,7 +30,7 @@ class FAFTokenServiceTest { assertThrows { fafTokenService.getTokenClaims( FafTokenType.LINK_TO_STEAM, - token + token, ) } } @@ -42,7 +42,7 @@ class FAFTokenServiceTest { assertThrows { fafTokenService.getTokenClaims( FafTokenType.REGISTRATION, - token + token, ) } } @@ -54,5 +54,4 @@ class FAFTokenServiceTest { fafTokenService.createToken(FafTokenType.REGISTRATION, Duration.ofSeconds(60), attributes) } } - -} \ No newline at end of file +}