44.2 Jasypt initialization Refactoring (#44)
This commit is contained in:
@ -6,7 +6,7 @@ import com.amazonaws.services.secretsmanager.model.*;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
@ -16,38 +16,26 @@ import java.util.Base64;
|
||||
import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
public class SecretsManagerPropertiesListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
public class SecretsManagerPropertiesListener implements ApplicationListener<ApplicationPreparedEvent> {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
public void onApplicationEvent(ApplicationPreparedEvent event) {
|
||||
|
||||
System.out.println("ApplicationListener<ApplicationEnvironmentPreparedEvent> invoked");
|
||||
log.info("ApplicationListener<ApplicationEnvironmentPreparedEvent> invoked");
|
||||
|
||||
ConfigurableEnvironment environment = event.getEnvironment();
|
||||
ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
|
||||
String activeProfiles = environment.getProperty("spring.profiles.active");
|
||||
// if (activeProfiles == null || !activeProfiles.contains("aws-rds")) return;
|
||||
if (activeProfiles == null || !activeProfiles.contains("aws-rds")) return;
|
||||
|
||||
String secretJson = getSecret();
|
||||
|
||||
log.debug("Retrieved secretJson from Secret Manager: {}", secretJson);
|
||||
System.out.println("Retrieved secretJson from Secret Manager: " + secretJson);
|
||||
|
||||
String jasyptPassword = getString(secretJson, "jasypt_password");
|
||||
// String jwtSecret = getString(secretJson, "app_jwt_secret");
|
||||
// String springDatasourceUsername = getString(secretJson, "spring_datasource_username");
|
||||
// String springDatasourcePassword = getString(secretJson, "spring_datasource_password");
|
||||
|
||||
Properties props = new Properties();
|
||||
System.setProperty("JASYPT_PASSWORD", jasyptPassword);
|
||||
props.put("jasypt.encryptor.password", jasyptPassword);
|
||||
|
||||
// props.put("app.jwt.secret", jwtSecret);
|
||||
// props.put("spring.datasource.username", springDatasourceUsername);
|
||||
// props.put("spring.datasource.password", springDatasourcePassword);
|
||||
|
||||
environment.getPropertySources().addFirst(new PropertiesPropertySource("aws.secret.manager", props));
|
||||
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ server.ssl:
|
||||
enabled: true # Enable HTTPS support (only accept HTTPS requests)
|
||||
key-alias: securedPortal # Alias that identifies the key in the key store
|
||||
key-store: classpath:securedPortal-keystore.p12 # Keystore location
|
||||
key-store-password: secret # Keystore password
|
||||
key-store-password: ENC(WNuqkduFC9d7bjWwv+KqKA==) # Keystore password
|
||||
key-store-type: PKCS12 # Keystore format
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user