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