|
17 | 17 | import javax.inject.Named; |
18 | 18 | import javax.inject.Singleton; |
19 | 19 |
|
20 | | -import java.io.BufferedReader; |
21 | | -import java.io.InputStreamReader; |
22 | 20 | import java.net.URI; |
23 | 21 | import java.net.URISyntaxException; |
24 | | -import java.util.Collections; |
25 | 22 | import java.util.HashMap; |
26 | 23 | import java.util.Map; |
27 | 24 | import java.util.StringTokenizer; |
28 | 25 |
|
29 | 26 | import org.codehaus.plexus.components.cipher.PlexusCipher; |
30 | 27 | import org.codehaus.plexus.components.cipher.PlexusCipherException; |
31 | | -import org.codehaus.plexus.components.cipher.internal.DefaultPlexusCipher; |
32 | 28 | import org.codehaus.plexus.components.secdispatcher.SecDispatcher; |
33 | 29 | import org.codehaus.plexus.components.secdispatcher.SecDispatcherException; |
34 | 30 | import org.codehaus.plexus.components.secdispatcher.model.SettingsSecurity; |
|
41 | 37 | @Singleton |
42 | 38 | @Named |
43 | 39 | public class DefaultSecDispatcher implements SecDispatcher { |
44 | | - public static final String DEFAULT_CONFIGURATION = "~/.m2/settings-security.xml"; |
45 | | - |
46 | | - public static final String SYSTEM_PROPERTY_SEC_LOCATION = "settings.security"; |
47 | | - |
48 | 40 | public static final String TYPE_ATTR = "type"; |
49 | 41 | public static final char ATTR_START = '['; |
50 | 42 | public static final char ATTR_STOP = ']'; |
@@ -166,7 +158,7 @@ private boolean isEncryptedString(String str) { |
166 | 158 | // ---------------------------------------------------------------------------- |
167 | 159 |
|
168 | 160 | private SettingsSecurity getSec() throws SecDispatcherException { |
169 | | - String location = System.getProperty(SYSTEM_PROPERTY_SEC_LOCATION, getConfigurationFile()); |
| 161 | + String location = System.getProperty(SYSTEM_PROPERTY_CONFIGURATION_LOCATION, getConfigurationFile()); |
170 | 162 | String realLocation = |
171 | 163 | location.charAt(0) == '~' ? System.getProperty("user.home") + location.substring(1) : location; |
172 | 164 |
|
@@ -226,53 +218,4 @@ private static boolean propertyExists(String[] values, String[] av) { |
226 | 218 |
|
227 | 219 | return false; |
228 | 220 | } |
229 | | - |
230 | | - private static void usage() { |
231 | | - System.out.println("usage: java -jar ...jar [-m|-p]\n-m: encrypt master password\n-p: encrypt password"); |
232 | | - } |
233 | | - |
234 | | - // --------------------------------------------------------------- |
235 | | - |
236 | | - private static final String[] SYSTEM_PROPERTY_MASTER_PASSWORD = |
237 | | - new String[] {"settings.master.password", "settings-master-password"}; |
238 | | - |
239 | | - private static final String[] SYSTEM_PROPERTY_SERVER_PASSWORD = |
240 | | - new String[] {"settings.server.password", "settings-server-password"}; |
241 | | - |
242 | | - public static void main(String[] args) throws Exception { |
243 | | - if (args == null || args.length < 1) { |
244 | | - usage(); |
245 | | - return; |
246 | | - } |
247 | | - |
248 | | - if ("-m".equals(args[0]) || propertyExists(SYSTEM_PROPERTY_MASTER_PASSWORD, args)) show(true); |
249 | | - else if ("-p".equals(args[0]) || propertyExists(SYSTEM_PROPERTY_SERVER_PASSWORD, args)) show(false); |
250 | | - else usage(); |
251 | | - } |
252 | | - |
253 | | - // --------------------------------------------------------------- |
254 | | - |
255 | | - private static void show(boolean showMaster) throws Exception { |
256 | | - if (showMaster) System.out.print("\nsettings master password\n"); |
257 | | - else System.out.print("\nsettings server password\n"); |
258 | | - |
259 | | - System.out.print("enter password: "); |
260 | | - |
261 | | - BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); |
262 | | - |
263 | | - String pass = r.readLine(); |
264 | | - |
265 | | - System.out.println("\n"); |
266 | | - |
267 | | - DefaultPlexusCipher dc = new DefaultPlexusCipher(); |
268 | | - DefaultSecDispatcher dd = |
269 | | - new DefaultSecDispatcher(dc, Collections.emptyMap(), Collections.emptyMap(), DEFAULT_CONFIGURATION); |
270 | | - |
271 | | - if (showMaster) |
272 | | - System.out.println(dc.encryptAndDecorate(pass, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION)); |
273 | | - else { |
274 | | - SettingsSecurity sec = dd.getSec(); |
275 | | - System.out.println(dc.encryptAndDecorate(pass, dd.getMaster(sec))); |
276 | | - } |
277 | | - } |
278 | 221 | } |
0 commit comments