2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 IBM.
7 * ===========================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END====================================================
23 package org.onap.aaf.auth.gui.pages;
25 import java.io.IOException;
26 import java.net.ConnectException;
28 import org.onap.aaf.auth.cmd.AAFcli;
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.auth.gui.AAF_GUI;
31 import org.onap.aaf.auth.gui.BreadCrumbs;
32 import org.onap.aaf.auth.gui.Page;
33 import org.onap.aaf.auth.gui.SlotCode;
34 import org.onap.aaf.cadi.CadiException;
35 import org.onap.aaf.cadi.LocatorException;
36 import org.onap.aaf.cadi.client.Future;
37 import org.onap.aaf.cadi.client.Rcli;
38 import org.onap.aaf.cadi.client.Retryable;
39 import org.onap.aaf.misc.env.APIException;
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 import aaf.v2_0.CredRequest;
46 public class PassDeleteAction extends Page {
47 public static final String CLASS = "PassDeleteAction";
48 public static final String HREF = "/gui/passdelete";
49 private enum Params{id,date,ns,type};
51 public PassDeleteAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
52 super(gui.env,CLASS,HREF,Params.values(),
53 new BreadCrumbs(breadcrumbs),
54 new SlotCode<AuthzTrans>(true,gui.env,CLASS,Params.values()) {
56 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
57 cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI, AuthzTrans>() {
59 public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
60 final CredRequest cr = new CredRequest();
61 cr.setId(get(trans,Params.id, ""));
62 cr.setType(Integer.parseInt(get(trans,Params.type, "0")));
63 cr.setEntry(get(trans,Params.date,"1960-01-01"));
65 String err = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<String>() {
67 public String code(Rcli<?> client) throws CadiException, ConnectException, APIException {
68 Future<CredRequest> fcr = client.delete("/authn/cred", gui.getDF(CredRequest.class),cr);
69 if (!fcr.get(AAFcli.timeout())) {
70 return gui.aafCon.readableErrMsg(fcr);
76 hgen.p("Password " + cr.getId() + ", " + cr.getEntry() + " is Deleted");
80 } catch (LocatorException | CadiException e) {
81 throw new APIException(e);