From 9adad27744a25118c988e6d81f6be9b01c78a4cf Mon Sep 17 00:00:00 2001 From: mrflick72 Date: Sun, 27 Oct 2024 12:01:46 +0100 Subject: [PATCH] refactor configuration class packaging --- .../server/account/AccountConfig.kt | 225 ++++++++++++++++++ .../server/config/AccountConfig.kt | 97 -------- .../server/config/EMailVerificationConfig.kt | 74 ------ .../server/config/ResetPasswordConfig.kt | 70 ------ .../server/config/SingUpConfig.kt | 30 --- .../server/config/WelcomeConfig.kt | 47 ---- .../server/{config => events}/EventsConfig.kt | 3 +- .../server/{config => i18n}/I18nConfig.kt | 4 +- .../server/{config => keys}/KeyConfig.kt | 2 +- .../{config => lambdas}/LambdaConfig.kt | 3 +- .../clientapp}/ClientApplicationConfig.kt | 2 +- .../{config => password}/PasswordConfig.kt | 66 ++++- .../{config => role}/PermissionConfig.kt | 2 +- .../server/{config => ticket}/TicketConfig.kt | 2 +- 14 files changed, 296 insertions(+), 331 deletions(-) create mode 100644 src/main/kotlin/com/vauthenticator/server/account/AccountConfig.kt delete mode 100644 src/main/kotlin/com/vauthenticator/server/config/AccountConfig.kt delete mode 100644 src/main/kotlin/com/vauthenticator/server/config/EMailVerificationConfig.kt delete mode 100644 src/main/kotlin/com/vauthenticator/server/config/ResetPasswordConfig.kt delete mode 100644 src/main/kotlin/com/vauthenticator/server/config/SingUpConfig.kt delete mode 100644 src/main/kotlin/com/vauthenticator/server/config/WelcomeConfig.kt rename src/main/kotlin/com/vauthenticator/server/{config => events}/EventsConfig.kt (95%) rename src/main/kotlin/com/vauthenticator/server/{config => i18n}/I18nConfig.kt (84%) rename src/main/kotlin/com/vauthenticator/server/{config => keys}/KeyConfig.kt (98%) rename src/main/kotlin/com/vauthenticator/server/{config => lambdas}/LambdaConfig.kt (88%) rename src/main/kotlin/com/vauthenticator/server/{config => oauth2/clientapp}/ClientApplicationConfig.kt (98%) rename src/main/kotlin/com/vauthenticator/server/{config => password}/PasswordConfig.kt (58%) rename src/main/kotlin/com/vauthenticator/server/{config => role}/PermissionConfig.kt (98%) rename src/main/kotlin/com/vauthenticator/server/{config => ticket}/TicketConfig.kt (97%) 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/config/AccountConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/AccountConfig.kt deleted file mode 100644 index 2b588d9b..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.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.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/EMailVerificationConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/EMailVerificationConfig.kt deleted file mode 100644 index 52c5fa2f..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.domain.AccountRepository -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.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 93fc2c1a..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.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.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 e5838cae..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.domain.AccountRepository -import com.vauthenticator.server.account.domain.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/WelcomeConfig.kt b/src/main/kotlin/com/vauthenticator/server/config/WelcomeConfig.kt deleted file mode 100644 index 1eb09c17..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.domain.AccountRepository -import com.vauthenticator.server.account.domain.welcome.SayWelcome -import com.vauthenticator.server.account.domain.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/config/EventsConfig.kt b/src/main/kotlin/com/vauthenticator/server/events/EventsConfig.kt similarity index 95% rename from src/main/kotlin/com/vauthenticator/server/config/EventsConfig.kt rename to src/main/kotlin/com/vauthenticator/server/events/EventsConfig.kt index 6f688d25..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.domain.emailverification.SendVerifyEMailChallengeUponSignUpEventConsumer import com.vauthenticator.server.account.domain.signup.SignUpEventConsumer import com.vauthenticator.server.account.domain.welcome.SendWelcomeMailUponSignUpEventConsumer -import com.vauthenticator.server.events.* 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/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/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/config/PasswordConfig.kt b/src/main/kotlin/com/vauthenticator/server/password/PasswordConfig.kt similarity index 58% rename from src/main/kotlin/com/vauthenticator/server/config/PasswordConfig.kt rename to src/main/kotlin/com/vauthenticator/server/password/PasswordConfig.kt index a0e0ac0e..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.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/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