|
1 | 1 | package com.example.busan.auth.config;
|
2 | 2 |
|
| 3 | +import com.example.busan.auth.domain.AuthorizationCodeGenerator; |
| 4 | +import com.example.busan.auth.infrastructure.InMemoryPhoneAuthenticator; |
| 5 | +import com.example.busan.auth.service.PhoneAuthenticator; |
3 | 6 | import net.nurigo.sdk.message.service.DefaultMessageService;
|
4 | 7 | import org.springframework.beans.factory.annotation.Value;
|
5 | 8 | import org.springframework.context.annotation.Bean;
|
6 | 9 | import org.springframework.context.annotation.Configuration;
|
| 10 | +import org.springframework.context.annotation.Profile; |
7 | 11 |
|
8 | 12 | @Configuration
|
9 | 13 | public class PhoneAuthenticatorConfig {
|
10 | 14 |
|
| 15 | + private final AuthorizationCodeGenerator codeGenerator; |
11 | 16 | private final String key;
|
12 | 17 | private final String secret;
|
| 18 | + private final String sender; |
13 | 19 |
|
14 |
| - public PhoneAuthenticatorConfig(@Value("${phone.key}") final String key, |
15 |
| - @Value("${phone.secret}") final String secret) { |
| 20 | + public PhoneAuthenticatorConfig(final AuthorizationCodeGenerator codeGenerator, |
| 21 | + @Value("${phone.key}") final String key, |
| 22 | + @Value("${phone.secret}") final String secret, |
| 23 | + @Value("${phone.sender}") final String sender) { |
| 24 | + this.codeGenerator = codeGenerator; |
16 | 25 | this.key = key;
|
17 | 26 | this.secret = secret;
|
| 27 | + this.sender = sender; |
| 28 | + } |
| 29 | + |
| 30 | + @Profile("prod") |
| 31 | + @Bean |
| 32 | + public PhoneAuthenticator phoneAuthenticator() { |
| 33 | + return new InMemoryPhoneAuthenticator(messageService(), codeGenerator, sender); |
| 34 | + } |
| 35 | + |
| 36 | + @Profile("default") |
| 37 | + @Bean |
| 38 | + public PhoneAuthenticator fakePhoneAuthenticator() { |
| 39 | + return new PhoneAuthenticator() { |
| 40 | + @Override |
| 41 | + public void sendCode(final String phone) { |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public void authenticate(final String code) { |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void validateAuthenticated(final String phone) { |
| 50 | + } |
| 51 | + }; |
18 | 52 | }
|
19 | 53 |
|
20 | 54 | @Bean
|
|
0 commit comments