1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codehaus.mojo.properties;
17
18 import java.util.List;
19 import java.util.Properties;
20
21 import org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.project.MavenProject;
24 import org.jasypt.util.text.TextEncryptor;
25 import org.kuali.common.util.EncUtils;
26 import org.kuali.common.util.PropertyUtils;
27
28
29
30
31
32
33
34 public class DecryptAllPropertiesMojo extends AbstractMojo {
35
36
37
38
39
40
41 private MavenProject project;
42
43
44
45
46
47
48
49 private String endsWith;
50
51
52
53
54
55
56
57 private String password;
58
59 @Override
60 public void execute() throws MojoExecutionException {
61 TextEncryptor encryptor = EncUtils.getTextEncryptor(password);
62 Properties props = PropertyUtils.getGlobalProperties(project.getProperties());
63 List<String> keys = PropertyUtils.getEndsWithKeys(props, endsWith);
64 for (String key : keys) {
65 String value = props.getProperty(key);
66 String decryptedValue = getDecryptedValue(encryptor, value);
67 int length = endsWith.length();
68 String newKey = key.substring(0, key.length() - length);
69 project.getProperties().setProperty(newKey, decryptedValue);
70 }
71 }
72
73 protected String getDecryptedValue(TextEncryptor encryptor, String value) {
74 if (PropertyUtils.isEncryptedPropertyValue(value)) {
75 return PropertyUtils.decryptPropertyValue(encryptor, value);
76 } else {
77 return encryptor.decrypt(value);
78 }
79 }
80
81 public MavenProject getProject() {
82 return project;
83 }
84
85 public void setProject(MavenProject project) {
86 this.project = project;
87 }
88
89 public String getEndsWith() {
90 return endsWith;
91 }
92
93 public void setEndsWith(String endsWith) {
94 this.endsWith = endsWith;
95 }
96
97 public String getPassword() {
98 return password;
99 }
100
101 public void setPassword(String password) {
102 this.password = password;
103 }
104 }