Skip to content

Commit 1a25a48

Browse files
committed
Updates
1 parent b9a4595 commit 1a25a48

File tree

7 files changed

+33
-48
lines changed

7 files changed

+33
-48
lines changed

pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>plexus-sec-dispatcher</artifactId>
13-
<version>2.1.0-SNAPSHOT</version>
13+
<version>3.0.0-SNAPSHOT</version>
1414

1515
<name>Plexus Security Dispatcher Component</name>
1616

@@ -45,12 +45,12 @@
4545
<dependency>
4646
<groupId>org.codehaus.plexus</groupId>
4747
<artifactId>plexus-utils</artifactId>
48-
<version>4.0.1</version>
48+
<version>4.0.2</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>org.codehaus.plexus</groupId>
5252
<artifactId>plexus-cipher</artifactId>
53-
<version>2.0</version>
53+
<version>3.0.0-SNAPSHOT</version>
5454
</dependency>
5555

5656
<dependency>
@@ -76,7 +76,7 @@
7676
<artifactId>modello-maven-plugin</artifactId>
7777
<version>2.4.0</version>
7878
<configuration>
79-
<version>1.0.0</version>
79+
<version>3.0.0</version>
8080
<models>
8181
<model>src/main/mdo/settings-security.mdo</model>
8282
</models>
@@ -86,6 +86,7 @@
8686
<id>standard</id>
8787
<goals>
8888
<goal>java</goal>
89+
<goal>xsd</goal>
8990
<goal>xpp3-reader</goal>
9091
<goal>xpp3-writer</goal>
9192
</goals>

src/main/java/org/sonatype/plexus/components/sec/dispatcher/DefaultSecDispatcher.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ public String decrypt(String str) throws SecDispatcherException {
8686

8787
try {
8888
bare = _cipher.unDecorate(str);
89-
} catch (PlexusCipherException e1) {
90-
throw new SecDispatcherException(e1);
91-
}
9289

93-
try {
9490
Map<String, String> attr = stripAttributes(bare);
9591

9692
String res;
@@ -114,22 +110,20 @@ public String decrypt(String str) throws SecDispatcherException {
114110

115111
if (dispatcher == null) throw new SecDispatcherException("no dispatcher for hint " + type);
116112

117-
String pass = attr == null ? bare : strip(bare);
113+
String pass = strip(bare);
118114

119115
return dispatcher.decrypt(pass, attr, conf);
120116
}
121117

122118
return res;
123-
} catch (Exception e) {
124-
throw new SecDispatcherException(e);
119+
} catch (PlexusCipherException e) {
120+
throw new SecDispatcherException(e.getMessage(), e);
125121
}
126122
}
127123

