[VID-55] Upgrade Tosca Parser (merge)
[vid.git] / vid-app-common / src / main / java / org / openecomp / aai / util / JettyObfuscationConversionCommandLineUtil.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.aai.util;\r
22 \r
23 \r
24 import org.apache.commons.cli.BasicParser;\r
25 import org.apache.commons.cli.CommandLine;\r
26 import org.apache.commons.cli.CommandLineParser;\r
27 import org.apache.commons.cli.Options;\r
28 import org.apache.commons.cli.ParseException;\r
29 import org.eclipse.jetty.util.security.Password;\r
30 \r
31 \r
32 public class JettyObfuscationConversionCommandLineUtil {\r
33         /**\r
34          * The main method.\r
35          *\r
36          * @param args the arguments\r
37          */\r
38         public static void main(String[] args){\r
39                 Options options = new Options();\r
40                 options.addOption("e", true, "obfuscate the given string");\r
41                 options.addOption("d", true, "deobfuscate the given string");\r
42                 \r
43                 CommandLineParser parser = new BasicParser();\r
44                 \r
45                 try {\r
46                         CommandLine cmd = parser.parse(options, args);\r
47                         String toProcess = null;\r
48                         \r
49                         if (cmd.hasOption("e")){\r
50                                 toProcess = cmd.getOptionValue("e");\r
51                                 String encoded = Password.obfuscate(toProcess);\r
52                                 System.out.println(encoded);\r
53                         } else if (cmd.hasOption("d")) {\r
54                                 toProcess = cmd.getOptionValue("d");\r
55                                 String decoded_str = Password.deobfuscate(toProcess);\r
56                                 System.out.println(decoded_str);\r
57                         } else {\r
58                                 usage();\r
59                         }\r
60                 } catch (ParseException e) {\r
61                         System.out.println("failed to parse input");\r
62                         System.out.println(e.toString());\r
63                         usage();\r
64                 } catch (Exception e) {\r
65                         System.out.println("exception:" + e.toString());\r
66                 }\r
67         }\r
68         \r
69         /**\r
70          * Usage.\r
71          */\r
72         private static void usage(){\r
73                 System.out.println("usage:");;\r
74                 System.out.println("-e [string] to obfuscate");\r
75                 System.out.println("-d [string] to deobfuscate");\r
76                 System.out.println("-h help");\r
77         }\r
78 }\r