Skip to content

Commit 1e3b3f2

Browse files
gangadkhopauljervis
authored andcommitted
Spring Boot and Jasypt Code (eugenp#4142)
* Spring Boot and Jasypt Code * Tabs to Spaces in POM * Removed unnecessary files * Formatted Pom
1 parent a9f0808 commit 1e3b3f2

13 files changed

Lines changed: 264 additions & 0 deletions

‎spring-boot-jasypt/.gitignore‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/

‎spring-boot-jasypt/pom.xml‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example.jasypt</groupId>
7+
<artifactId>JasyptDemo</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>JasyptDemo</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.1.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter</artifactId>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>com.github.ulisesbocchio</groupId>
41+
<artifactId>jasypt-spring-boot-starter</artifactId>
42+
<version>2.0.0</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>com.github.ulisesbocchio</groupId>
47+
<artifactId>jasypt-spring-boot</artifactId>
48+
<version>2.0.0</version>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-maven-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.jasypt;
2+
3+
import org.jasypt.encryption.StringEncryptor;
4+
import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
5+
import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.builder.SpringApplicationBuilder;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.ComponentScan;
10+
11+
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
12+
13+
@SpringBootApplication
14+
@ComponentScan(basePackages = { "com.baeldung.jasypt" })
15+
@EnableEncryptableProperties
16+
public class Main {
17+
public static void main(String[] args) {
18+
new SpringApplicationBuilder().sources(Main.class).run(args);
19+
}
20+
21+
@Bean(name = "encryptorBean")
22+
public StringEncryptor stringEncryptor() {
23+
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
24+
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
25+
config.setPassword("password");
26+
config.setAlgorithm("PBEWithMD5AndDES");
27+
config.setKeyObtentionIterations("1000");
28+
config.setPoolSize("1");
29+
config.setProviderName("SunJCE");
30+
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
31+
config.setStringOutputType("base64");
32+
encryptor.setConfig(config);
33+
return encryptor;
34+
}
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.jasypt.simple;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
5+
import com.ulisesbocchio.jasyptspringboot.annotation.EncryptablePropertySource;
6+
7+
@Configuration
8+
@EncryptablePropertySource(value = "encryptedv2.properties")
9+
public class AppConfigForJasyptSimple {
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.jasypt.simple;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.stereotype.Service;
5+
6+
@Service
7+
public class PropertyServiceForJasyptSimple {
8+
9+
@Value("${encryptedv2.property}")
10+
private String property;
11+
12+
public String getProperty() {
13+
return property;
14+
}
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.jasypt.starter;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.context.annotation.PropertySource;
5+
6+
@Configuration
7+
@PropertySource(value = "encrypted.properties")
8+
public class AppConfigForJasyptStarter {
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.jasypt.starter;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.core.env.Environment;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
public class PropertyServiceForJasyptStarter {
9+
10+
@Value("${encrypted.property}")
11+
private String property;
12+
13+
public String getProperty() {
14+
return property;
15+
}
16+
17+
public String getPasswordUsingEnvironment(Environment environment) {
18+
return environment.getProperty("encrypted.property");
19+
}
20+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jasypt.encryptor.bean=encryptorBean
2+
encryptedv3.property=ENC(askygdq8PHapYFnlX6WsTwZZOxWInq+i)
3+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
encrypted.property=ENC(uTSqb9grs1+vUv3iN8lItC0kl65lMG+8)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
encryptedv2.property=ENC(dQWokHUXXFe+OqXRZYWu22BpXoRZ0Drt)

0 commit comments

Comments
 (0)