com.infusers.core.secrets.dto.EmailSecrets Maven / Gradle / Ivy
package com.infusers.core.secrets.dto;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Component
@ConfigurationProperties(prefix = "spring.mail")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EmailSecrets implements ISecrets {
private static final int MIN_PORT = 1;
private static final int MAX_PORT = 65535;
private String username;
private String password;
private String host;
private String port;
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getHost() {
return host;
}
public String getPort() {
return port;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public void setHost(String host) {
this.host = host;
}
public void setPort(String port) {
this.port = port;
}
public boolean isValid() {
return isValidField(username) &&
isValidField(password) &&
isValidField(host) &&
isValidField(port) &&
isValidPort(port);
}
private boolean isValidField(String field) {
return field != null && !field.isEmpty();
}
private boolean isValidPort(String port) {
try {
int intValue = Integer.parseInt(port);
return intValue >= MIN_PORT && intValue <= MAX_PORT;
} catch (NumberFormatException e) {
return false; // Not a valid integer
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy