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;
27 import java.util.regex.Pattern;
29 import javax.servlet.ServletInputStream;
30 import javax.servlet.http.Cookie;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
34 import org.onap.aaf.auth.cmd.AAFcli;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.gui.AAF_GUI;
37 import org.onap.aaf.auth.gui.Page;
38 import org.onap.aaf.auth.rserv.HttpCode;
39 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
40 import org.onap.aaf.cadi.http.HTransferSS;
41 import org.onap.aaf.cadi.principal.TaggedPrincipal;
42 import org.onap.aaf.misc.env.Env;
43 import org.onap.aaf.misc.env.TimeTaken;
46 public class CUI extends HttpCode<AuthzTrans, Void> {
47 private final AAF_GUI gui;
48 private static final Pattern userPerm = Pattern.compile("perm (create|delete).*@.*:id.*aaf.gui.*");
51 public CUI(AAF_GUI gui) {
52 super(null,"Command Line");
57 public void handle(AuthzTrans trans, HttpServletRequest req,HttpServletResponse resp) throws Exception {
58 ServletInputStream isr = req.getInputStream();
59 PrintWriter pw = resp.getWriter();
61 StringBuilder cmd = new StringBuilder();
63 while ((c=isr.read())>=0) {
67 TimeTaken tt = trans.start("Execute AAFCLI", Env.REMOTE);
69 TaggedPrincipal p = trans.getUserPrincipal();
70 // Access needs to be set after overall construction. Thus, the lazy create.
72 AAFConHttp aafcon = gui.aafCon();
73 aafcli= new AAFcli(gui.access,gui.env, pw,
75 aafcon.securityInfo(),
76 new HTransferSS(p,AAF_GUI.app,
77 aafcon.securityInfo()));
78 aafcli.verbose(false);
81 String cmdStr = cmd.toString();
82 if (cmdStr.contains("--help")) {
83 cmdStr = cmdStr.replaceAll("--help", "help");
85 if (cmdStr.contains("--version")) {
86 cmdStr = cmdStr.replaceAll("--version", "version");
90 if(userPerm.matcher(cmdStr).matches()) {
92 Cookie cookie = new Cookie(Page.AAF_THEME,trans.getProperty(Page.AAF_THEME));
93 cookie.setSecure(true);
95 cookie.setComment("Remove AAF GUI Theme");
96 trans.hresp().addCookie(cookie);
99 } catch (Exception e) {
101 trans.error().log("Error", e.getMessage());