Skip to content

Commit 1ae037a

Browse files
committed
Tidy up
1 parent 69e3c31 commit 1ae037a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,19 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher
108108
attr = new HashMap<>(attr);
109109
}
110110
if (attr.get(DISPATCHER_NAME_ATTR) == null) {
111-
attr.put(
112-
DISPATCHER_NAME_ATTR,
113-
requireNonNull(
114-
requireNonNull(SecUtil.read(configurationFile), "no configuration")
115-
.getDefaultDispatcher(),
116-
"no default dispatcher set in configuration"));
111+
SettingsSecurity conf = readConfiguration(false);
112+
if (conf == null) {
113+
throw new SecDispatcherException("No configuration found");
114+
}
115+
String defaultDispatcher = conf.getDefaultDispatcher();
116+
if (defaultDispatcher == null) {
117+
throw new SecDispatcherException("No defaultDispatcher set in configuration");
118+
}
119+
attr.put(DISPATCHER_NAME_ATTR, defaultDispatcher);
117120
}
118121
String name = attr.get(DISPATCHER_NAME_ATTR);
119122
Dispatcher dispatcher = dispatchers.get(name);
120-
if (dispatcher == null) throw new SecDispatcherException("no dispatcher for name " + name);
123+
if (dispatcher == null) throw new SecDispatcherException("No dispatcher exist with name " + name);
121124
Dispatcher.EncryptPayload payload = dispatcher.encrypt(str, attr, prepareDispatcherConfig(name));
122125
HashMap<String, String> resultAttributes = new HashMap<>(payload.getAttributes());
123126
resultAttributes.put(SecDispatcher.DISPATCHER_NAME_ATTR, name);
@@ -143,12 +146,9 @@ public String decrypt(String str) throws SecDispatcherException, IOException {
143146
if (isLegacyPassword(str)) {
144147
attr.put(DISPATCHER_NAME_ATTR, LegacyDispatcher.NAME);
145148
}
146-
if (attr.get(DISPATCHER_NAME_ATTR) == null) {
147-
throw new SecDispatcherException("Invalid encrypted string; mandatory attributes missing");
148-
}
149149
String name = attr.get(DISPATCHER_NAME_ATTR);
150150
Dispatcher dispatcher = dispatchers.get(name);
151-
if (dispatcher == null) throw new SecDispatcherException("no dispatcher for name " + name);
151+
if (dispatcher == null) throw new SecDispatcherException("No dispatcher exist with name " + name);
152152
return dispatcher.decrypt(strip(bare), attr, prepareDispatcherConfig(name));
153153
} catch (PlexusCipherException e) {
154154
throw new SecDispatcherException(e.getMessage(), e);
@@ -285,7 +285,6 @@ protected Map<String, String> stripAttributes(String str) {
285285
}
286286

287287
protected boolean isEncryptedString(String str) {
288-
if (str == null) return false;
289288
return cipher.isEncryptedString(str);
290289
}
291290
}

0 commit comments

Comments
 (0)