Skip to content

Instantly share code, notes, and snippets.

View rajeevshukla's full-sized avatar
🎯
Focusing

Rajeev Shukla rajeevshukla

🎯
Focusing
View GitHub Profile
@Configuration
public class DevProfileEnvironmentPostProcessor implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (environment.acceptsProfiles("dev")) {
Map<String, Object> devProperties = new HashMap<>();
devProperties.put("server.port", 8080);
devProperties.put("logging.level.org.springframework.web", "DEBUG");
devProperties.put("logging.level.com.example.application", "TRACE");
@rajeevshukla
rajeevshukla / application.properties
Created January 17, 2023 19:28
Log4j appender to log IP and user Id via log4j MDC
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %X{ip} %X{userId} - %m%n
@rajeevshukla
rajeevshukla / LoggingAspect.java
Created January 17, 2023 19:26
Spring AOP Aspect to log ip address and User Id
@Aspect
@Component
public class LoggingAspect {
@Before("execution(* com.example.controller.*.*(..))")
public void before(JoinPoint joinPoint) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
MDC.put("ip", request.getRemoteAddr());
MDC.put("userId", request.getHeader("userId"));
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>7.38.0.Final</version>
</dependency>
@SpringBootApplication
public class SpringCloudVaultIntegrationApplication implements CommandLineRunner {
// Reading through yml file
@Value("${app.security.key}")
private String appSecurityKey;
// Accessing same key what we added in vault and accessing that directly in @Value()
@Value("${appSecurityKey}")
private String secretKeyVaultDirectAccess;
public static void main(String[] args) {
spring:
application:
name: spring-cloud-vault
cloud:
vault:
token: s.lL1wRFK79QQQRflLyIS3WyYm
scheme: http
host: http://127.0.0.1
port: 8200
spring:
application:
name: spring-cloud-vault
cloud:
vault:
token: s.lL1wRFK79QQQRflLyIS3WyYm
scheme: http
host: http://127.0.0.1
port: 8200
spring:
application:
name: spring-cloud-vault
cloud:
vault:
token: s.lL1wRFK79QQQRflLyIS3WyYm
scheme: http
host: http://127.0.0.1
port: 8200
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
root@rajeev-Latitude-5480:/home/rajeev# vault operator unseal waqRq56mn1YAdf6wvjZ6Dz1TwqkC4ZGegAqM/lp4e9TN 
Key Value
 - - - - -
Seal Type shamir
Initialized true
Sealed true
Total Shares 5
Threshold 3
Unseal Progress 2/3
Unseal Nonce 181be784–7c72-a040–48a5–105eb398f026