Skip to content

Commit 98231b3

Browse files
committed
Dispatcher cares only about its own required attributes,
SecDispatcher handles the 'n' and 'v'.
1 parent 433f8d4 commit 98231b3

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcher.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
24-
import java.util.Objects;
2524
import java.util.Set;
2625
import java.util.StringTokenizer;
2726
import java.util.stream.Collectors;
@@ -120,11 +119,11 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher
120119
Dispatcher dispatcher = dispatchers.get(name);
121120
if (dispatcher == null) throw new SecDispatcherException("no dispatcher for name " + name);
122121
Dispatcher.EncryptPayload payload = dispatcher.encrypt(str, attr, prepareDispatcherConfig(name));
123-
if (!Objects.equals(payload.getAttributes().get(DISPATCHER_NAME_ATTR), name)) {
124-
throw new SecDispatcherException("Dispatcher " + name + " bug: mismatched name attribute");
125-
}
122+
HashMap<String, String> resultAttributes = new HashMap<>(payload.getAttributes());
123+
resultAttributes.put(SecDispatcher.DISPATCHER_NAME_ATTR, name);
124+
resultAttributes.put(SecDispatcher.DISPATCHER_VERSION_ATTR, SecUtil.specVersion());
126125
String res = ATTR_START
127-
+ payload.getAttributes().entrySet().stream()
126+
+ resultAttributes.entrySet().stream()
128127
.map(e -> e.getKey() + "=" + e.getValue())
129128
.collect(Collectors.joining(","))
130129
+ ATTR_STOP;

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/dispatchers/MasterDispatcher.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.codehaus.plexus.components.secdispatcher.MasterSourceMeta;
3232
import org.codehaus.plexus.components.secdispatcher.SecDispatcher;
3333
import org.codehaus.plexus.components.secdispatcher.SecDispatcherException;
34-
import org.codehaus.plexus.components.secdispatcher.internal.SecUtil;
3534

3635
/**
3736
* This dispatcher is logically equivalent (but much more secure) that Maven3 "master password" encryption.
@@ -106,8 +105,6 @@ public EncryptPayload encrypt(String str, Map<String, String> attributes, Map<St
106105
String masterCipher = getMasterCipher(config, true);
107106
String encrypted = cipher.encrypt(masterCipher, str, getMasterPassword(config));
108107
HashMap<String, String> attr = new HashMap<>(attributes);
109-
attr.put(SecDispatcher.DISPATCHER_NAME_ATTR, NAME);
110-
attr.put(SecDispatcher.DISPATCHER_VERSION_ATTR, SecUtil.specVersion());
111108
attr.put(MASTER_CIPHER_ATTR, masterCipher);
112109
return new EncryptPayload(attr, encrypted);
113110
} catch (PlexusCipherException e) {

0 commit comments

Comments
 (0)