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;
26 import java.text.ParseException;
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.NamedCode;
32 import org.onap.aaf.auth.gui.Page;
33 import org.onap.aaf.cadi.CadiException;
34 import org.onap.aaf.cadi.client.Future;
35 import org.onap.aaf.cadi.client.Rcli;
36 import org.onap.aaf.cadi.client.Retryable;
37 import org.onap.aaf.misc.env.APIException;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.Slot;
40 import org.onap.aaf.misc.env.TimeTaken;
41 import org.onap.aaf.misc.env.util.Chrono;
42 import org.onap.aaf.misc.xgen.Cache;
43 import org.onap.aaf.misc.xgen.DynamicCode;
44 import org.onap.aaf.misc.xgen.html.HTMLGen;
46 import aaf.v2_0.CredRequest;
48 public class NsInfoAction extends Page {
49 public NsInfoAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException {
50 super(gui.env,"Onboard",PassChangeForm.HREF, PassChangeForm.fields,
51 new BreadCrumbs(breadcrumbs),
52 new NamedCode(true,"content") {
53 final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]);
54 final Slot sCurrPass = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[1]);
55 final Slot sPassword = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[2]);
56 final Slot sPassword2 = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[3]);
57 final Slot startDate = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[4]);
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 {
64 String id = trans.get(sID,null);
65 String currPass = trans.get(sCurrPass,null);
66 final String password = trans.get(sPassword,null);
67 String password2 = trans.get(sPassword2,null);
72 if (id==null || id.indexOf('@')<=0) {
73 hgen.p("Data Entry Failure: Please enter a valid ID, including domain.");
74 } else if (password == null || password2 == null || currPass == null) {
75 hgen.p("Data Entry Failure: Both Password Fields need entries.");
76 } else if (!password.equals(password2)) {
77 hgen.p("Data Entry Failure: Passwords do not match.");
78 } else { // everything else is checked by Server
79 final CredRequest cred = new CredRequest();
81 cred.setPassword(currPass);
83 fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable<Boolean>() {
85 public Boolean code(Rcli<?> client)throws CadiException, ConnectException, APIException {
86 TimeTaken tt = trans.start("Check Current Password",Env.REMOTE);
88 Future<CredRequest> fcr = client.create( // Note: Need "Post", because of hiding password in SSL Data
90 gui.getDF(CredRequest.class),
96 if (fcr.code() == 200) {
97 hgen.p("Current Password validated");
100 hgen.p(String.format("Invalid Current Password: %d %s",fcr.code(),fcr.body()));
105 tt = trans.start("AAF Change Password",Env.REMOTE);
107 // Change over Cred to reset mode
108 cred.setPassword(password);
109 String start = trans.get(startDate, null);
112 cred.setStart(Chrono.timeStamp(Chrono.dateOnlyFmt.parse(start)));
113 } catch (ParseException e) {
114 throw new CadiException(e);
120 gui.getDF(CredRequest.class),
126 hgen.p("New Password has been added.");
129 gui.writeError(trans, fcr, hgen, 0);
142 } catch (Exception e) {
143 hgen.p("Unknown Error");
149 hgen.incr("a",true,"href="+PassChangeForm.HREF+"?id="+id).text("Try again").end();
151 hgen.incr("a",true,"href="+Home.HREF).text("Home").end();