Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 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 |
|
| 22 |
|
| 23 | package org.onap.osam.aai.util;
|
| 24 |
|
| 25 |
|
| 26 | import org.apache.commons.cli.*;
|
| 27 | import org.eclipse.jetty.util.security.Password;
|
| 28 |
|
| 29 |
|
| 30 | public class JettyObfuscationConversionCommandLineUtil {
|
| 31 | public static void main(String[] args){
|
| 32 | Options options = new Options();
|
| 33 | options.addOption("e", true, "obfuscate the given string");
|
| 34 | options.addOption("d", true, "deobfuscate the given string");
|
| 35 |
|
| 36 | CommandLineParser parser = new BasicParser();
|
| 37 |
|
| 38 | try {
|
| 39 | CommandLine cmd = parser.parse(options, args);
|
| 40 | String toProcess = null;
|
| 41 |
|
| 42 | if (cmd.hasOption("e")){
|
| 43 | toProcess = cmd.getOptionValue("e");
|
| 44 | String encoded = Password.obfuscate(toProcess);
|
| 45 | System.out.println(encoded);
|
| 46 | } else if (cmd.hasOption("d")) {
|
| 47 | toProcess = cmd.getOptionValue("d");
|
| 48 | String decoded_str = Password.deobfuscate(toProcess);
|
| 49 | System.out.println(decoded_str);
|
| 50 | } else {
|
| 51 | usage();
|
| 52 | }
|
| 53 | } catch (ParseException e) {
|
| 54 | System.out.println("failed to parse input");
|
| 55 | System.out.println(e.toString());
|
| 56 | usage();
|
| 57 | } catch (Exception e) {
|
| 58 | System.out.println("exception:" + e.toString());
|
| 59 | }
|
| 60 | }
|
| 61 |
|
| 62 | private static void usage(){
|
| 63 | System.out.println("usage:");
|
| 64 | System.out.println("-e [string] to obfuscate");
|
| 65 | System.out.println("-d [string] to deobfuscate");
|
| 66 | System.out.println("-h help");
|
| 67 | }
|
| 68 | }
|