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.cmd.AAFcli;
28 import org.onap.aaf.auth.env.AuthzTrans;
29 import org.onap.aaf.auth.gui.AAF_GUI;
30 import org.onap.aaf.auth.gui.BreadCrumbs;
31 import org.onap.aaf.auth.gui.Page;
32 import org.onap.aaf.auth.gui.SlotCode;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.LocatorException;
35 import org.onap.aaf.cadi.client.Future;
36 import org.onap.aaf.cadi.client.Rcli;
37 import org.onap.aaf.cadi.client.Retryable;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.xgen.Cache;
40 import org.onap.aaf.misc.xgen.DynamicCode;
41 import org.onap.aaf.misc.xgen.html.HTMLGen;
43 import aaf.v2_0.CredRequest;
45 public class PassDeleteAction extends Page {
46 public static final String NAME = "PassDeleteAction";
47 public static final String HREF = "/gui/passdelete";
48 private static enum Params{id,date,ns,type};
50 public PassDeleteAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
51 super(gui.env,NAME,HREF,Params.values(),
52 new BreadCrumbs(breadcrumbs),
53 new SlotCode<AuthzTrans>(true,gui.env,NAME,Params.values()) {
55 public void code(final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
56 cache.dynamic(hgen, new DynamicCode<HTMLGen,AAF_GUI, AuthzTrans>() {
58 public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache<HTMLGen> cache, final HTMLGen hgen) throws APIException, IOException {
59 final CredRequest cr = new CredRequest();
60 cr.setId(get(trans,Params.id, ""));
61 cr.setType(Integer.parseInt(get(trans,Params.type, "0")));
62 cr.setEntry(get(trans,Params.date,"1960-01-01"));
64 String err = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<String>() {
66 public String code(Rcli<?> client) throws CadiException, ConnectException, APIException {
67 Future<CredRequest> fcr = client.delete("/authn/cred", gui.getDF(CredRequest.class),cr);
68 if (!fcr.get(AAFcli.timeout())) {
69 return gui.aafCon.readableErrMsg(fcr);
75 hgen.p("Password " + cr.getId() + ", " + cr.getEntry() + " is Deleted");
79 } catch (LocatorException | CadiException e) {
80 throw new APIException(e);