128124
private String strip(String str) {
129125
int pos = str.indexOf(ATTR_STOP);
130126

131-
if (pos == str.length()) return null;
132-
133127
if (pos != -1) return str.substring(pos + 1);
134128

135129
return str;
@@ -143,7 +137,7 @@ private Map<String, String> stripAttributes(String str) {
143137

144138
String attrs = str.substring(start + 1, stop).trim();
145139

146-
if (attrs.length() < 1) return null;
140+
if (attrs.isEmpty()) return null;
147141

148142
Map<String, String> res = null;
149143

@@ -160,11 +154,6 @@ private Map<String, String> stripAttributes(String str) {
160154

161155
String key = pair.substring(0, pos).trim();
162156

163-
if (pos == pair.length()) {
164-
res.put(key, null);
165-
continue;
166-
}
167-
168157
String val = pair.substring(pos + 1);
169158

170159
res.put(key, val.trim());
@@ -210,7 +199,7 @@ private String getMaster(SettingsSecurity sec) throws SecDispatcherException {
210199
try {
211200
return _cipher.decryptDecorated(master, SYSTEM_PROPERTY_SEC_LOCATION);
212201
} catch (PlexusCipherException e) {
213-
throw new SecDispatcherException(e);
202+
throw new SecDispatcherException(e.getMessage(), e);
214203
}
215204
}
216205
// ---------------------------------------------------------------

src/main/java/org/sonatype/plexus/components/sec/dispatcher/PasswordDecryptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ public interface PasswordDecryptor {
3333
*
3434
* @throws SecDispatcherException
3535
*/
36-
String decrypt(String str, Map attributes, Map config) throws SecDispatcherException;
36+
String decrypt(String str, Map<String, String> attributes, Map<String, String> config) throws SecDispatcherException;
3737
}

src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecDispatcherException.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313

1414
package org.sonatype.plexus.components.sec.dispatcher;
1515

16-
public class SecDispatcherException extends Exception {
16+
public class SecDispatcherException extends RuntimeException {
1717
public SecDispatcherException(String message) {
1818
super(message);
1919
}
20-
21-
public SecDispatcherException(Throwable cause) {
22-
super(cause);
23-
}
24-
2520
public SecDispatcherException(String message, Throwable cause) {
2621
super(message, cause);
2722
}

src/main/java/org/sonatype/plexus/components/sec/dispatcher/SecUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static SettingsSecurity read(String location, boolean cycle) throws SecDi
5555

5656
return sec;
5757
} catch (Exception e) {
58-
throw new SecDispatcherException(e);
58+
throw new SecDispatcherException(e.getMessage(), e);
5959
}
6060
}
6161
// ---------------------------------------------------------------------------------------------------------------

src/main/mdo/settings-security.mdo

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
*/
1414
-->
1515

16-
<model>
16+
<model xml.namespace="http://codehaus-plexus.github.io/plexus-sec-dispatcher/${version}"
17+
xml.schemaLocation="https://codehaus-plexus.github.io/xsd/plexus-sec-dispatcher-${version}.xsd">
1718
<id>settings-security</id>
1819

1920
<name>SecurityConfiguration</name>
@@ -30,26 +31,26 @@
3031

3132
<class rootElement="true">
3233
<name>SettingsSecurity</name>
33-
<version>1.0.0</version>
34+
<version>1.0.0+</version>
3435
<fields>
3536

3637
<field>
3738
<name>master</name>
38-
<version>1.0.0</version>
39+
<version>1.0.0+</version>
3940
<type>String</type>
4041
<description>encrypted master password</description>
4142
</field>
4243

4344
<field>
4445
<name>relocation</name>
45-
<version>1.0.0</version>
46+
<version>1.0.0+</version>
4647
<type>String</type>
4748
<description>reference to the location of the security file</description>
4849
</field>
4950

5051
<field>
5152
<name>configurations</name>
52-
<version>1.0.0</version>
53+
<version>1.0.0+</version>
5354
<description>named configurations</description>
5455
<association>
5556
<type>Config</type>
@@ -62,21 +63,21 @@
6263

6364
<class>
6465
<name>Config</name>
65-
<version>1.0.0</version>
66+
<version>1.0.0+</version>
6667
<description>Named configuration</description>
6768
<fields>
6869

6970
<field>
7071
<name>name</name>
7172
<type>String</type>
7273
<required>true</required>
73-
<version>1.0.0</version>
74+
<version>1.0.0+</version>
7475
<description>name of this configuration</description>
7576
</field>
7677

7778
<field>
7879
<name>properties</name>
79-
<version>1.0.0</version>
80+
<version>1.0.0+</version>
8081
<description>properties</description>
8182
<association>
8283
<type>ConfigProperty</type>
@@ -89,7 +90,7 @@
8990

9091
<class>
9192
<name>ConfigProperty</name>
92-
<version>1.0.0</version>
93+
<version>1.0.0+</version>
9394
<description>generic property - name/value pair</description>
9495

9596
<fields>
@@ -98,15 +99,15 @@
9899
<name>name</name>
99100
<type>String</type>
100101
<required>true</required>
101-
<version>1.0.0</version>
102+
<version>1.0.0+</version>
102103
<description>name of this property</description>
103104
</field>
104105

105106
<field>
106107
<name>value</name>
107108
<type>String</type>
108109
<required>true</required>
109-
<version>1.0.0</version>
110+
<version>1.0.0+</version>
110111
<description>value of this property</description>
111112
</field>
112113

src/test/java/org/sonatype/plexus/components/sec/dispatcher/SecUtilTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@
3535
*
3636
*/
3737
public class SecUtilTest {
38-
String _pw = "{1wQaa6S/o8MH7FnaTNL53XmhT5O0SEGXQi3gC49o6OY=}";
39-
40-
String _clear = "testtest";
41-
42-
String _encrypted = "{BteqUEnqHecHM7MZfnj9FwLcYbdInWxou1C929Txa0A=}";
38+
String masterPassword = "masterPw";
39+
String masterPasswordEncrypted = "{zKIp99JSqcMP383jVX4zaomd8/gXhXxY0k1ZTKgIY81yzWesjdM0SZPnlI9fEJYp}";
40+
String password = "somePassword";
41+
String passwordEncrypted = "{Gfsw+RhB7REL9DE4+T73MdNRbF8zHW4Dt3YbhooZVVJVa70IjqGFz9hXOs7AH1Hi}";
4342

4443
String _confName = "cname";
4544

@@ -60,7 +59,7 @@ public void prepare() throws Exception {
6059
new SecurityConfigurationXpp3Writer().write(new FileWriter("./target/sec.xml"), sec);
6160

6261
sec.setRelocation(null);
63-
sec.setMaster(_pw);
62+
sec.setMaster(masterPasswordEncrypted);
6463

6564
ConfigProperty cp = new ConfigProperty();
6665
cp.setName(_propName);
@@ -81,7 +80,7 @@ void testRead() throws Exception {
8180

8281
assertNotNull(sec);
8382

84-
assertEquals(_pw, sec.getMaster());
83+
assertEquals(masterPasswordEncrypted, sec.getMaster());
8584

8685
Map<String, String> conf = SecUtil.getConfig(sec, _confName);
8786

@@ -96,10 +95,10 @@ void testRead() throws Exception {
9695
void testDecrypt() throws Exception {
9796
DefaultSecDispatcher sd = new DefaultSecDispatcher(new DefaultPlexusCipher());
9897

99-
String pass = sd.decrypt(_encrypted);
98+
String pass = sd.decrypt(masterPasswordEncrypted);
10099

101100
assertNotNull(pass);
102101

103-
assertEquals(_clear, pass);
102+
assertEquals(masterPassword, pass);
104103
}
105104
}

0 commit comments

Comments
 (0)