2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Modifications Copyright (C) 2018 IBM.
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END====================================================
24 package org.onap.aaf.auth.cui;
26 import java.io.PrintWriter;
28 import javax.servlet.ServletInputStream;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
32 import org.onap.aaf.auth.cmd.AAFcli;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.gui.AAF_GUI;
36 import org.onap.aaf.auth.rserv.HttpCode;
37 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
38 import org.onap.aaf.cadi.http.HTransferSS;
39 import org.onap.aaf.cadi.principal.TaggedPrincipal;
40 import org.onap.aaf.misc.env.Env;
41 import org.onap.aaf.misc.env.TimeTaken;
44 public class CUI extends HttpCode<AuthzTrans, Void> {
45 private final AAF_GUI gui;
48 public CUI(AAF_GUI gui) {
49 super(null,"Command Line");
54 public void handle(AuthzTrans trans, HttpServletRequest req,HttpServletResponse resp) throws Exception {
55 ServletInputStream isr = req.getInputStream();
56 PrintWriter pw = resp.getWriter();
58 StringBuilder cmd = new StringBuilder();
60 while ((c=isr.read())>=0) {
64 TimeTaken tt = trans.start("Execute AAFCLI", Env.REMOTE);
66 TaggedPrincipal p = trans.getUserPrincipal();
67 // Access needs to be set after overall construction. Thus, the lazy create.
69 AAFConHttp aafcon = gui.aafCon();
70 aafcli= new AAFcli(gui.access,gui.env, pw,
72 aafcon.securityInfo(),
73 new HTransferSS(p,AAF_GUI.app,
74 aafcon.securityInfo()));
75 aafcli.verbose(false);
78 String cmdStr = cmd.toString();
79 if (!cmdStr.contains("--help")) {
80 cmdStr = cmdStr.replaceAll("help", "--help");
82 if (!cmdStr.contains("--version")) {
83 cmdStr = cmdStr.replaceAll("version", "--version");
88 } catch (Exception e) {
90 trans.error().log("Error", e.getMessage());