44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package com.kri.notihub.server.config;
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
import jakarta.validation.constraints.Min;
|
|
import jakarta.validation.constraints.NotBlank;
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
@Getter
|
|
@Setter
|
|
@Validated
|
|
@Component
|
|
@ConfigurationProperties(prefix = "kri.sms.verification")
|
|
public class PhoneVerificationProperties {
|
|
|
|
public static final String CODE_PLACEHOLDER = "#{verificationCode}";
|
|
|
|
@Min(1)
|
|
private int expireMinutes = 5;
|
|
|
|
@Min(1)
|
|
private int maxAttempts = 5;
|
|
|
|
@NotBlank
|
|
private String messageTemplate = "인증번호는 [#{verificationCode}] 입니다.";
|
|
|
|
@PostConstruct
|
|
void validateMessageTemplate() {
|
|
int first = messageTemplate.indexOf(CODE_PLACEHOLDER);
|
|
int last = messageTemplate.lastIndexOf(CODE_PLACEHOLDER);
|
|
if (first < 0 || first != last) {
|
|
throw new IllegalStateException(
|
|
"kri.sms.verification.message-template must contain #{verificationCode} exactly once");
|
|
}
|
|
}
|
|
|
|
public String renderMessage(String verificationCode) {
|
|
return messageTemplate.replace(CODE_PLACEHOLDER, verificationCode);
|
|
}
|
|
}
|