X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-gui%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fcui%2FCUI.java;h=f2d7522eea33cc29fca9d04fbf01289a97c09172;hb=2c3cb70208785cf0272eae075206074318ca74cc;hp=ecbd0a25bd2ad709106d1d9d3d5f624871108831;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java index ecbd0a25..f2d7522e 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/cui/CUI.java @@ -4,12 +4,14 @@ * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. * =========================================================================== + * Modifications Copyright (C) 2018 IBM. + * ============================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,14 +24,17 @@ package org.onap.aaf.auth.cui; import java.io.PrintWriter; +import java.util.regex.Pattern; import javax.servlet.ServletInputStream; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.onap.aaf.auth.cmd.AAFcli; import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.gui.AAF_GUI; +import org.onap.aaf.auth.gui.Page; import org.onap.aaf.auth.rserv.HttpCode; import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp; import org.onap.aaf.cadi.http.HTransferSS; @@ -37,8 +42,12 @@ import org.onap.aaf.cadi.principal.TaggedPrincipal; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; + public class CUI extends HttpCode { private final AAF_GUI gui; + private final static Pattern userPerm = Pattern.compile("perm (create|delete).*@.*:id.*aaf.gui.*"); + + public CUI(AAF_GUI gui) { super(null,"Command Line"); this.gui = gui; @@ -51,7 +60,7 @@ public class CUI extends HttpCode { int c; StringBuilder cmd = new StringBuilder(); - while((c=isr.read())>=0) { + while ((c=isr.read())>=0) { cmd.append((char)c); } @@ -61,33 +70,40 @@ public class CUI extends HttpCode { // Access needs to be set after overall construction. Thus, the lazy create. AAFcli aafcli; AAFConHttp aafcon = gui.aafCon(); - aafcli= new AAFcli(gui.access,gui.env, pw, - aafcon.hman(), - aafcon.securityInfo(), + aafcli= new AAFcli(gui.access,gui.env, pw, + aafcon.hman(), + aafcon.securityInfo(), new HTransferSS(p,AAF_GUI.app, - aafcon.securityInfo())); + aafcon.securityInfo())); aafcli.verbose(false); aafcli.gui(true); String cmdStr = cmd.toString(); - if (!cmdStr.contains("--help")) { - cmdStr = cmdStr.replaceAll("help", "--help"); + if (cmdStr.contains("--help")) { + cmdStr = cmdStr.replaceAll("--help", "help"); } - if (!cmdStr.contains("--version")) { - cmdStr = cmdStr.replaceAll("version", "--version"); + if (cmdStr.contains("--version")) { + cmdStr = cmdStr.replaceAll("--version", "version"); } try { aafcli.eval(cmdStr); + if(userPerm.matcher(cmdStr).matches()) { + trans.clearCache(); + Cookie cookie = new Cookie(Page.AAF_THEME,trans.getProperty(Page.AAF_THEME)); + cookie.setMaxAge(-1); + cookie.setComment("Remove AAF GUI Theme"); + trans.hresp().addCookie(cookie); + } pw.flush(); } catch (Exception e) { pw.flush(); - pw.println(e.getMessage()); + trans.error().log("Error", e.getMessage()); } finally { aafcli.close(); } } finally { tt.done(); } - + } }