2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.gui;
24 import static org.onap.aaf.auth.rserv.HttpMethods.GET;
25 import static org.onap.aaf.auth.rserv.HttpMethods.POST;
26 import static org.onap.aaf.auth.rserv.HttpMethods.PUT;
30 import javax.servlet.Filter;
32 import org.onap.aaf.auth.cmd.Cmd;
33 import org.onap.aaf.auth.cui.CUI;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.env.AuthzTransFilter;
37 import org.onap.aaf.auth.gui.pages.ApiDocs;
38 import org.onap.aaf.auth.gui.pages.ApiExample;
39 import org.onap.aaf.auth.gui.pages.ApprovalAction;
40 import org.onap.aaf.auth.gui.pages.ApprovalForm;
41 import org.onap.aaf.auth.gui.pages.CMArtiChangeAction;
42 import org.onap.aaf.auth.gui.pages.CMArtiChangeForm;
43 import org.onap.aaf.auth.gui.pages.CMArtifactShow;
44 import org.onap.aaf.auth.gui.pages.CredDetail;
45 import org.onap.aaf.auth.gui.pages.Home;
46 import org.onap.aaf.auth.gui.pages.LoginLanding;
47 import org.onap.aaf.auth.gui.pages.LoginLandingAction;
48 import org.onap.aaf.auth.gui.pages.NsDetail;
49 import org.onap.aaf.auth.gui.pages.NsHistory;
50 import org.onap.aaf.auth.gui.pages.NsInfoAction;
51 import org.onap.aaf.auth.gui.pages.NsInfoForm;
52 import org.onap.aaf.auth.gui.pages.NssShow;
53 import org.onap.aaf.auth.gui.pages.PassChangeAction;
54 import org.onap.aaf.auth.gui.pages.PassChangeForm;
55 import org.onap.aaf.auth.gui.pages.PassDeleteAction;
56 import org.onap.aaf.auth.gui.pages.PendingRequestsShow;
57 import org.onap.aaf.auth.gui.pages.PermDetail;
58 import org.onap.aaf.auth.gui.pages.PermGrantAction;
59 import org.onap.aaf.auth.gui.pages.PermGrantForm;
60 import org.onap.aaf.auth.gui.pages.PermHistory;
61 import org.onap.aaf.auth.gui.pages.PermsShow;
62 import org.onap.aaf.auth.gui.pages.RequestDetail;
63 import org.onap.aaf.auth.gui.pages.RoleDetail;
64 import org.onap.aaf.auth.gui.pages.RoleDetailAction;
65 import org.onap.aaf.auth.gui.pages.RoleHistory;
66 import org.onap.aaf.auth.gui.pages.RolesShow;
67 import org.onap.aaf.auth.gui.pages.UserRoleExtend;
68 import org.onap.aaf.auth.gui.pages.UserRoleRemove;
69 import org.onap.aaf.auth.gui.pages.WebCommand;
70 import org.onap.aaf.auth.rserv.CachingFileAccess;
71 import org.onap.aaf.auth.server.AbsService;
72 import org.onap.aaf.auth.server.JettyServiceStarter;
73 import org.onap.aaf.auth.server.Log4JLogIt;
74 import org.onap.aaf.cadi.CadiException;
75 import org.onap.aaf.cadi.LocatorException;
76 import org.onap.aaf.cadi.PropAccess;
77 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
78 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
79 import org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker;
80 import org.onap.aaf.cadi.client.Future;
81 import org.onap.aaf.cadi.client.Retryable;
82 import org.onap.aaf.cadi.config.Config;
83 import org.onap.aaf.cadi.http.HTransferSS;
84 import org.onap.aaf.cadi.principal.TaggedPrincipal;
85 import org.onap.aaf.cadi.register.Registrant;
86 import org.onap.aaf.cadi.register.RemoteRegistrant;
87 import org.onap.aaf.misc.env.APIException;
88 import org.onap.aaf.misc.env.Env;
89 import org.onap.aaf.misc.env.Slot;
90 import org.onap.aaf.misc.env.StaticSlot;
91 import org.onap.aaf.misc.env.util.Split;
92 import org.onap.aaf.misc.rosetta.env.RosettaDF;
93 import org.onap.aaf.misc.xgen.html.HTMLGen;
94 import org.onap.aaf.misc.xgen.html.State;
96 import certman.v1_0.Artifacts;
97 import certman.v1_0.CertInfo;
99 public class AAF_GUI extends AbsService<AuthzEnv, AuthzTrans> implements State<Env>{
100 private static final String AAF_GUI_THEME = "aaf_gui_theme";
101 public static final String AAF_GUI_COPYRIGHT = "aaf_gui_copyright";
102 public static final String HTTP_SERVLET_REQUEST = "HTTP_SERVLET_REQUEST";
103 public static final int TIMEOUT = 60000;
104 public static final String app = "AAF GUI";
108 // Certificate manager API
109 public RosettaDF<Artifacts> artifactsDF;
110 public RosettaDF<CertInfo> certInfoDF;
112 private final AAFConHttp cmCon;
113 public final AAFConHttp aafCon;
114 public final AAFLurPerm lur;
116 public final Slot slot_httpServletRequest;
117 protected final String deployedVersion;
118 private StaticSlot sTheme;
119 public final String theme;
122 public AAF_GUI(final AuthzEnv env) throws Exception {
123 super(env.access(), env);
124 sTheme = env.staticSlot(CachingFileAccess.CFA_WEB_PATH,access.getProperty(CachingFileAccess.CFA_WEB_PATH,null)==null?AAF_GUI_THEME:CachingFileAccess.CFA_WEB_PATH);
125 theme = env.getProperty(AAF_GUI_THEME);
127 //OrganizationFactory.setDefaultOrg(env, "org.osaaf.authz.org.att.ATT");
129 slot_httpServletRequest = env.slot(HTTP_SERVLET_REQUEST);
130 String[] component = Split.split(':', access.getProperty(Config.AAF_COMPONENT, "N/A:2.x"));
131 if(component.length>1) {
132 deployedVersion =component[1];
134 deployedVersion = "2.x";
137 // Certificate Manager
138 cmCon = new AAFConHttp(env.access(),Config.CM_URL);
139 artifactsDF = env.newDataFactory(Artifacts.class);
140 certInfoDF = env.newDataFactory(CertInfo.class);
143 /////////////////////////
145 /////////////////////////
147 final Page start = new Display(this, GET, new Home(this)).page();
150 final Page myPerms = new Display(this, GET, new PermsShow(this, start)).page();
151 Page permDetail = new Display(this, GET, new PermDetail(this, start, myPerms)).page();
152 new Display(this, GET, new PermHistory(this,start,myPerms,permDetail));
155 final Page myRoles = new Display(this, GET, new RolesShow(this, start)).page();
156 Page roleDetail = new Display(this, GET, new RoleDetail(this, start, myRoles)).page();
157 new Display(this, POST, new RoleDetailAction(this,start,myRoles,roleDetail));
158 new Display(this, GET, new RoleHistory(this,start,myRoles,roleDetail));
161 final Page myNamespaces = new Display(this, GET, new NssShow(this, start)).page();
162 Page nsDetail = new Display(this, GET, new NsDetail(this, start, myNamespaces)).page();
163 new Display(this, GET, new NsHistory(this, start,myNamespaces,nsDetail));
164 Page crdDetail = new Display(this, GET, new CredDetail(this, start, myNamespaces, nsDetail)).page();
165 Page artiShow = new Display(this, GET, new CMArtifactShow(this, start, myNamespaces, nsDetail, crdDetail)).page();
166 Page artiCForm = new Display(this, GET, new CMArtiChangeForm(this, start, myNamespaces, nsDetail, crdDetail,artiShow)).page();
167 new Display(this, POST, new CMArtiChangeAction(this, start,artiShow,artiCForm));
169 // Password Change Screens
170 final Page pwc = new Display(this, GET, new PassChangeForm(this, start,crdDetail)).page();
171 new Display(this, POST, new PassChangeAction(this, start, pwc));
173 // Password Delete Screen
174 new Display(this, GET, new PassDeleteAction(this, start,crdDetail));
176 // Validation Change Screens
177 final Page validate = new Display(this, GET, new ApprovalForm(this, start)).page();
178 new Display(this, POST, new ApprovalAction(this, start, validate));
180 // Onboard, Detailed Edit Screens
181 final Page onb = new Display(this, GET, new NsInfoForm(this, start)).page();
182 new Display(this, POST, new NsInfoAction(this, start, onb));
184 // Web Command Screens
185 /* final Page webCommand =*/ new Display(this, GET, new WebCommand(this, start)).page();
188 final Page apidocs = new Display(this, GET, new ApiDocs(this, start)).page();
189 new Display(this, GET, new ApiExample(this,start, apidocs)).page();
191 // Permission Grant Page
192 final Page permGrant = new Display(this, GET, new PermGrantForm(this, start)).page();
193 new Display(this, POST, new PermGrantAction(this, start, permGrant)).page();
195 // Login Landing if no credentials detected
196 final Page loginLanding = new Display(this, GET, new LoginLanding(this, start)).page();
197 new Display(this, POST, new LoginLandingAction(this, start, loginLanding));
199 // User Role Request Extend and Remove
200 new Display(this, GET, new UserRoleExtend(this, start,myRoles)).page();
201 new Display(this, GET, new UserRoleRemove(this, start,myRoles)).page();
203 // See my Pending Requests
204 final Page requestsShow = new Display(this, GET, new PendingRequestsShow(this, start)).page();
205 new Display(this, GET, new RequestDetail(this, start, requestsShow));
207 // Command line Mechanism
208 route(env, PUT, "/gui/cui", new CUI(this),"text/plain;charset=utf-8","*/*");
210 ///////////////////////
211 // WebContent Handler
212 ///////////////////////
213 route(env,GET,"/"+env.get(sTheme)+"/:key", new CachingFileAccess<AuthzTrans>(env));
214 ///////////////////////
216 lur = aafCon.newLur();
219 public<T> RosettaDF<T> getDF(Class<T> cls) throws APIException {
220 return Cmd.getDF(env,cls);
223 public void writeError(AuthzTrans trans, Future<?> fp, HTMLGen hgen, int indent) {
225 String msg = aafCon.readableErrMsg(fp);
226 hgen.incr(HTMLGen.P,"style=text-indent:"+indent*10+"px")
227 .text("<font color=\"red\"><i>Error</i>:</font> ")
230 trans.checkpoint(msg);
234 public<RET> RET cmClientAsUser(TaggedPrincipal p,Retryable<RET> retryable) throws APIException, LocatorException, CadiException {
235 return cmCon.hman().best(new HTransferSS(p,app, aafCon.securityInfo()), retryable);
238 public Filter[] filters() throws CadiException, LocatorException {
240 return new Filter[] {
241 new XFrameFilter(XFrameFilter.TYPE.none),
242 new AuthzTransFilter(env,aafCon(),
243 new AAFTrustChecker((Env)env)),
244 new OrgLookupFilter()
246 } catch (NumberFormatException e) {
247 throw new CadiException("Invalid Property information", e);
251 @SuppressWarnings("unchecked")
253 public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException {
254 return new Registrant[] {
255 new RemoteRegistrant<AuthzEnv>(aafCon(),app_name,app_version,port)
259 public static void main(final String[] args) {
261 String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
262 String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
263 String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
264 File logs = new File(log_dir);
265 if(!logs.isDirectory()) {
271 Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "authz");
272 PropAccess propAccess = new PropAccess(logIt,args);
274 AAF_GUI service = new AAF_GUI(new AuthzEnv(propAccess));
275 JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
277 } catch (Exception e) {