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;
44 public class UserRoleRemove extends Page {
45 public static final String HREF = "/gui/urRemove";
46 static final String NAME = "Remove User Role";
47 static final String fields[] = {"user","role"};
49 public UserRoleRemove(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
50 super(gui.env,NAME, HREF, fields,
51 new BreadCrumbs(breadcrumbs),
52 new NamedCode(true, "content") {
54 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
55 final Slot sUser = gui.env.slot(NAME+".user");
56 final Slot sRole = gui.env.slot(NAME+".role");
59 cache.dynamic(hgen, new DynamicCode<HTMLGen, AAF_GUI, AuthzTrans>() {
61 public void code(final AAF_GUI gui, final AuthzTrans trans, final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
62 final String user = trans.get(sUser, "");
63 final String role = trans.get(sRole, "");
65 TimeTaken tt = trans.start("Request a user role delete",Env.REMOTE);
67 gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Void>() {
69 public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
70 Future<Void> fv = client.delete(
71 "/authz/userRole/"+user+"/"+role+"?request=true",Void.class);
74 // not sure if we'll ever hit this
75 hgen.p("User ["+ user+"] Removed from Role [" +role+"]");
77 if (fv.code() == 202 ) {
78 hgen.p("User ["+ user+"] Removal from Role [" +role+"] sent for Approval");
80 gui.writeError(trans, fv, hgen, 0);
86 } catch (Exception e) {