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.pages;
24 import java.io.IOException;
25 import java.net.ConnectException;
27 import org.onap.aaf.auth.env.AuthzTrans;
28 import org.onap.aaf.auth.gui.AAF_GUI;
29 import org.onap.aaf.auth.gui.BreadCrumbs;
30 import org.onap.aaf.auth.gui.NamedCode;
31 import org.onap.aaf.auth.gui.Page;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
35 import org.onap.aaf.cadi.client.Retryable;
36 import org.onap.aaf.misc.env.APIException;
37 import org.onap.aaf.misc.env.Env;
38 import org.onap.aaf.misc.env.Slot;
39 import org.onap.aaf.misc.env.TimeTaken;
40 import org.onap.aaf.misc.xgen.Cache;
41 import org.onap.aaf.misc.xgen.DynamicCode;
42 import org.onap.aaf.misc.xgen.html.HTMLGen;
45 import aaf.v2_0.RolePermRequest;
47 public class PermGrantAction extends Page {
50 public PermGrantAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
51 super(gui.env,PermGrantForm.NAME, PermGrantForm.HREF, PermGrantForm.fields,
52 new BreadCrumbs(breadcrumbs),
53 new NamedCode(true,"content") {
54 final Slot sType = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[0]);
55 final Slot sInstance = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[1]);
56 final Slot sAction = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[2]);
57 final Slot sRole = gui.env.slot(PermGrantForm.NAME+'.'+PermGrantForm.fields[3]);
60 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
61 cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI, AuthzTrans>() {
63 public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
65 String type = trans.get(sType,null);
66 String instance = trans.get(sInstance,null);
67 String action = trans.get(sAction,null);
68 String role = trans.get(sRole,null);
70 String lastPage = PermGrantForm.HREF
71 + "?type=" + type + "&instance=" + instance + "&action=" + action;
76 TimeTaken tt = trans.start("AAF Grant Permission to Role",Env.REMOTE);
79 final RolePermRequest grantReq = new RolePermRequest();
80 Pkey pkey = new Pkey();
82 pkey.setInstance(instance);
83 pkey.setAction(action);
84 grantReq.setPerm(pkey);
85 grantReq.setRole(role);
87 fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Boolean>() {
89 public Boolean code(Rcli<?> client) throws CadiException, ConnectException, APIException {
91 Future<RolePermRequest> fgrant = client.create(
93 gui.getDF(RolePermRequest.class),
97 if(fgrant.get(5000)) {
98 hgen.p("Permission has been granted to role.");
101 if (202==fgrant.code()) {
102 hgen.p("Permission Grant Request sent, but must be Approved before actualizing");
105 gui.writeError(trans, fgrant, hgen, 0);
111 } catch (Exception e) {
112 hgen.p("Unknown Error");
119 hgen.incr("a",true,"href="+lastPage);
121 hgen.text("Try again");
123 hgen.text("Grant this Permission to Another Role");
127 .text("alterLink('permgrant', '"+lastPage + "');")