diff --git a/src/main/kotlin/com/vauthenticator/server/account/AccountConfig.kt b/src/main/kotlin/com/vauthenticator/server/account/AccountConfig.kt new file mode 100644 index 00000000..07e98351 --- /dev/null +++ b/src/main/kotlin/com/vauthenticator/server/account/AccountConfig.kt @@ -0,0 +1,225 @@ +package com.vauthenticator.server.account + +import com.fasterxml.jackson.databind.ObjectMapper +import com.hubspot.jinjava.Jinjava +import com.vauthenticator.document.repository.DocumentRepository +import com.vauthenticator.server.account.adapter.CachedAccountRepository +import com.vauthenticator.server.account.adapter.dynamodb.DynamoDbAccountRepository +import com.vauthenticator.server.account.adapter.jdbc.JdbcAccountRepository +import com.vauthenticator.server.account.domain.AccountCacheContentConverter +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.AccountUpdateAdminAction +import com.vauthenticator.server.account.domain.SaveAccount +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallenge +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer +import com.vauthenticator.server.account.domain.emailverification.VerifyEMailChallenge +import com.vauthenticator.server.account.domain.signup.SignUpUse +import com.vauthenticator.server.account.domain.welcome.SayWelcome +import com.vauthenticator.server.account.domain.welcome.SendWelcomeMailUponSignUpEventConsumer +import com.vauthenticator.server.cache.CacheOperation +import com.vauthenticator.server.cache.RedisCacheOperation +import com.vauthenticator.server.communication.NoReplyEMailConfiguration +import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver +import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService +import com.vauthenticator.server.communication.domain.EMailSenderService +import com.vauthenticator.server.communication.domain.EMailType +import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory +import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher +import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment +import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation +import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository +import com.vauthenticator.server.password.domain.PasswordPolicy +import com.vauthenticator.server.password.domain.VAuthenticatorPasswordEncoder +import com.vauthenticator.server.role.domain.RoleRepository +import com.vauthenticator.server.ticket.domain.TicketRepository +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.mail.javamail.JavaMailSender +import software.amazon.awssdk.services.dynamodb.DynamoDbClient +import java.time.Duration + +@Configuration(proxyBeanMethods = false) +class AccountConfig { + + @Bean + fun changeAccountEnabling(accountRepository: AccountRepository): AccountUpdateAdminAction = + AccountUpdateAdminAction(accountRepository) + + @Bean + fun saveAccount(accountRepository: AccountRepository): SaveAccount = + SaveAccount(accountRepository) + + + @Bean("accountRepository") + @Profile("experimental_database_persistence") + fun jdbcAccountRepository( + jdbcTemplate: JdbcTemplate + ) = JdbcAccountRepository(jdbcTemplate) + + + @Bean("accountRepository") + @ConditionalOnProperty( + name = ["vauthenticator.dynamo-db.account.cache.enabled"], + havingValue = "false", + matchIfMissing = true + ) + @Profile("!experimental_database_persistence") + fun dynamoDbAccountRepository( + mapper: ObjectMapper, + dynamoDbClient: DynamoDbClient, + roleRepository: RoleRepository, + @Value("\${vauthenticator.dynamo-db.account.table-name}") accountTableName: String, + @Value("\${vauthenticator.dynamo-db.account.role.table-name}") accountRoleTableName: String + ) = + DynamoDbAccountRepository(dynamoDbClient, accountTableName, roleRepository) + + + @Bean("accountRepository") + @ConditionalOnProperty( + name = ["vauthenticator.dynamo-db.account.cache.enabled"], + havingValue = "true", + matchIfMissing = false + ) + @Profile("!experimental_database_persistence") + fun cachedDynamoDbAccountRepository( + mapper: ObjectMapper, + dynamoDbClient: DynamoDbClient, + accountCacheOperation: CacheOperation, + roleRepository: RoleRepository, + @Value("\${vauthenticator.dynamo-db.account.table-name}") accountTableName: String, + @Value("\${vauthenticator.dynamo-db.account.role.table-name}") accountRoleTableName: String + ) = + CachedAccountRepository( + AccountCacheContentConverter(mapper), + accountCacheOperation, + DynamoDbAccountRepository(dynamoDbClient, accountTableName, roleRepository), + ) + + @Bean + @ConditionalOnProperty( + name = ["vauthenticator.dynamo-db.account.cache.enabled"], + havingValue = "true", + matchIfMissing = false + ) + @Profile("!experimental_database_persistence") + fun accountCacheOperation( + redisTemplate: RedisTemplate<*, *>, + @Value("\${vauthenticator.dynamo-db.account.cache.ttl}") ttl: Duration, + @Value("\${vauthenticator.dynamo-db.account.cache.name}") cacheRegionName: String, + ) = RedisCacheOperation( + cacheName = cacheRegionName, + ttl = ttl, + redisTemplate = redisTemplate as RedisTemplate + ) +} + + +@Configuration(proxyBeanMethods = false) +class WelcomeConfig { + + @Bean + fun sayWelcome( + accountRepository: AccountRepository, + welcomeMailSender: EMailSenderService + ) = SayWelcome(accountRepository, welcomeMailSender) + + @Bean + fun welcomeMailSender( + javaMailSender: JavaMailSender, + documentRepository: DocumentRepository, + noReplyEMailConfiguration: NoReplyEMailConfiguration + ) = + JavaEMailSenderService( + documentRepository, + javaMailSender, + JinJavaTemplateResolver(Jinjava()), + SimpleEMailMessageFactory( + noReplyEMailConfiguration.from, + noReplyEMailConfiguration.welcomeEMailSubject, + EMailType.WELCOME + ) + ) + + @Bean + fun sendWelcomeMailUponSignUpEventConsumer(sayWelcome: SayWelcome) = + SendWelcomeMailUponSignUpEventConsumer(sayWelcome) +} + + +@Configuration(proxyBeanMethods = false) +class EMailVerificationConfig { + + @Bean + fun sendVerifyMailChallenge( + clientAccountRepository: ClientApplicationRepository, + accountRepository: AccountRepository, + mfaMethodsEnrollment: MfaMethodsEnrollment, + verificationMailSender: EMailSenderService, + @Value("\${vauthenticator.host}") frontChannelBaseUrl: String + ) = + SendVerifyEMailChallenge( + accountRepository, + mfaMethodsEnrollment, + verificationMailSender, + frontChannelBaseUrl + ) + + @Bean + fun verifyMailChallengeSent( + accountRepository: AccountRepository, + ticketRepository: TicketRepository, + mfaMethodsEnrollmentAssociation: MfaMethodsEnrollmentAssociation + ) = + VerifyEMailChallenge( + ticketRepository, + accountRepository, + mfaMethodsEnrollmentAssociation + ) + + @Bean + fun verificationMailSender( + javaMailSender: JavaMailSender, + documentRepository: DocumentRepository, + noReplyEMailConfiguration: NoReplyEMailConfiguration + ) = + JavaEMailSenderService( + documentRepository, + javaMailSender, + JinJavaTemplateResolver(Jinjava()), + SimpleEMailMessageFactory( + noReplyEMailConfiguration.from, + noReplyEMailConfiguration.welcomeEMailSubject, + EMailType.EMAIL_VERIFICATION + ) + ) + + @Bean + fun sendVerifyMailChallengeUponSignUpEventConsumer(mailChallenge: SendVerifyEMailChallenge) = + SendVerifyEMailChallengeUponSignUpEventConsumer(mailChallenge) +} + + +@Configuration(proxyBeanMethods = false) +class SingUpConfig { + + @Bean + fun signUpUseCase( + passwordPolicy: PasswordPolicy, + clientAccountRepository: ClientApplicationRepository, + accountRepository: AccountRepository, + vAuthenticatorPasswordEncoder: VAuthenticatorPasswordEncoder, + vAuthenticatorEventsDispatcher : VAuthenticatorEventsDispatcher + ): SignUpUse = + SignUpUse( + passwordPolicy, + accountRepository, + vAuthenticatorPasswordEncoder, + vAuthenticatorEventsDispatcher + ) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepository.kt b/src/main/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepository.kt similarity index 86% rename from src/main/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepository.kt rename to src/main/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepository.kt index 433441e3..ee2c0b2c 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepository.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepository.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.repository +package com.vauthenticator.server.account.adapter -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.cache.CacheContentConverter import com.vauthenticator.server.cache.CacheOperation import java.util.* diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountConverter.kt b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountConverter.kt similarity index 79% rename from src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountConverter.kt rename to src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountConverter.kt index cd199ab4..75ccee0b 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountConverter.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountConverter.kt @@ -1,6 +1,6 @@ -package com.vauthenticator.server.account.repository.dynamodb +package com.vauthenticator.server.account.adapter.dynamodb -import com.vauthenticator.server.account.* +import com.vauthenticator.server.account.domain.* import com.vauthenticator.server.extentions.asDynamoAttribute import com.vauthenticator.server.extentions.valueAsBoolFor import com.vauthenticator.server.extentions.valueAsStringFor @@ -22,10 +22,24 @@ object DynamoAccountConverter { firstName = dynamoPayload.valueAsStringFor("firstName"), lastName = dynamoPayload.valueAsStringFor("lastName"), authorities = dynamoPayload.valueAsStringSetFor("authorities"), - birthDate = Date.isoDateFor(dynamoPayload.valueAsStringFor("birthDate")), - phone = Phone.phoneFor(dynamoPayload.valueAsStringFor("phone")), - locale = UserLocale.localeFrom(dynamoPayload.valueAsStringFor("locale")), - mandatoryAction = AccountMandatoryAction.valueOf(dynamoPayload.valueAsStringFor("mandatory_action")) + birthDate = Date.isoDateFor( + dynamoPayload.valueAsStringFor( + "birthDate" + ) + ), + phone = Phone.phoneFor( + dynamoPayload.valueAsStringFor( + "phone" + ) + ), + locale = UserLocale.localeFrom( + dynamoPayload.valueAsStringFor( + "locale" + ) + ), + mandatoryAction = AccountMandatoryAction.valueOf( + dynamoPayload.valueAsStringFor("mandatory_action") + ) ) fun fromDomainToDynamo(account: Account) = diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountQueryFactory.kt b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountQueryFactory.kt similarity index 79% rename from src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountQueryFactory.kt rename to src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountQueryFactory.kt index a5b158f8..e476036d 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoAccountQueryFactory.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoAccountQueryFactory.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.repository.dynamodb +package com.vauthenticator.server.account.adapter.dynamodb -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.adapter.dynamodb.DynamoAccountConverter.fromDomainToDynamo +import com.vauthenticator.server.account.domain.Account import com.vauthenticator.server.extentions.asDynamoAttribute import software.amazon.awssdk.services.dynamodb.model.GetItemRequest import software.amazon.awssdk.services.dynamodb.model.PutItemRequest @@ -19,7 +20,7 @@ object DynamoAccountQueryFactory { fun storeAccountQueryFor(account: Account, table: String, withUpsert: Boolean = true): PutItemRequest = PutItemRequest.builder() .tableName(table) - .item(DynamoAccountConverter.fromDomainToDynamo(account)) + .item(fromDomainToDynamo(account)) .let { if (withUpsert) it diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAccountRepository.kt b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAccountRepository.kt similarity index 76% rename from src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAccountRepository.kt rename to src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAccountRepository.kt index 32962ff1..f6a65438 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAccountRepository.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAccountRepository.kt @@ -1,11 +1,11 @@ -package com.vauthenticator.server.account.repository.dynamodb - -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.repository.AccountRegistrationException -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountConverter.fromDynamoToDomain -import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountQueryFactory.findAccountQueryForUserName -import com.vauthenticator.server.account.repository.dynamodb.DynamoAccountQueryFactory.storeAccountQueryFor +package com.vauthenticator.server.account.adapter.dynamodb + +import com.vauthenticator.server.account.adapter.dynamodb.DynamoAccountConverter.fromDynamoToDomain +import com.vauthenticator.server.account.adapter.dynamodb.DynamoAccountQueryFactory.findAccountQueryForUserName +import com.vauthenticator.server.account.adapter.dynamodb.DynamoAccountQueryFactory.storeAccountQueryFor +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRegistrationException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.extentions.filterEmptyMetadata import com.vauthenticator.server.role.domain.RoleRepository import software.amazon.awssdk.services.dynamodb.DynamoDbClient diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepository.kt b/src/main/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepository.kt similarity index 92% rename from src/main/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepository.kt rename to src/main/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepository.kt index bfcab100..6bd96d65 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepository.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepository.kt @@ -1,9 +1,7 @@ -package com.vauthenticator.server.account.repository.jdbc +package com.vauthenticator.server.account.adapter.jdbc -import com.vauthenticator.server.account.* -import com.vauthenticator.server.account.Date -import com.vauthenticator.server.account.repository.AccountRegistrationException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.* +import com.vauthenticator.server.account.domain.Date import org.springframework.dao.DuplicateKeyException import org.springframework.jdbc.core.JdbcTemplate import org.springframework.transaction.annotation.Transactional @@ -106,10 +104,18 @@ class JdbcAccountRepository(private val jdbcTemplate: JdbcTemplate) : AccountRep firstName = rs.getString("first_name"), lastName = rs.getString("last_name"), authorities = authorities, - birthDate = Date.isoDateFor(rs.getString("birth_date").orEmpty()), + birthDate = Date.isoDateFor( + rs.getString("birth_date").orEmpty() + ), phone = Phone.phoneFor(rs.getString("phone")), - locale = UserLocale.localeFrom(rs.getString("locale")), - mandatoryAction = AccountMandatoryAction.valueOf(rs.getString("mandatory_action")) + locale = UserLocale.localeFrom( + rs.getString( + "locale" + ) + ), + mandatoryAction = AccountMandatoryAction.valueOf( + rs.getString("mandatory_action") + ) ) }, username) return Optional.ofNullable(queryResult.firstOrNull()) diff --git a/src/main/kotlin/com/vauthenticator/server/account/api/AccountEndPoint.kt b/src/main/kotlin/com/vauthenticator/server/account/api/AccountEndPoint.kt index 862d21fd..745747e2 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/api/AccountEndPoint.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/api/AccountEndPoint.kt @@ -1,10 +1,10 @@ package com.vauthenticator.server.account.api -import com.vauthenticator.server.account.* -import com.vauthenticator.server.account.AccountMandatoryAction.NO_ACTION -import com.vauthenticator.server.account.Date +import com.vauthenticator.server.account.domain.AccountMandatoryAction.NO_ACTION import com.vauthenticator.server.account.api.SignUpAccountConverter.fromRepresentationToSignedUpAccount -import com.vauthenticator.server.account.signup.SignUpUse +import com.vauthenticator.server.account.domain.* +import com.vauthenticator.server.account.domain.Date +import com.vauthenticator.server.account.domain.signup.SignUpUse import com.vauthenticator.server.extentions.clientAppId import com.vauthenticator.server.extentions.oauth2ClientId import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/main/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPoint.kt b/src/main/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPoint.kt index 8e048ffd..1b271d32 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPoint.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPoint.kt @@ -1,10 +1,6 @@ package com.vauthenticator.server.account.api -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.AccountMandatoryAction -import com.vauthenticator.server.account.AccountUpdateAdminAction -import com.vauthenticator.server.account.AdminAccountApiRequest -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.* import org.springframework.http.ResponseEntity.noContent import org.springframework.http.ResponseEntity.ok import org.springframework.security.core.Authentication diff --git a/src/main/kotlin/com/vauthenticator/server/account/emailverification/EMailVerificationEndPoint.kt b/src/main/kotlin/com/vauthenticator/server/account/api/EMailVerificationEndPoint.kt similarity index 62% rename from src/main/kotlin/com/vauthenticator/server/account/emailverification/EMailVerificationEndPoint.kt rename to src/main/kotlin/com/vauthenticator/server/account/api/EMailVerificationEndPoint.kt index 855390dc..1df649d4 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/emailverification/EMailVerificationEndPoint.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/api/EMailVerificationEndPoint.kt @@ -1,7 +1,6 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.api -import com.vauthenticator.server.i18n.I18nMessageInjector -import com.vauthenticator.server.i18n.I18nScope +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallenge import com.vauthenticator.server.oauth2.clientapp.domain.Scope import com.vauthenticator.server.oauth2.clientapp.domain.Scopes import com.vauthenticator.server.role.domain.PermissionValidator @@ -10,8 +9,6 @@ import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity.badRequest import org.springframework.http.ResponseEntity.noContent import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken -import org.springframework.stereotype.Controller -import org.springframework.ui.Model import org.springframework.web.bind.annotation.* @RestController @@ -38,21 +35,4 @@ class MailVerificationEndPoint( } -} - -@Controller -class MailVerificationController( - private val i18nMessageInjector: I18nMessageInjector, - private val verifyEMailChallenge: VerifyEMailChallenge -) { - - @GetMapping("/email-verify/{ticket}") - fun verifyMail(@PathVariable ticket: String, model: Model): String { - verifyEMailChallenge.verifyMail(ticket) - - i18nMessageInjector.setMessagedFor(I18nScope.SUCCESSFUL_MAIL_VERIFY_PAGE, model) - model.addAttribute("assetBundle", "successfulMailVerify_bundle.js") - return "template" - } - } \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/account/welcome/WelcomeMailEndPoint.kt b/src/main/kotlin/com/vauthenticator/server/account/api/WelcomeMailEndPoint.kt similarity index 87% rename from src/main/kotlin/com/vauthenticator/server/account/welcome/WelcomeMailEndPoint.kt rename to src/main/kotlin/com/vauthenticator/server/account/api/WelcomeMailEndPoint.kt index 68749af6..27eadfa0 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/welcome/WelcomeMailEndPoint.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/api/WelcomeMailEndPoint.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.api -import com.vauthenticator.server.account.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.welcome.SayWelcome import com.vauthenticator.server.oauth2.clientapp.domain.Scope import com.vauthenticator.server.oauth2.clientapp.domain.Scopes import com.vauthenticator.server.role.domain.PermissionValidator diff --git a/src/main/kotlin/com/vauthenticator/server/account/Account.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/Account.kt similarity index 86% rename from src/main/kotlin/com/vauthenticator/server/account/Account.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/Account.kt index 57824889..e12bfe98 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/Account.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/Account.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.domain import com.fasterxml.jackson.databind.ObjectMapper import com.vauthenticator.server.cache.CacheContentConverter @@ -84,7 +84,14 @@ data class Date( fun empty(): Optional = Optional.empty() fun isoDateFor(date: String): Optional = try { - Optional.of(Date(LocalDate.parse(date, USER_INFO_DEFAULT_DATE_TIME_FORMATTER))) + Optional.of( + Date( + LocalDate.parse( + date, + USER_INFO_DEFAULT_DATE_TIME_FORMATTER + ) + ) + ) } catch (e: RuntimeException) { empty() } @@ -106,9 +113,21 @@ data class Phone(private val countryPrefix: String, private val prefix: String, var phone = Optional.empty() val split = phoneNumber.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray() if (split.size == 3) { - phone = Optional.of(Phone(split[0], split[1], split[2])) + phone = Optional.of( + Phone( + split[0], + split[1], + split[2] + ) + ) } else if (split.size == 2) { - phone = Optional.of(Phone("", split[0], split[1])) + phone = Optional.of( + Phone( + "", + split[0], + split[1] + ) + ) } phone } catch (e: RuntimeException) { @@ -140,8 +159,12 @@ class AccountCacheContentConverter(private val objectMapper: ObjectMapper) : Cac lastName = it["lastName"] as String, birthDate = Date.isoDateFor(it["birthDate"] as String), phone = Phone.phoneFor(it["phone"] as String), - locale = UserLocale.localeFrom((it["locale"] as String)), - mandatoryAction = AccountMandatoryAction.valueOf(it["mandatory_action"] as String) + locale = UserLocale.localeFrom( + (it["locale"] as String) + ), + mandatoryAction = AccountMandatoryAction.valueOf( + it["mandatory_action"] as String + ) ) } diff --git a/src/main/kotlin/com/vauthenticator/server/account/repository/AccountRepository.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/AccountRepository.kt similarity index 73% rename from src/main/kotlin/com/vauthenticator/server/account/repository/AccountRepository.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/AccountRepository.kt index b65f9bcf..f2e1af43 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/repository/AccountRepository.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/AccountRepository.kt @@ -1,6 +1,5 @@ -package com.vauthenticator.server.account.repository +package com.vauthenticator.server.account.domain -import com.vauthenticator.server.account.Account import java.util.* interface AccountRepository { diff --git a/src/main/kotlin/com/vauthenticator/server/account/AccountUpdateAdminAction.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminAction.kt similarity index 88% rename from src/main/kotlin/com/vauthenticator/server/account/AccountUpdateAdminAction.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminAction.kt index eeec012d..5bff5408 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/AccountUpdateAdminAction.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminAction.kt @@ -1,6 +1,5 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.domain -import com.vauthenticator.server.account.repository.AccountRepository data class AdminAccountApiRequest( val accountLocked: Boolean = true, diff --git a/src/main/kotlin/com/vauthenticator/server/account/SaveAccount.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/SaveAccount.kt similarity index 90% rename from src/main/kotlin/com/vauthenticator/server/account/SaveAccount.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/SaveAccount.kt index 7386082b..5ba8500d 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/SaveAccount.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/SaveAccount.kt @@ -1,6 +1,5 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.domain -import com.vauthenticator.server.account.repository.AccountRepository import java.security.Principal class SaveAccount(private val accountRepository: AccountRepository) { diff --git a/src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallenge.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallenge.kt similarity index 90% rename from src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallenge.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallenge.kt index 136a07ea..827e78b0 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallenge.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallenge.kt @@ -1,7 +1,7 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.mfa.domain.MfaMethod import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment diff --git a/src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt similarity index 88% rename from src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt index 16ee71ed..f629ac7f 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumer.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification import com.vauthenticator.server.events.EventConsumer import com.vauthenticator.server.events.SignUpEvent diff --git a/src/main/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallenge.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallenge.kt similarity index 88% rename from src/main/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallenge.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallenge.kt index f53d5122..8a442825 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallenge.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallenge.kt @@ -1,7 +1,7 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation import com.vauthenticator.server.ticket.domain.InvalidTicketException import com.vauthenticator.server.ticket.domain.TicketId diff --git a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumer.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumer.kt similarity index 92% rename from src/main/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumer.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumer.kt index bb2118b9..d709777b 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumer.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumer.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.account.signup +package com.vauthenticator.server.account.domain.signup import com.vauthenticator.server.events.EventConsumer import com.vauthenticator.server.events.SignUpEvent diff --git a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpUse.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUse.kt similarity index 85% rename from src/main/kotlin/com/vauthenticator/server/account/signup/SignUpUse.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUse.kt index 21c44170..358efd1a 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpUse.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUse.kt @@ -1,8 +1,8 @@ -package com.vauthenticator.server.account.signup +package com.vauthenticator.server.account.domain.signup -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.Email -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.events.SignUpEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/main/kotlin/com/vauthenticator/server/account/welcome/SayWelcome.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcome.kt similarity index 69% rename from src/main/kotlin/com/vauthenticator/server/account/welcome/SayWelcome.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcome.kt index 30806d22..c7dc5dcb 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/welcome/SayWelcome.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcome.kt @@ -1,7 +1,7 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.domain.welcome -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService class SayWelcome( diff --git a/src/main/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumer.kt b/src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumer.kt similarity index 89% rename from src/main/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumer.kt rename to src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumer.kt index 60788598..8c7c318a 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumer.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumer.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.domain.welcome import com.vauthenticator.server.events.EventConsumer import com.vauthenticator.server.events.SignUpEvent diff --git a/src/main/kotlin/com/vauthenticator/server/account/web/MailVerificationController.kt b/src/main/kotlin/com/vauthenticator/server/account/web/MailVerificationController.kt new file mode 100644 index 00000000..a1ab0e2a --- /dev/null +++ b/src/main/kotlin/com/vauthenticator/server/account/web/MailVerificationController.kt @@ -0,0 +1,26 @@ +package com.vauthenticator.server.account.web + +import com.vauthenticator.server.account.domain.emailverification.VerifyEMailChallenge +import com.vauthenticator.server.i18n.I18nMessageInjector +import com.vauthenticator.server.i18n.I18nScope +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable + +@Controller +class MailVerificationController( + private val i18nMessageInjector: I18nMessageInjector, + private val verifyEMailChallenge: VerifyEMailChallenge +) { + + @GetMapping("/email-verify/{ticket}") + fun verifyMail(@PathVariable ticket: String, model: Model): String { + verifyEMailChallenge.verifyMail(ticket) + + i18nMessageInjector.setMessagedFor(I18nScope.SUCCESSFUL_MAIL_VERIFY_PAGE, model) + model.addAttribute("assetBundle", "successfulMailVerify_bundle.js") + return "template" + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpController.kt b/src/main/kotlin/com/vauthenticator/server/account/web/SignUpController.kt similarity index 95% rename from src/main/kotlin/com/vauthenticator/server/account/signup/SignUpController.kt rename to src/main/kotlin/com/vauthenticator/server/account/web/SignUpController.kt index b69d55cc..c6b1e5c5 100644 --- a/src/main/kotlin/com/vauthenticator/server/account/signup/SignUpController.kt +++ b/src/main/kotlin/com/vauthenticator/server/account/web/SignUpController.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.account.signup +package com.vauthenticator.server.account.web import com.vauthenticator.server.i18n.I18nMessageInjector import com.vauthenticator.server.i18n.I18nScope diff --git a/src/main/kotlin/com/vauthenticator/server/communication/adapter/javamail/JavaEMailSenderService.kt b/src/main/kotlin/com/vauthenticator/server/communication/adapter/javamail/JavaEMailSenderService.kt index 64f159d9..6e6e474e 100644 --- a/src/main/kotlin/com/vauthenticator/server/communication/adapter/javamail/JavaEMailSenderService.kt +++ b/src/main/kotlin/com/vauthenticator/server/communication/adapter/javamail/JavaEMailSenderService.kt @@ -2,7 +2,7 @@ package com.vauthenticator.server.communication.adapter.javamail import com.vauthenticator.document.repository.DocumentRepository import com.vauthenticator.document.repository.DocumentType -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account import com.vauthenticator.server.communication.domain.* import jakarta.mail.internet.MimeMessage import org.springframework.mail.javamail.JavaMailSender diff --git a/src/main/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderService.kt b/src/main/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderService.kt index bf495b5b..cfe35254 100644 --- a/src/main/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderService.kt +++ b/src/main/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderService.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.communication.adapter.sns -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account import com.vauthenticator.server.communication.domain.MessageContext import com.vauthenticator.server.communication.domain.SmsMessageFactory import com.vauthenticator.server.communication.domain.SmsSenderService diff --git a/src/main/kotlin/com/vauthenticator/server/communication/domain/Email.kt b/src/main/kotlin/com/vauthenticator/server/communication/domain/Email.kt index 1da2d774..50444b21 100644 --- a/src/main/kotlin/com/vauthenticator/server/communication/domain/Email.kt +++ b/src/main/kotlin/com/vauthenticator/server/communication/domain/Email.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.communication.domain -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account fun interface EMailSenderService { fun sendFor(account: Account, emailContext: MessageContext) diff --git a/src/main/kotlin/com/vauthenticator/server/communication/domain/MessageContext.kt b/src/main/kotlin/com/vauthenticator/server/communication/domain/MessageContext.kt index 2bc1f317..9706755a 100644 --- a/src/main/kotlin/com/vauthenticator/server/communication/domain/MessageContext.kt +++ b/src/main/kotlin/com/vauthenticator/server/communication/domain/MessageContext.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.communication.domain -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account typealias MessageContext = Map diff --git a/src/main/kotlin/com/vauthenticator/server/communication/domain/Sms.kt b/src/main/kotlin/com/vauthenticator/server/communication/domain/Sms.kt index 304e55b9..cc02f746 100644 --- a/src/main/kotlin/com/vauthenticator/server/communication/domain/Sms.kt +++ b/src/main/kotlin/com/vauthenticator/server/communication/domain/Sms.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.communication.domain -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account data class SmsMessage(val phoneNumber: String, val message: String) diff --git a/src/main/kotlin/com/vauthenticator/server/config/AccountConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/AccountConfig.kt deleted file mode 100644 index 413864b0..00000000 --- a/src/main/kotlin/com/vauthenticator/server/config/AccountConfig.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.vauthenticator.server.config - -import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.account.AccountCacheContentConverter -import com.vauthenticator.server.account.AccountUpdateAdminAction -import com.vauthenticator.server.account.SaveAccount -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.account.repository.CachedAccountRepository -import com.vauthenticator.server.account.repository.dynamodb.DynamoDbAccountRepository -import com.vauthenticator.server.account.repository.jdbc.JdbcAccountRepository -import com.vauthenticator.server.cache.CacheOperation -import com.vauthenticator.server.cache.RedisCacheOperation -import com.vauthenticator.server.role.domain.RoleRepository -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Profile -import org.springframework.data.redis.core.RedisTemplate -import org.springframework.jdbc.core.JdbcTemplate -import software.amazon.awssdk.services.dynamodb.DynamoDbClient -import java.time.Duration - -@Configuration(proxyBeanMethods = false) -class AccountConfig { - - @Bean - fun changeAccountEnabling(accountRepository: AccountRepository): AccountUpdateAdminAction = - AccountUpdateAdminAction(accountRepository) - - @Bean - fun saveAccount(accountRepository: AccountRepository): SaveAccount = - SaveAccount(accountRepository) - - - @Bean("accountRepository") - @Profile("experimental_database_persistence") - fun jdbcAccountRepository( - jdbcTemplate: JdbcTemplate - ) = JdbcAccountRepository(jdbcTemplate) - - - @Bean("accountRepository") - @ConditionalOnProperty( - name = ["vauthenticator.dynamo-db.account.cache.enabled"], - havingValue = "false", - matchIfMissing = true - ) - @Profile("!experimental_database_persistence") - fun dynamoDbAccountRepository( - mapper: ObjectMapper, - dynamoDbClient: DynamoDbClient, - roleRepository: RoleRepository, - @Value("\${vauthenticator.dynamo-db.account.table-name}") accountTableName: String, - @Value("\${vauthenticator.dynamo-db.account.role.table-name}") accountRoleTableName: String - ) = - DynamoDbAccountRepository(dynamoDbClient, accountTableName, roleRepository) - - - @Bean("accountRepository") - @ConditionalOnProperty( - name = ["vauthenticator.dynamo-db.account.cache.enabled"], - havingValue = "true", - matchIfMissing = false - ) - @Profile("!experimental_database_persistence") - fun cachedDynamoDbAccountRepository( - mapper: ObjectMapper, - dynamoDbClient: DynamoDbClient, - accountCacheOperation: CacheOperation, - roleRepository: RoleRepository, - @Value("\${vauthenticator.dynamo-db.account.table-name}") accountTableName: String, - @Value("\${vauthenticator.dynamo-db.account.role.table-name}") accountRoleTableName: String - ) = - CachedAccountRepository( - AccountCacheContentConverter(mapper), - accountCacheOperation, - DynamoDbAccountRepository(dynamoDbClient, accountTableName, roleRepository), - ) - - @Bean - @ConditionalOnProperty( - name = ["vauthenticator.dynamo-db.account.cache.enabled"], - havingValue = "true", - matchIfMissing = false - ) - @Profile("!experimental_database_persistence") - fun accountCacheOperation( - redisTemplate: RedisTemplate<*, *>, - @Value("\${vauthenticator.dynamo-db.account.cache.ttl}") ttl: Duration, - @Value("\${vauthenticator.dynamo-db.account.cache.name}") cacheRegionName: String, - ) = RedisCacheOperation( - cacheName = cacheRegionName, - ttl = ttl, - redisTemplate = redisTemplate as RedisTemplate - ) -} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/config/AuthorizationServerConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/AuthorizationServerConfig.kt index 0c8203aa..99e2002c 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/AuthorizationServerConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/config/AuthorizationServerConfig.kt @@ -2,7 +2,7 @@ package com.vauthenticator.server.config import com.nimbusds.jose.jwk.source.JWKSource import com.nimbusds.jose.proc.SecurityContext -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.keys.adapter.spring.KeysJWKSource import com.vauthenticator.server.keys.domain.KeyDecrypter import com.vauthenticator.server.keys.domain.KeyRepository diff --git a/src/main/kotlin/com/vauthenticator/server/config/EMailVerificationConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/EMailVerificationConfig.kt deleted file mode 100644 index 5186b5ee..00000000 --- a/src/main/kotlin/com/vauthenticator/server/config/EMailVerificationConfig.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.vauthenticator.server.config - -import com.hubspot.jinjava.Jinjava -import com.vauthenticator.document.repository.DocumentRepository -import com.vauthenticator.server.account.emailverification.SendVerifyEMailChallenge -import com.vauthenticator.server.account.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer -import com.vauthenticator.server.account.emailverification.VerifyEMailChallenge -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.communication.NoReplyEMailConfiguration -import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver -import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService -import com.vauthenticator.server.communication.domain.EMailSenderService -import com.vauthenticator.server.communication.domain.EMailType -import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory -import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment -import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation -import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository -import com.vauthenticator.server.ticket.domain.TicketRepository -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.mail.javamail.JavaMailSender - -@Configuration(proxyBeanMethods = false) -class EMailVerificationConfig { - - @Bean - fun sendVerifyMailChallenge( - clientAccountRepository: ClientApplicationRepository, - accountRepository: AccountRepository, - mfaMethodsEnrollment: MfaMethodsEnrollment, - verificationMailSender: EMailSenderService, - @Value("\${vauthenticator.host}") frontChannelBaseUrl: String - ) = - SendVerifyEMailChallenge( - accountRepository, - mfaMethodsEnrollment, - verificationMailSender, - frontChannelBaseUrl - ) - - @Bean - fun verifyMailChallengeSent( - accountRepository: AccountRepository, - ticketRepository: TicketRepository, - mfaMethodsEnrollmentAssociation: MfaMethodsEnrollmentAssociation - ) = - VerifyEMailChallenge( - ticketRepository, - accountRepository, - mfaMethodsEnrollmentAssociation - ) - - @Bean - fun verificationMailSender( - javaMailSender: JavaMailSender, - documentRepository: DocumentRepository, - noReplyEMailConfiguration: NoReplyEMailConfiguration - ) = - JavaEMailSenderService( - documentRepository, - javaMailSender, - JinJavaTemplateResolver(Jinjava()), - SimpleEMailMessageFactory( - noReplyEMailConfiguration.from, - noReplyEMailConfiguration.welcomeEMailSubject, - EMailType.EMAIL_VERIFICATION - ) - ) - - @Bean - fun sendVerifyMailChallengeUponSignUpEventConsumer(mailChallenge: SendVerifyEMailChallenge) = - SendVerifyEMailChallengeUponSignUpEventConsumer(mailChallenge) -} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/config/ResetPasswordConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/ResetPasswordConfig.kt deleted file mode 100644 index 50b779ac..00000000 --- a/src/main/kotlin/com/vauthenticator/server/config/ResetPasswordConfig.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.vauthenticator.server.config - -import com.hubspot.jinjava.Jinjava -import com.vauthenticator.document.repository.DocumentRepository -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.communication.NoReplyEMailConfiguration -import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver -import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService -import com.vauthenticator.server.communication.domain.EMailSenderService -import com.vauthenticator.server.communication.domain.EMailType -import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory -import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher -import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository -import com.vauthenticator.server.password.domain.PasswordPolicy -import com.vauthenticator.server.password.domain.VAuthenticatorPasswordEncoder -import com.vauthenticator.server.password.domain.resetpassword.ResetAccountPassword -import com.vauthenticator.server.password.domain.resetpassword.SendResetPasswordMailChallenge -import com.vauthenticator.server.ticket.domain.TicketCreator -import com.vauthenticator.server.ticket.domain.TicketRepository -import org.springframework.beans.factory.annotation.Value -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.mail.javamail.JavaMailSender - -@Configuration(proxyBeanMethods = false) -class ResetPasswordConfig { - - @Bean - fun sendResetPasswordMailChallenge( - accountRepository: AccountRepository, - clientApplicationRepository: ClientApplicationRepository, - ticketCreator: TicketCreator, - resetPasswordMailSender: EMailSenderService, - @Value("\${vauthenticator.host}") frontChannelBaseUrl: String - ) = - SendResetPasswordMailChallenge( - accountRepository, - ticketCreator, - resetPasswordMailSender, - frontChannelBaseUrl - ) - - @Bean - fun resetPasswordChallengeSent( - eventsDispatcher: VAuthenticatorEventsDispatcher, - accountRepository: AccountRepository, - vAuthenticatorPasswordEncoder: VAuthenticatorPasswordEncoder, - passwordPolicy: PasswordPolicy, - ticketRepository: TicketRepository - ) = - ResetAccountPassword(eventsDispatcher, accountRepository, vAuthenticatorPasswordEncoder,passwordPolicy, ticketRepository) - - @Bean - fun resetPasswordMailSender( - javaMailSender: JavaMailSender, - documentRepository: DocumentRepository, - noReplyEMailConfiguration: NoReplyEMailConfiguration - ) = - JavaEMailSenderService( - documentRepository, - javaMailSender, - JinJavaTemplateResolver(Jinjava()), - SimpleEMailMessageFactory( - noReplyEMailConfiguration.from, - noReplyEMailConfiguration.resetPasswordEMailSubject, - EMailType.RESET_PASSWORD - ) - ) - -} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/config/SingUpConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/SingUpConfig.kt deleted file mode 100644 index eb21b254..00000000 --- a/src/main/kotlin/com/vauthenticator/server/config/SingUpConfig.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.vauthenticator.server.config - -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.account.signup.SignUpUse -import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher -import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository -import com.vauthenticator.server.password.domain.PasswordPolicy -import com.vauthenticator.server.password.domain.VAuthenticatorPasswordEncoder -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -@Configuration(proxyBeanMethods = false) -class SingUpConfig { - - @Bean - fun signUpUseCase( - passwordPolicy: PasswordPolicy, - clientAccountRepository: ClientApplicationRepository, - accountRepository: AccountRepository, - vAuthenticatorPasswordEncoder: VAuthenticatorPasswordEncoder, - vAuthenticatorEventsDispatcher : VAuthenticatorEventsDispatcher - ): SignUpUse = - SignUpUse( - passwordPolicy, - accountRepository, - vAuthenticatorPasswordEncoder, - vAuthenticatorEventsDispatcher - ) - -} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/config/WebSecurityConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/WebSecurityConfig.kt index c694b341..5be9951b 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/WebSecurityConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/config/WebSecurityConfig.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.config -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.login.userdetails.AccountUserDetailsService import com.vauthenticator.server.login.workflow.CompositeLoginWorkflowEngine import com.vauthenticator.server.login.workflow.LOGIN_ENGINE_BROKER_PAGE diff --git a/src/main/kotlin/com/vauthenticator/server/config/WelcomeConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/WelcomeConfig.kt deleted file mode 100644 index 97c18d06..00000000 --- a/src/main/kotlin/com/vauthenticator/server/config/WelcomeConfig.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.vauthenticator.server.config - -import com.hubspot.jinjava.Jinjava -import com.vauthenticator.document.repository.DocumentRepository -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.account.welcome.SayWelcome -import com.vauthenticator.server.account.welcome.SendWelcomeMailUponSignUpEventConsumer -import com.vauthenticator.server.communication.NoReplyEMailConfiguration -import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver -import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService -import com.vauthenticator.server.communication.domain.EMailSenderService -import com.vauthenticator.server.communication.domain.EMailType -import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.mail.javamail.JavaMailSender - -@Configuration(proxyBeanMethods = false) -class WelcomeConfig { - - @Bean - fun sayWelcome( - accountRepository: AccountRepository, - welcomeMailSender: EMailSenderService - ) = SayWelcome(accountRepository, welcomeMailSender) - - @Bean - fun welcomeMailSender( - javaMailSender: JavaMailSender, - documentRepository: DocumentRepository, - noReplyEMailConfiguration: NoReplyEMailConfiguration - ) = - JavaEMailSenderService( - documentRepository, - javaMailSender, - JinJavaTemplateResolver(Jinjava()), - SimpleEMailMessageFactory( - noReplyEMailConfiguration.from, - noReplyEMailConfiguration.welcomeEMailSubject, - EMailType.WELCOME - ) - ) - - @Bean - fun sendWelcomeMailUponSignUpEventConsumer(sayWelcome: SayWelcome) = - SendWelcomeMailUponSignUpEventConsumer(sayWelcome) -} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/events/Events.kt b/src/main/kotlin/com/vauthenticator/server/events/Events.kt index ac26a3d8..b60773c1 100644 --- a/src/main/kotlin/com/vauthenticator/server/events/Events.kt +++ b/src/main/kotlin/com/vauthenticator/server/events/Events.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.events -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.password.domain.Password import org.springframework.boot.context.properties.ConfigurationProperties diff --git a/src/main/kotlin/com/vauthenticator/server/config/EventsConfig.kt b/src/main/kotlin/com/vauthenticator/server/events/EventsConfig.kt similarity index 82% rename from src/main/kotlin/com/vauthenticator/server/config/EventsConfig.kt rename to src/main/kotlin/com/vauthenticator/server/events/EventsConfig.kt index d9fffe52..41aa16a2 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/EventsConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/events/EventsConfig.kt @@ -1,9 +1,8 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.events -import com.vauthenticator.server.account.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer -import com.vauthenticator.server.account.signup.SignUpEventConsumer -import com.vauthenticator.server.account.welcome.SendWelcomeMailUponSignUpEventConsumer -import com.vauthenticator.server.events.* +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer +import com.vauthenticator.server.account.domain.signup.SignUpEventConsumer +import com.vauthenticator.server.account.domain.welcome.SendWelcomeMailUponSignUpEventConsumer import com.vauthenticator.server.password.domain.changepassword.ChangePasswordEventConsumer import com.vauthenticator.server.password.domain.resetpassword.ResetPasswordEventConsumer import org.springframework.context.ApplicationEventPublisher diff --git a/src/main/kotlin/com/vauthenticator/server/events/EventsDispatcher.kt b/src/main/kotlin/com/vauthenticator/server/events/EventsDispatcher.kt index 2003ab2a..e98c1689 100644 --- a/src/main/kotlin/com/vauthenticator/server/events/EventsDispatcher.kt +++ b/src/main/kotlin/com/vauthenticator/server/events/EventsDispatcher.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.events -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.extentions.oauth2ClientId import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import jakarta.servlet.http.HttpServletRequest diff --git a/src/main/kotlin/com/vauthenticator/server/extentions/DateExt.kt b/src/main/kotlin/com/vauthenticator/server/extentions/DateExt.kt index 5eec37dd..c7b664e3 100644 --- a/src/main/kotlin/com/vauthenticator/server/extentions/DateExt.kt +++ b/src/main/kotlin/com/vauthenticator/server/extentions/DateExt.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.extentions -import com.vauthenticator.server.account.Date +import com.vauthenticator.server.account.domain.Date import software.amazon.awssdk.services.dynamodb.model.AttributeValue fun Date.asDynamoAttribute() : AttributeValue = AttributeValue.builder().s(this.formattedDate()).build() \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/extentions/PhoneExt.kt b/src/main/kotlin/com/vauthenticator/server/extentions/PhoneExt.kt index c7958d48..84b77fe5 100644 --- a/src/main/kotlin/com/vauthenticator/server/extentions/PhoneExt.kt +++ b/src/main/kotlin/com/vauthenticator/server/extentions/PhoneExt.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.extentions -import com.vauthenticator.server.account.Phone +import com.vauthenticator.server.account.domain.Phone import software.amazon.awssdk.services.dynamodb.model.AttributeValue fun Phone.asDynamoAttribute() : AttributeValue = AttributeValue.builder().s(this.formattedPhone()).build() \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/config/I18nConfig.kt b/src/main/kotlin/com/vauthenticator/server/i18n/I18nConfig.kt similarity index 84% rename from src/main/kotlin/com/vauthenticator/server/config/I18nConfig.kt rename to src/main/kotlin/com/vauthenticator/server/i18n/I18nConfig.kt index 416cab19..b1d3ef8b 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/I18nConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/i18n/I18nConfig.kt @@ -1,8 +1,6 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.i18n import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.i18n.I18nMessageInjector -import com.vauthenticator.server.i18n.I18nMessageRepository import com.vauthenticator.server.web.CurrentHttpServletRequestService import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration diff --git a/src/main/kotlin/com/vauthenticator/server/config/KeyConfig.kt b/src/main/kotlin/com/vauthenticator/server/keys/KeyConfig.kt similarity index 98% rename from src/main/kotlin/com/vauthenticator/server/config/KeyConfig.kt rename to src/main/kotlin/com/vauthenticator/server/keys/KeyConfig.kt index 7efa033c..c13fb96a 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/KeyConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/keys/KeyConfig.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.keys import com.vauthenticator.server.keys.adapter.dynamo.DynamoDbKeyStorage import com.vauthenticator.server.keys.adapter.jdbc.JdbcKeyStorage diff --git a/src/main/kotlin/com/vauthenticator/server/config/LambdaConfig.kt b/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaConfig.kt similarity index 88% rename from src/main/kotlin/com/vauthenticator/server/config/LambdaConfig.kt rename to src/main/kotlin/com/vauthenticator/server/lambdas/LambdaConfig.kt index 72658230..681aed8c 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/LambdaConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaConfig.kt @@ -1,7 +1,6 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.lambdas import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.lambdas.AwsLambdaFunction import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration diff --git a/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaTokenEnhancer.kt b/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaTokenEnhancer.kt index a1f6c3b3..10bfab2d 100644 --- a/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaTokenEnhancer.kt +++ b/src/main/kotlin/com/vauthenticator/server/lambdas/LambdaTokenEnhancer.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.lambdas -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import org.springframework.security.oauth2.server.authorization.token.JwtEncodingContext import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenCustomizer import java.util.* diff --git a/src/main/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsService.kt b/src/main/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsService.kt index 35a72aae..f2ffc904 100644 --- a/src/main/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsService.kt +++ b/src/main/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsService.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.login.userdetails -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.security.core.authority.SimpleGrantedAuthority diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/MfaConfig.kt b/src/main/kotlin/com/vauthenticator/server/mfa/MfaConfig.kt index c24c31f6..24c50c34 100644 --- a/src/main/kotlin/com/vauthenticator/server/mfa/MfaConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/mfa/MfaConfig.kt @@ -2,7 +2,8 @@ package com.vauthenticator.server.mfa import com.hubspot.jinjava.Jinjava import com.vauthenticator.document.repository.DocumentRepository -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.adapter.jdbc.JdbcAccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.NoReplyEMailConfiguration import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService @@ -15,6 +16,7 @@ import com.vauthenticator.server.mask.SensitiveDataMaskerResolver import com.vauthenticator.server.mask.SensitiveEmailMasker import com.vauthenticator.server.mask.SensitivePhoneMasker import com.vauthenticator.server.mfa.adapter.dynamodb.DynamoMfaAccountMethodsRepository +import com.vauthenticator.server.mfa.adapter.jdbc.JdbcMfaAccountMethodsRepository import com.vauthenticator.server.mfa.domain.* import com.vauthenticator.server.ticket.domain.TicketCreator import com.vauthenticator.server.ticket.domain.TicketRepository @@ -22,6 +24,8 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import org.springframework.jdbc.core.JdbcTemplate import org.springframework.mail.javamail.JavaMailSender import software.amazon.awssdk.services.dynamodb.DynamoDbClient import software.amazon.awssdk.services.sns.SnsClient @@ -30,8 +34,9 @@ import java.util.* @Configuration(proxyBeanMethods = false) class MfaConfig { - @Bean - fun mfaAccountMethodsRepository( + @Bean("mfaAccountMethodsRepository") + @Profile("!experimental_database_persistence") + fun dynamoDbMfaAccountMethodsRepository( keyRepository: KeyRepository, dynamoDbClient: DynamoDbClient, @Value("\${key.master-key}") masterKey: String, @@ -46,6 +51,19 @@ class MfaConfig { MasterKid(masterKey) ) { MfaDeviceId(UUID.randomUUID().toString()) } + @Bean("mfaAccountMethodsRepository") + @Profile("experimental_database_persistence") + fun jdbcMfaAccountMethodsRepository( + keyRepository: KeyRepository, + jdbcTemplate: JdbcTemplate, + @Value("\${key.master-key}") masterKey: String + ): MfaAccountMethodsRepository = + JdbcMfaAccountMethodsRepository( + jdbcTemplate, + keyRepository, + MasterKid(masterKey) + ) { MfaDeviceId(UUID.randomUUID().toString()) } + @Bean fun sensitiveEmailMasker() = SensitiveEmailMasker() diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepository.kt b/src/main/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepository.kt new file mode 100644 index 00000000..c1b44b34 --- /dev/null +++ b/src/main/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepository.kt @@ -0,0 +1,100 @@ +package com.vauthenticator.server.mfa.adapter.jdbc + +import com.vauthenticator.server.keys.domain.* +import com.vauthenticator.server.mfa.domain.MfaAccountMethod +import com.vauthenticator.server.mfa.domain.MfaAccountMethodsRepository +import com.vauthenticator.server.mfa.domain.MfaDeviceId +import com.vauthenticator.server.mfa.domain.MfaMethod +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.transaction.annotation.Transactional +import java.sql.ResultSet +import java.util.* + +@Transactional +class JdbcMfaAccountMethodsRepository( + private val jdbcTemplate: JdbcTemplate, + private val keyRepository: KeyRepository, + private val masterKid: MasterKid, + private val mfaDeviceIdGenerator: () -> MfaDeviceId +) : MfaAccountMethodsRepository { + override fun findBy(userName: String, mfaMfaMethod: MfaMethod, mfaChannel: String): Optional = + Optional.ofNullable( + jdbcTemplate.query( + "SELECT * FROM MFA_ACCOUNT_METHODS WHERE user_name=? AND mfa_method=? AND mfa_channel=?", + { rs, _ -> mfaAccountMethodFrom(rs) }, + userName, mfaMfaMethod.name, mfaChannel + ).firstOrNull() + ) + + + override fun findBy(deviceId: MfaDeviceId): Optional = + Optional.ofNullable( + jdbcTemplate.query( + "SELECT * FROM MFA_ACCOUNT_METHODS WHERE mfa_device_id=?", + { rs, _ -> mfaAccountMethodFrom(rs) }, + deviceId.content + ).firstOrNull() + ) + + override fun findAll(userName: String): List = + jdbcTemplate.query("SELECT * FROM MFA_ACCOUNT_METHODS") + { rs, _ -> mfaAccountMethodFrom(rs) } + + + override fun save( + userName: String, + mfaMfaMethod: MfaMethod, + mfaChannel: String, + associated: Boolean + ): MfaAccountMethod { + val kid = keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) + val mfaDeviceId = mfaDeviceIdGenerator.invoke() + + jdbcTemplate.update( + "INSERT INTO MFA_ACCOUNT_METHODS (user_name, mfa_device_id, mfa_method, mfa_channel, key_id, associated) VALUES (?,?,?,?,?,?)", + userName, mfaDeviceId.content, mfaMfaMethod.name, mfaChannel, kid.content(), associated + ) + + return MfaAccountMethod(userName, mfaDeviceId, kid, mfaMfaMethod, mfaChannel, associated) + } + + + override fun setAsDefault(userName: String, deviceId: MfaDeviceId) { + Optional.ofNullable( + jdbcTemplate.query( + "SELECT mfa_device_id FROM MFA_ACCOUNT_METHODS WHERE user_name=? AND default_mfa_method=true", + { rs, _ -> MfaDeviceId(rs.getString("mfa_device_id")) }, + userName + ).firstOrNull() + ).ifPresent { + jdbcTemplate.update( + "UPDATE MFA_ACCOUNT_METHODS SET default_mfa_method = false WHERE user_name=? AND mfa_device_id=?", + userName, it.content + ) + } + + jdbcTemplate.update( + "UPDATE MFA_ACCOUNT_METHODS SET default_mfa_method = true WHERE user_name=? AND mfa_device_id=?", + userName, deviceId.content + ) + } + + override fun getDefaultDevice(userName: String): Optional = + Optional.ofNullable( + jdbcTemplate.query( + "SELECT mfa_device_id FROM MFA_ACCOUNT_METHODS WHERE user_name=? AND default_mfa_method=true", + { rs, _ -> MfaDeviceId(rs.getString("mfa_device_id")) }, + userName + ).firstOrNull() + ) + + private fun mfaAccountMethodFrom(rs: ResultSet) = MfaAccountMethod( + userName = rs.getString("user_name"), + mfaDeviceId = MfaDeviceId(rs.getString("mfa_device_id")), + key = Kid(rs.getString("key_id")), + mfaMethod = MfaMethod.valueOf(rs.getString("mfa_method")), + mfaChannel = rs.getString("mfa_channel"), + associated = rs.getBoolean("associated"), + ) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollment.kt b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollment.kt index c2343107..cdf6cd92 100644 --- a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollment.kt +++ b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollment.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.mask.SensitiveDataMaskerResolver import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.ticket.domain.TicketContext diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaSender.kt b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaSender.kt index 8e286adc..43933aac 100644 --- a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaSender.kt +++ b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaSender.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.communication.domain.SmsSenderService diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaVerifier.kt b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaVerifier.kt index dcbe3d17..5bec68cb 100644 --- a/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaVerifier.kt +++ b/src/main/kotlin/com/vauthenticator/server/mfa/domain/MfaVerifier.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository interface MfaVerifier { fun verifyMfaChallengeToBeAssociatedFor( diff --git a/src/main/kotlin/com/vauthenticator/server/mfa/domain/OtpMfa.kt b/src/main/kotlin/com/vauthenticator/server/mfa/domain/OtpMfa.kt index a1a5f4c3..e1b2738e 100644 --- a/src/main/kotlin/com/vauthenticator/server/mfa/domain/OtpMfa.kt +++ b/src/main/kotlin/com/vauthenticator/server/mfa/domain/OtpMfa.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.mfa.domain import com.j256.twofactorauth.TimeBasedOneTimePasswordUtil -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account import com.vauthenticator.server.extentions.decoder import com.vauthenticator.server.keys.domain.KeyDecrypter import com.vauthenticator.server.keys.domain.KeyPurpose diff --git a/src/main/kotlin/com/vauthenticator/server/config/ClientApplicationConfig.kt b/src/main/kotlin/com/vauthenticator/server/oauth2/clientapp/ClientApplicationConfig.kt similarity index 98% rename from src/main/kotlin/com/vauthenticator/server/config/ClientApplicationConfig.kt rename to src/main/kotlin/com/vauthenticator/server/oauth2/clientapp/ClientApplicationConfig.kt index b6157e0e..b97a3550 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/ClientApplicationConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/oauth2/clientapp/ClientApplicationConfig.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.oauth2.clientapp import com.fasterxml.jackson.databind.ObjectMapper import com.vauthenticator.server.cache.CacheOperation diff --git a/src/main/kotlin/com/vauthenticator/server/oidc/userinfo/UserInfoEnhancer.kt b/src/main/kotlin/com/vauthenticator/server/oidc/userinfo/UserInfoEnhancer.kt index 3b0bc105..bdd378ee 100644 --- a/src/main/kotlin/com/vauthenticator/server/oidc/userinfo/UserInfoEnhancer.kt +++ b/src/main/kotlin/com/vauthenticator/server/oidc/userinfo/UserInfoEnhancer.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.oidc.userinfo -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRepository import org.springframework.security.oauth2.core.oidc.OidcUserInfo import org.springframework.security.oauth2.server.authorization.oidc.authentication.OidcUserInfoAuthenticationContext import java.time.LocalDateTime diff --git a/src/main/kotlin/com/vauthenticator/server/config/PasswordConfig.kt b/src/main/kotlin/com/vauthenticator/server/password/PasswordConfig.kt similarity index 57% rename from src/main/kotlin/com/vauthenticator/server/config/PasswordConfig.kt rename to src/main/kotlin/com/vauthenticator/server/password/PasswordConfig.kt index 09f511e2..e734e529 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/PasswordConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/PasswordConfig.kt @@ -1,17 +1,31 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.password -import com.vauthenticator.server.account.repository.AccountRepository +import com.hubspot.jinjava.Jinjava +import com.vauthenticator.document.repository.DocumentRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.communication.NoReplyEMailConfiguration +import com.vauthenticator.server.communication.adapter.JinJavaTemplateResolver +import com.vauthenticator.server.communication.adapter.javamail.JavaEMailSenderService +import com.vauthenticator.server.communication.domain.EMailSenderService +import com.vauthenticator.server.communication.domain.EMailType +import com.vauthenticator.server.communication.domain.SimpleEMailMessageFactory import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher +import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository import com.vauthenticator.server.password.adapter.dynamodb.DynamoPasswordHistoryRepository import com.vauthenticator.server.password.domain.* import com.vauthenticator.server.password.domain.changepassword.ChangePassword import com.vauthenticator.server.password.domain.changepassword.ChangePasswordEventConsumer +import com.vauthenticator.server.password.domain.resetpassword.ResetAccountPassword import com.vauthenticator.server.password.domain.resetpassword.ResetPasswordEventConsumer +import com.vauthenticator.server.password.domain.resetpassword.SendResetPasswordMailChallenge +import com.vauthenticator.server.ticket.domain.TicketCreator +import com.vauthenticator.server.ticket.domain.TicketRepository import org.springframework.beans.factory.annotation.Value import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.mail.javamail.JavaMailSender import software.amazon.awssdk.services.dynamodb.DynamoDbClient import java.time.Clock @@ -88,4 +102,52 @@ data class PasswordPolicyConfigProp( val minSize: Int, val minSpecialSymbol: Int, val enablePasswordReusePrevention: Boolean -) \ No newline at end of file +) + + +@Configuration(proxyBeanMethods = false) +class ResetPasswordConfig { + + @Bean + fun sendResetPasswordMailChallenge( + accountRepository: AccountRepository, + clientApplicationRepository: ClientApplicationRepository, + ticketCreator: TicketCreator, + resetPasswordMailSender: EMailSenderService, + @Value("\${vauthenticator.host}") frontChannelBaseUrl: String + ) = + SendResetPasswordMailChallenge( + accountRepository, + ticketCreator, + resetPasswordMailSender, + frontChannelBaseUrl + ) + + @Bean + fun resetPasswordChallengeSent( + eventsDispatcher: VAuthenticatorEventsDispatcher, + accountRepository: AccountRepository, + vAuthenticatorPasswordEncoder: VAuthenticatorPasswordEncoder, + passwordPolicy: PasswordPolicy, + ticketRepository: TicketRepository + ) = + ResetAccountPassword(eventsDispatcher, accountRepository, vAuthenticatorPasswordEncoder,passwordPolicy, ticketRepository) + + @Bean + fun resetPasswordMailSender( + javaMailSender: JavaMailSender, + documentRepository: DocumentRepository, + noReplyEMailConfiguration: NoReplyEMailConfiguration + ) = + JavaEMailSenderService( + documentRepository, + javaMailSender, + JinJavaTemplateResolver(Jinjava()), + SimpleEMailMessageFactory( + noReplyEMailConfiguration.from, + noReplyEMailConfiguration.resetPasswordEMailSubject, + EMailType.RESET_PASSWORD + ) + ) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPoint.kt b/src/main/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPoint.kt index 13d83194..620f15c8 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPoint.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPoint.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.api -import com.vauthenticator.server.account.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountNotFoundException import com.vauthenticator.server.password.domain.PasswordPolicyViolation import com.vauthenticator.server.password.domain.changepassword.ChangePassword import com.vauthenticator.server.password.domain.changepassword.ChangePasswordRequest diff --git a/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePassword.kt b/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePassword.kt index 3735a425..7128e40c 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePassword.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePassword.kt @@ -1,8 +1,8 @@ package com.vauthenticator.server.password.domain.changepassword -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.Email -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.events.ChangePasswordEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandler.kt b/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandler.kt index 9fcd63df..79bbf8f8 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandler.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandler.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.domain.changepassword -import com.vauthenticator.server.account.AccountMandatoryAction -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountMandatoryAction +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.login.workflow.LoginWorkflowHandler import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse diff --git a/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPassword.kt b/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPassword.kt index dfda1426..2682f83a 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPassword.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPassword.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.domain.resetpassword -import com.vauthenticator.server.account.Email -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.events.ResetPasswordEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallenge.kt b/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallenge.kt index ec4f0ddc..2560d671 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallenge.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallenge.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.domain.resetpassword -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.ticket.domain.TicketCreator diff --git a/src/main/kotlin/com/vauthenticator/server/password/web/ChangePasswordController.kt b/src/main/kotlin/com/vauthenticator/server/password/web/ChangePasswordController.kt index a8e59880..06b245d9 100644 --- a/src/main/kotlin/com/vauthenticator/server/password/web/ChangePasswordController.kt +++ b/src/main/kotlin/com/vauthenticator/server/password/web/ChangePasswordController.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.web -import com.vauthenticator.server.account.AccountMandatoryAction -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountMandatoryAction +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.i18n.I18nMessageInjector import com.vauthenticator.server.i18n.I18nScope import com.vauthenticator.server.password.domain.changepassword.* diff --git a/src/main/kotlin/com/vauthenticator/server/config/PermissionConfig.kt b/src/main/kotlin/com/vauthenticator/server/role/PermissionConfig.kt similarity index 98% rename from src/main/kotlin/com/vauthenticator/server/config/PermissionConfig.kt rename to src/main/kotlin/com/vauthenticator/server/role/PermissionConfig.kt index 94f5b419..57e17eef 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/PermissionConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/role/PermissionConfig.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.role import com.fasterxml.jackson.databind.ObjectMapper import com.vauthenticator.server.cache.CacheOperation diff --git a/src/main/kotlin/com/vauthenticator/server/config/TicketConfig.kt b/src/main/kotlin/com/vauthenticator/server/ticket/TicketConfig.kt similarity index 97% rename from src/main/kotlin/com/vauthenticator/server/config/TicketConfig.kt rename to src/main/kotlin/com/vauthenticator/server/ticket/TicketConfig.kt index 33e61489..803129cd 100644 --- a/src/main/kotlin/com/vauthenticator/server/config/TicketConfig.kt +++ b/src/main/kotlin/com/vauthenticator/server/ticket/TicketConfig.kt @@ -1,4 +1,4 @@ -package com.vauthenticator.server.config +package com.vauthenticator.server.ticket import com.fasterxml.jackson.databind.ObjectMapper import com.vauthenticator.server.ticket.adapter.dynamodb.DynamoDbTicketRepository diff --git a/src/main/kotlin/com/vauthenticator/server/ticket/domain/TicketCreator.kt b/src/main/kotlin/com/vauthenticator/server/ticket/domain/TicketCreator.kt index 5cd7a83b..61fa0b8b 100644 --- a/src/main/kotlin/com/vauthenticator/server/ticket/domain/TicketCreator.kt +++ b/src/main/kotlin/com/vauthenticator/server/ticket/domain/TicketCreator.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.ticket.domain -import com.vauthenticator.server.account.Account +import com.vauthenticator.server.account.domain.Account import com.vauthenticator.server.extentions.expirationTimeStampInSecondFromNow import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import java.time.Clock diff --git a/src/main/resources/data/schema.sql b/src/main/resources/data/schema.sql index 65c2f079..5f691314 100644 --- a/src/main/resources/data/schema.sql +++ b/src/main/resources/data/schema.sql @@ -62,13 +62,27 @@ CREATE TABLE TICKET CREATE TABLE PASSWORD_HISTORY ( - user_name varchar(255) not null , - created_at bigint not null default 0, - password varchar(255) not null, + user_name varchar(255) not null, + created_at bigint not null default 0, + password varchar(255) not null, primary key (user_name, password) ); +CREATE TABLE MFA_ACCOUNT_METHODS +( + user_name varchar(255) not null, + mfa_device_id varchar(255) not null, + mfa_method varchar(255) not null, + mfa_channel varchar(255) not null, + key_id varchar(255) not null, + associated varchar(255) not null, + default_mfa_method boolean default false, + + primary key (user_name, mfa_channel) +); + +CREATE INDEX mfa_account_methods_mfa_device_id ON MFA_ACCOUNT_METHODS (mfa_device_id); CREATE TABLE CLIENT_APPLICATION ( diff --git a/src/test/kotlin/com/vauthenticator/server/account/repository/AbstractAccountRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/account/adapter/AbstractAccountRepositoryTest.kt similarity index 91% rename from src/test/kotlin/com/vauthenticator/server/account/repository/AbstractAccountRepositoryTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/adapter/AbstractAccountRepositoryTest.kt index 61a206c8..c03d7ae1 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/repository/AbstractAccountRepositoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/adapter/AbstractAccountRepositoryTest.kt @@ -1,7 +1,9 @@ -package com.vauthenticator.server.account.repository +package com.vauthenticator.server.account.adapter -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.AccountMandatoryAction.RESET_PASSWORD +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountMandatoryAction.RESET_PASSWORD +import com.vauthenticator.server.account.domain.AccountRegistrationException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.role.domain.Role import com.vauthenticator.server.role.domain.RoleRepository import com.vauthenticator.server.support.AccountTestFixture.anAccount diff --git a/src/test/kotlin/com/vauthenticator/server/account/AccountCacheContentConverterTest.kt b/src/test/kotlin/com/vauthenticator/server/account/adapter/AccountCacheContentConverterTest.kt similarity index 87% rename from src/test/kotlin/com/vauthenticator/server/account/AccountCacheContentConverterTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/adapter/AccountCacheContentConverterTest.kt index 6018a65c..6d3a67e7 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/AccountCacheContentConverterTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/adapter/AccountCacheContentConverterTest.kt @@ -1,6 +1,10 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.adapter import com.fasterxml.jackson.databind.ObjectMapper +import com.vauthenticator.server.account.domain.AccountCacheContentConverter +import com.vauthenticator.server.account.domain.Date +import com.vauthenticator.server.account.domain.Phone +import com.vauthenticator.server.account.domain.UserLocale import com.vauthenticator.server.support.AccountTestFixture.anAccount import com.vauthenticator.server.support.JsonUtils.prettifyInOneLineJsonFrom import org.junit.jupiter.api.Assertions diff --git a/src/test/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepositoryTest.kt similarity index 93% rename from src/test/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepositoryTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepositoryTest.kt index 196f8deb..7ee2b54e 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/repository/CachedAccountRepositoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/adapter/CachedAccountRepositoryTest.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.repository +package com.vauthenticator.server.account.adapter -import com.vauthenticator.server.account.AccountCacheContentConverter +import com.vauthenticator.server.account.domain.AccountCacheContentConverter +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.cache.CacheOperation import com.vauthenticator.server.support.AccountTestFixture.anAccount import io.mockk.every diff --git a/src/test/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt similarity index 83% rename from src/test/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt index 1101ba84..ae70ce81 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/repository/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/adapter/dynamodb/DynamoDbAbstractAccountRepositoryTest.kt @@ -1,7 +1,7 @@ -package com.vauthenticator.server.account.repository.dynamodb +package com.vauthenticator.server.account.adapter.dynamodb -import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.adapter.AbstractAccountRepositoryTest import com.vauthenticator.server.role.adapter.dynamodb.DynamoDbRoleRepository import com.vauthenticator.server.role.domain.RoleRepository import com.vauthenticator.server.support.DynamoDbUtils.dynamoAccountTableName diff --git a/src/test/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepositoryTest.kt similarity index 76% rename from src/test/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepositoryTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepositoryTest.kt index c2710fcf..9042c7b1 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/repository/jdbc/JdbcAccountRepositoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/adapter/jdbc/JdbcAccountRepositoryTest.kt @@ -1,7 +1,7 @@ -package com.vauthenticator.server.account.repository.jdbc +package com.vauthenticator.server.account.adapter.jdbc -import com.vauthenticator.server.account.repository.AbstractAccountRepositoryTest -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.adapter.AbstractAccountRepositoryTest import com.vauthenticator.server.role.adapter.jdbc.JdbcRoleRepository import com.vauthenticator.server.role.domain.RoleRepository import com.vauthenticator.server.support.JdbcUtils.jdbcTemplate diff --git a/src/test/kotlin/com/vauthenticator/server/account/api/AccountEndPointTest.kt b/src/test/kotlin/com/vauthenticator/server/account/api/AccountEndPointTest.kt index 12ba8f73..62de7d6a 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/api/AccountEndPointTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/api/AccountEndPointTest.kt @@ -1,10 +1,10 @@ package com.vauthenticator.server.account.api import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.account.Phone -import com.vauthenticator.server.account.SaveAccount -import com.vauthenticator.server.account.repository.AccountRepository -import com.vauthenticator.server.account.signup.SignUpUse +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.Phone +import com.vauthenticator.server.account.domain.SaveAccount +import com.vauthenticator.server.account.domain.signup.SignUpUse import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository import com.vauthenticator.server.oauth2.clientapp.domain.Scope diff --git a/src/test/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPointTest.kt b/src/test/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPointTest.kt index 728d04af..f1bc994f 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPointTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/api/AdminApiAccountEndPointTest.kt @@ -1,9 +1,9 @@ package com.vauthenticator.server.account.api import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.account.AccountUpdateAdminAction -import com.vauthenticator.server.account.AdminAccountApiRequest -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.AccountUpdateAdminAction +import com.vauthenticator.server.account.domain.AdminAccountApiRequest import com.vauthenticator.server.support.AccountTestFixture import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationEndPointTest.kt b/src/test/kotlin/com/vauthenticator/server/account/api/MailVerificationEndPointTest.kt similarity index 96% rename from src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationEndPointTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/api/MailVerificationEndPointTest.kt index 0dac5b3d..2d348498 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationEndPointTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/api/MailVerificationEndPointTest.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.api import com.fasterxml.jackson.databind.ObjectMapper +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallenge import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository import com.vauthenticator.server.oauth2.clientapp.domain.Scope import com.vauthenticator.server.role.domain.PermissionValidator diff --git a/src/test/kotlin/com/vauthenticator/server/account/welcome/WelcomeEMailEndPointTest.kt b/src/test/kotlin/com/vauthenticator/server/account/api/WelcomeEMailEndPointTest.kt similarity index 92% rename from src/test/kotlin/com/vauthenticator/server/account/welcome/WelcomeEMailEndPointTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/api/WelcomeEMailEndPointTest.kt index e6d89109..2c8acca5 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/welcome/WelcomeEMailEndPointTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/api/WelcomeEMailEndPointTest.kt @@ -1,7 +1,8 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.api import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.account.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.welcome.SayWelcome import com.vauthenticator.server.oauth2.clientapp.domain.ClientApplicationRepository import com.vauthenticator.server.oauth2.clientapp.domain.Scope import com.vauthenticator.server.role.domain.PermissionValidator @@ -72,7 +73,9 @@ internal class WelcomeEMailEndPointTest { @Test internal fun `no account found`() { - every { sayWelcome.welcome(EMAIL) } throws AccountNotFoundException("") + every { sayWelcome.welcome(EMAIL) } throws AccountNotFoundException( + "" + ) mokMvc.perform( put("/api/sign-up/welcome") diff --git a/src/test/kotlin/com/vauthenticator/server/account/AccountUpdateAdminActionTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminActionTest.kt similarity index 94% rename from src/test/kotlin/com/vauthenticator/server/account/AccountUpdateAdminActionTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminActionTest.kt index 368bff91..a2fd5467 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/AccountUpdateAdminActionTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/AccountUpdateAdminActionTest.kt @@ -1,6 +1,5 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.domain -import com.vauthenticator.server.account.repository.AccountRepository import com.vauthenticator.server.support.AccountTestFixture.anAccount import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/src/test/kotlin/com/vauthenticator/server/account/SaveAccountTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/SaveAccountTest.kt similarity index 93% rename from src/test/kotlin/com/vauthenticator/server/account/SaveAccountTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/SaveAccountTest.kt index 7a0cc7a5..2a03fcb8 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/SaveAccountTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/SaveAccountTest.kt @@ -1,6 +1,5 @@ -package com.vauthenticator.server.account +package com.vauthenticator.server.account.domain -import com.vauthenticator.server.account.repository.AccountRepository import com.vauthenticator.server.support.AccountTestFixture.anAccount import com.vauthenticator.server.support.SecurityFixture import io.mockk.every diff --git a/src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeTest.kt similarity index 91% rename from src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeTest.kt index 61c3dd12..20a8f1dc 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeTest.kt @@ -1,7 +1,8 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallenge import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.mfa.domain.MfaMethod import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollment diff --git a/src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt similarity index 76% rename from src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt index 7169bb7b..b088eb50 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/SendVerifyEMailChallengeUponSignUpEventConsumerTest.kt @@ -1,5 +1,7 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallenge +import com.vauthenticator.server.account.domain.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer import com.vauthenticator.server.events.EventFixture.signUpEvent import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/src/test/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallengeTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallengeTest.kt similarity index 93% rename from src/test/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallengeTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallengeTest.kt index 7a7739a3..5ab352b4 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/emailverification/VerifyEMailChallengeTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/emailverification/VerifyEMailChallengeTest.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.domain.emailverification -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.emailverification.VerifyEMailChallenge import com.vauthenticator.server.mfa.domain.MfaMethodsEnrollmentAssociation import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.support.AccountTestFixture diff --git a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumerTest.kt similarity index 86% rename from src/test/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumerTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumerTest.kt index 80f2cd7f..af7db125 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpEventConsumerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpEventConsumerTest.kt @@ -1,6 +1,7 @@ -package com.vauthenticator.server.account.signup +package com.vauthenticator.server.account.domain.signup -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email +import com.vauthenticator.server.account.domain.signup.SignUpEventConsumer import com.vauthenticator.server.events.SignUpEvent import com.vauthenticator.server.password.domain.Password import com.vauthenticator.server.password.domain.PasswordHistoryRepository diff --git a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpUseTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUseTest.kt similarity index 91% rename from src/test/kotlin/com/vauthenticator/server/account/signup/SignUpUseTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUseTest.kt index 05d092f7..374c990b 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpUseTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/signup/SignUpUseTest.kt @@ -1,7 +1,8 @@ -package com.vauthenticator.server.account.signup +package com.vauthenticator.server.account.domain.signup -import com.vauthenticator.server.account.Email -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.Email +import com.vauthenticator.server.account.domain.signup.SignUpUse import com.vauthenticator.server.events.SignUpEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/test/kotlin/com/vauthenticator/server/account/welcome/SayWelcomeTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcomeTest.kt similarity index 86% rename from src/test/kotlin/com/vauthenticator/server/account/welcome/SayWelcomeTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcomeTest.kt index 897de0ec..1086d727 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/welcome/SayWelcomeTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SayWelcomeTest.kt @@ -1,7 +1,8 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.domain.welcome -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository +import com.vauthenticator.server.account.domain.welcome.SayWelcome import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.support.AccountTestFixture import io.mockk.every diff --git a/src/test/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt similarity index 79% rename from src/test/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt index b21923d9..3986579e 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/domain/welcome/SendWelcomeMailUponSignUpEventConsumerTest.kt @@ -1,5 +1,7 @@ -package com.vauthenticator.server.account.welcome +package com.vauthenticator.server.account.domain.welcome +import com.vauthenticator.server.account.domain.welcome.SayWelcome +import com.vauthenticator.server.account.domain.welcome.SendWelcomeMailUponSignUpEventConsumer import com.vauthenticator.server.events.EventFixture.signUpEvent import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpControllerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpControllerTest.kt deleted file mode 100644 index ed6a21dd..00000000 --- a/src/test/kotlin/com/vauthenticator/server/account/signup/SignUpControllerTest.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.vauthenticator.server.account.signup - -//TODO -class SignUpControllerTest \ No newline at end of file diff --git a/src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationControllerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/web/MailVerificationControllerTest.kt similarity index 91% rename from src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationControllerTest.kt rename to src/test/kotlin/com/vauthenticator/server/account/web/MailVerificationControllerTest.kt index bd6f8136..e3fb4919 100644 --- a/src/test/kotlin/com/vauthenticator/server/account/emailverification/MailVerificationControllerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/account/web/MailVerificationControllerTest.kt @@ -1,5 +1,6 @@ -package com.vauthenticator.server.account.emailverification +package com.vauthenticator.server.account.web +import com.vauthenticator.server.account.domain.emailverification.VerifyEMailChallenge import com.vauthenticator.server.i18n.I18nMessageInjector import com.vauthenticator.server.i18n.I18nScope import io.mockk.every diff --git a/src/test/kotlin/com/vauthenticator/server/account/web/SignUpControllerTest.kt b/src/test/kotlin/com/vauthenticator/server/account/web/SignUpControllerTest.kt new file mode 100644 index 00000000..76f63aba --- /dev/null +++ b/src/test/kotlin/com/vauthenticator/server/account/web/SignUpControllerTest.kt @@ -0,0 +1,4 @@ +package com.vauthenticator.server.account.web + +//TODO +class SignUpControllerTest \ No newline at end of file diff --git a/src/test/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderServiceTest.kt b/src/test/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderServiceTest.kt index 5c9f9f2c..1716d02e 100644 --- a/src/test/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderServiceTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/communication/adapter/sns/SnsSmsSenderServiceTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.communication.adapter.sns -import com.vauthenticator.server.account.Phone.Companion.phoneFor +import com.vauthenticator.server.account.domain.Phone.Companion.phoneFor import com.vauthenticator.server.communication.domain.SmsMessage import com.vauthenticator.server.communication.domain.SmsMessageFactory import com.vauthenticator.server.support.AccountTestFixture.anAccount diff --git a/src/test/kotlin/com/vauthenticator/server/events/EventFixture.kt b/src/test/kotlin/com/vauthenticator/server/events/EventFixture.kt index ef7cfc80..4581771e 100644 --- a/src/test/kotlin/com/vauthenticator/server/events/EventFixture.kt +++ b/src/test/kotlin/com/vauthenticator/server/events/EventFixture.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.events -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.password.domain.Password import com.vauthenticator.server.support.A_CLIENT_APP_ID diff --git a/src/test/kotlin/com/vauthenticator/server/lambdas/AwsLambdaFunctionContextFactoryTest.kt b/src/test/kotlin/com/vauthenticator/server/lambdas/AwsLambdaFunctionContextFactoryTest.kt index d1016d7c..a06930bb 100644 --- a/src/test/kotlin/com/vauthenticator/server/lambdas/AwsLambdaFunctionContextFactoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/lambdas/AwsLambdaFunctionContextFactoryTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.lambdas -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.extentions.toSha256 import com.vauthenticator.server.support.AccountTestFixture.anAccount import com.vauthenticator.server.support.EMAIL diff --git a/src/test/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsServiceTest.kt b/src/test/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsServiceTest.kt index 32bc4084..d3e48462 100644 --- a/src/test/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsServiceTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/login/userdetails/AccountUserDetailsServiceTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.login.userdetails -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.support.AccountTestFixture import io.mockk.every import io.mockk.impl.annotations.MockK diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/adapter/AbstractMfaAccountMethodsRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/AbstractMfaAccountMethodsRepositoryTest.kt new file mode 100644 index 00000000..fb2687b6 --- /dev/null +++ b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/AbstractMfaAccountMethodsRepositoryTest.kt @@ -0,0 +1,98 @@ +package com.vauthenticator.server.mfa.adapter + +import com.vauthenticator.server.keys.domain.* +import com.vauthenticator.server.mfa.domain.MfaAccountMethod +import com.vauthenticator.server.mfa.domain.MfaAccountMethodsRepository +import com.vauthenticator.server.mfa.domain.MfaDeviceId +import com.vauthenticator.server.mfa.domain.MfaMethod +import com.vauthenticator.server.support.AccountTestFixture.anAccount +import io.mockk.every +import io.mockk.impl.annotations.MockK +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import java.util.* + +abstract class AbstractMfaAccountMethodsRepositoryTest { + + val mfaDeviceId = MfaDeviceId("A_MFA_DEVICE_ID") + val masterKid = MasterKid("") + val email = anAccount().email + val key = Kid("") + + @MockK + lateinit var keyRepository: KeyRepository + + lateinit var uut: MfaAccountMethodsRepository + abstract fun initMfaAccountMethodsRepository(): MfaAccountMethodsRepository + abstract fun resetDatabase() + @BeforeEach + fun setUp() { + + resetDatabase() + uut = initMfaAccountMethodsRepository() + } + + @Test + fun `when a mfa account method is stored`() { + every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns key + + uut.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) + val mfaAccountMethods = uut.findAll(email) + assertEquals( + listOf(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), + mfaAccountMethods + ) + } + + @Test + fun `when a mfa account do not have method stored`() { + val mfaAccountMethods = uut.findAll(email) + assertEquals(emptyList(), mfaAccountMethods) + } + + @Test + fun `when try to get one specific enrolment association`() { + every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns Kid("") + + uut.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) + val mfaAccountMethods = uut.findBy(email, MfaMethod.EMAIL_MFA_METHOD, email) + assertEquals( + Optional.of(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), + mfaAccountMethods + ) + } + + @Test + fun `when one specific mfa account method is found by device id`() { + every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns Kid("") + + val savedMfaAccountMethod = uut.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) + val mfaAccountMethods = uut.findBy(savedMfaAccountMethod.mfaDeviceId) + + assertEquals( + Optional.of(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), + mfaAccountMethods + ) + + } + + @Test + fun `when one specific enrolment association is not found`() { + val mfaAccountMethods = uut.findBy(email, MfaMethod.EMAIL_MFA_METHOD, email) + val expected = Optional.empty() + assertEquals(expected, mfaAccountMethods) + } + + @Test + fun `when decide what mfa use as default`() { + every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns key + uut.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) + + val expected = Optional.of(mfaDeviceId) + uut.setAsDefault(email, mfaDeviceId) + val defaultDevice = uut.getDefaultDevice(email) + + assertEquals(expected, defaultDevice) + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/adapter/dynamodb/DynamoMfaAccountMethodsRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/dynamodb/DynamoMfaAccountMethodsRepositoryTest.kt index e713c078..db7d4275 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/adapter/dynamodb/DynamoMfaAccountMethodsRepositoryTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/dynamodb/DynamoMfaAccountMethodsRepositoryTest.kt @@ -1,107 +1,27 @@ package com.vauthenticator.server.mfa.adapter.dynamodb -import com.vauthenticator.server.keys.domain.* -import com.vauthenticator.server.mfa.domain.MfaAccountMethod +import com.vauthenticator.server.mfa.adapter.AbstractMfaAccountMethodsRepositoryTest import com.vauthenticator.server.mfa.domain.MfaAccountMethodsRepository -import com.vauthenticator.server.mfa.domain.MfaDeviceId -import com.vauthenticator.server.mfa.domain.MfaMethod -import com.vauthenticator.server.support.AccountTestFixture.anAccount import com.vauthenticator.server.support.DynamoDbUtils.dynamoDbClient import com.vauthenticator.server.support.DynamoDbUtils.dynamoDefaultMfaAccountMethodsTableName import com.vauthenticator.server.support.DynamoDbUtils.dynamoMfaAccountMethodsTableName import com.vauthenticator.server.support.DynamoDbUtils.resetDynamoDb -import io.mockk.every -import io.mockk.impl.annotations.MockK import io.mockk.junit5.MockKExtension -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import java.util.* @ExtendWith(MockKExtension::class) -class DynamoMfaAccountMethodsRepositoryTest { +class DynamoMfaAccountMethodsRepositoryTest : AbstractMfaAccountMethodsRepositoryTest() { - private val mfaDeviceId = MfaDeviceId("A_MFA_DEVICE_ID") - private val masterKid = MasterKid("") - private val email = anAccount().email - private val key = Kid("") - - @MockK - lateinit var keyRepository: KeyRepository - - lateinit var underTest: MfaAccountMethodsRepository - - @BeforeEach - fun setUp() { - - resetDynamoDb() - underTest = DynamoMfaAccountMethodsRepository( + override fun initMfaAccountMethodsRepository() = + DynamoMfaAccountMethodsRepository( dynamoMfaAccountMethodsTableName, dynamoDefaultMfaAccountMethodsTableName, dynamoDbClient, keyRepository, masterKid ) { mfaDeviceId } - } - - @Test - fun `when a mfa account method is stored`() { - every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns key - - underTest.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) - val mfaAccountMethods = underTest.findAll(email) - assertEquals( - listOf(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), - mfaAccountMethods - ) - } - - @Test - fun `when a mfa account do not have method stored`() { - val mfaAccountMethods = underTest.findAll(email) - assertEquals(emptyList(), mfaAccountMethods) - } - - @Test - fun `when try to get one specific enrolment association`() { - every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns Kid("") - underTest.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) - val mfaAccountMethods = underTest.findBy(email, MfaMethod.EMAIL_MFA_METHOD, email) - assertEquals( - Optional.of(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), - mfaAccountMethods - ) - } - - @Test - fun `when one specific mfa account method is found by device id`() { - every { keyRepository.createKeyFrom(masterKid, KeyType.SYMMETRIC, KeyPurpose.MFA) } returns Kid("") - - val savedMfaAccountMethod = underTest.save(email, MfaMethod.EMAIL_MFA_METHOD, email, true) - val mfaAccountMethods = underTest.findBy(savedMfaAccountMethod.mfaDeviceId) - - assertEquals( - Optional.of(MfaAccountMethod(email, mfaDeviceId, key, MfaMethod.EMAIL_MFA_METHOD, email, true)), - mfaAccountMethods - ) - - } - - @Test - fun `when one specific enrolment association is not found`() { - val mfaAccountMethods = underTest.findBy(email, MfaMethod.EMAIL_MFA_METHOD, email) - val expected = Optional.empty() - assertEquals(expected, mfaAccountMethods) - } - - @Test - fun `when decide what mfa use as default`() { - val expected = Optional.of(mfaDeviceId) - underTest.setAsDefault(email, mfaDeviceId) - val defaultDevice = underTest.getDefaultDevice(email) - - assertEquals(expected, defaultDevice) + override fun resetDatabase() { + resetDynamoDb() } } \ No newline at end of file diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepositoryTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepositoryTest.kt new file mode 100644 index 00000000..c9f4710c --- /dev/null +++ b/src/test/kotlin/com/vauthenticator/server/mfa/adapter/jdbc/JdbcMfaAccountMethodsRepositoryTest.kt @@ -0,0 +1,22 @@ +package com.vauthenticator.server.mfa.adapter.jdbc + +import com.vauthenticator.server.mfa.adapter.AbstractMfaAccountMethodsRepositoryTest +import com.vauthenticator.server.support.JdbcUtils.jdbcTemplate +import com.vauthenticator.server.support.JdbcUtils.resetDb +import io.mockk.junit5.MockKExtension +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(MockKExtension::class) +class JdbcMfaAccountMethodsRepositoryTest : AbstractMfaAccountMethodsRepositoryTest() { + override fun initMfaAccountMethodsRepository() = JdbcMfaAccountMethodsRepository( + jdbcTemplate, + keyRepository, + masterKid + ) { mfaDeviceId } + + + override fun resetDatabase() { + resetDb() + } + +} \ No newline at end of file diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/domain/EmailMfaChallengeSenderTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/domain/EmailMfaChallengeSenderTest.kt index e2f90b14..e8099dd7 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/domain/EmailMfaChallengeSenderTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/domain/EmailMfaChallengeSenderTest.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.Account -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.Account +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.communication.domain.SmsSenderService import com.vauthenticator.server.support.MfaFixture.account diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollmentTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollmentTest.kt index 2b699625..4192853c 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollmentTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/domain/MfaMethodsEnrollmentTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.mask.SensitiveDataMaskerResolver import com.vauthenticator.server.mask.SensitiveEmailMasker import com.vauthenticator.server.mfa.domain.MfaMethod.EMAIL_MFA_METHOD diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierAssociationTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierAssociationTest.kt index 6b9fb984..30018931 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierAssociationTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierAssociationTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.support.MfaFixture.account import com.vauthenticator.server.support.MfaFixture.associatedMfaAccountMethod import com.vauthenticator.server.support.MfaFixture.challenge diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithDefaultMfaDeviceTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithDefaultMfaDeviceTest.kt index fd49c652..715199ad 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithDefaultMfaDeviceTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithDefaultMfaDeviceTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.support.MfaFixture.account import com.vauthenticator.server.support.MfaFixture.associatedMfaAccountMethod import com.vauthenticator.server.support.MfaFixture.challenge diff --git a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithoutDefaultMfaDeviceTest.kt b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithoutDefaultMfaDeviceTest.kt index 0448b97b..4b9485e6 100644 --- a/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithoutDefaultMfaDeviceTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/mfa/domain/OtpMfaVerifierWithoutDefaultMfaDeviceTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.mfa.domain -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.support.MfaFixture.account import com.vauthenticator.server.support.MfaFixture.challenge import com.vauthenticator.server.support.MfaFixture.email diff --git a/src/test/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPointTest.kt b/src/test/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPointTest.kt index 4ce8e085..38c9a9a6 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPointTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/api/ChangePasswordEndPointTest.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.api import com.fasterxml.jackson.databind.ObjectMapper -import com.vauthenticator.server.account.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountNotFoundException import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.oauth2.clientapp.domain.Scope import com.vauthenticator.server.password.domain.PasswordPolicyViolation diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordEventConsumerTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordEventConsumerTest.kt index 3e8c316d..c1f5fc2d 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordEventConsumerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordEventConsumerTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.domain.changepassword -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.events.ChangePasswordEvent import com.vauthenticator.server.password.domain.Password import com.vauthenticator.server.password.domain.PasswordHistoryRepository diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandlerTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandlerTest.kt index 1b908ee6..50f12ed9 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandlerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordLoginWorkflowHandlerTest.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.domain.changepassword -import com.vauthenticator.server.account.AccountMandatoryAction.RESET_PASSWORD -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountMandatoryAction.RESET_PASSWORD +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.support.AccountTestFixture import com.vauthenticator.server.support.SecurityFixture.principalFor import io.mockk.every diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordTest.kt index 7ee7c268..cb93c583 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/changepassword/ChangePasswordTest.kt @@ -1,7 +1,7 @@ package com.vauthenticator.server.password.domain.changepassword -import com.vauthenticator.server.account.AccountNotFoundException -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountNotFoundException +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.events.ChangePasswordEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPasswordTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPasswordTest.kt index 4d58a7d7..1fdfd3b6 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPasswordTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetAccountPasswordTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.domain.resetpassword -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.events.ResetPasswordEvent import com.vauthenticator.server.events.VAuthenticatorEventsDispatcher import com.vauthenticator.server.password.api.ResetPasswordRequest diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetPasswordEventConsumerTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetPasswordEventConsumerTest.kt index d16fd924..522e0881 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetPasswordEventConsumerTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/ResetPasswordEventConsumerTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.domain.resetpassword -import com.vauthenticator.server.account.Email +import com.vauthenticator.server.account.domain.Email import com.vauthenticator.server.events.ResetPasswordEvent import com.vauthenticator.server.password.domain.Password import com.vauthenticator.server.password.domain.PasswordHistoryRepository diff --git a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallengeTest.kt b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallengeTest.kt index c95efc45..9a18f608 100644 --- a/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallengeTest.kt +++ b/src/test/kotlin/com/vauthenticator/server/password/domain/resetpassword/SendResetPasswordMailChallengeTest.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.password.domain.resetpassword -import com.vauthenticator.server.account.repository.AccountRepository +import com.vauthenticator.server.account.domain.AccountRepository import com.vauthenticator.server.communication.domain.EMailSenderService import com.vauthenticator.server.oauth2.clientapp.domain.ClientAppId import com.vauthenticator.server.support.AccountTestFixture.anAccount diff --git a/src/test/kotlin/com/vauthenticator/server/support/AccountTestFixture.kt b/src/test/kotlin/com/vauthenticator/server/support/AccountTestFixture.kt index 636ebd60..6880e26d 100644 --- a/src/test/kotlin/com/vauthenticator/server/support/AccountTestFixture.kt +++ b/src/test/kotlin/com/vauthenticator/server/support/AccountTestFixture.kt @@ -1,6 +1,6 @@ package com.vauthenticator.server.support -import com.vauthenticator.server.account.* +import com.vauthenticator.server.account.domain.* import com.vauthenticator.server.role.domain.Role const val EMAIL = "email@domain.com" diff --git a/src/test/kotlin/com/vauthenticator/server/support/JdbcUtils.kt b/src/test/kotlin/com/vauthenticator/server/support/JdbcUtils.kt index 16e6d533..ccc4fb94 100644 --- a/src/test/kotlin/com/vauthenticator/server/support/JdbcUtils.kt +++ b/src/test/kotlin/com/vauthenticator/server/support/JdbcUtils.kt @@ -31,6 +31,7 @@ object JdbcUtils { jdbcTemplate.execute("DROP TABLE IF EXISTS KEYS;") jdbcTemplate.execute("DROP TABLE IF EXISTS TICKET;") jdbcTemplate.execute("DROP TABLE IF EXISTS PASSWORD_HISTORY;") + jdbcTemplate.execute("DROP TABLE IF EXISTS MFA_ACCOUNT_METHODS;") jdbcTemplate.execute("DROP TABLE IF EXISTS oauth2_authorization;") jdbcTemplate.execute(Files.readString(Paths.get("src/main/resources/data/schema.sql"))) } catch (e: java.lang.Exception) {