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.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.context.ApplicationListener;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.PropertiesPropertySource;
|
import org.springframework.core.env.PropertiesPropertySource;
|
||||||
@ -16,38 +16,26 @@ import java.util.Base64;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SecretsManagerPropertiesListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
public class SecretsManagerPropertiesListener implements ApplicationListener<ApplicationPreparedEvent> {
|
||||||
|
|
||||||
private ObjectMapper mapper = new ObjectMapper();
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
public void onApplicationEvent(ApplicationPreparedEvent event) {
|
||||||
|
|
||||||
System.out.println("ApplicationListener<ApplicationEnvironmentPreparedEvent> invoked");
|
ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
|
||||||
log.info("ApplicationListener<ApplicationEnvironmentPreparedEvent> invoked");
|
|
||||||
|
|
||||||
ConfigurableEnvironment environment = event.getEnvironment();
|
|
||||||
String activeProfiles = environment.getProperty("spring.profiles.active");
|
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();
|
String secretJson = getSecret();
|
||||||
|
|
||||||
log.debug("Retrieved secretJson from Secret Manager: {}", secretJson);
|
log.debug("Retrieved secretJson from Secret Manager: {}", secretJson);
|
||||||
System.out.println("Retrieved secretJson from Secret Manager: " + secretJson);
|
|
||||||
|
|
||||||
String jasyptPassword = getString(secretJson, "jasypt_password");
|
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();
|
Properties props = new Properties();
|
||||||
System.setProperty("JASYPT_PASSWORD", jasyptPassword);
|
|
||||||
props.put("jasypt.encryptor.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));
|
environment.getPropertySources().addFirst(new PropertiesPropertySource("aws.secret.manager", props));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,7 +129,7 @@ server.ssl:
|
|||||||
enabled: true # Enable HTTPS support (only accept HTTPS requests)
|
enabled: true # Enable HTTPS support (only accept HTTPS requests)
|
||||||
key-alias: securedPortal # Alias that identifies the key in the key store
|
key-alias: securedPortal # Alias that identifies the key in the key store
|
||||||
key-store: classpath:securedPortal-keystore.p12 # Keystore location
|
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
|
key-store-type: PKCS12 # Keystore format
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user