X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-gui%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fgui%2Fpages%2FPassChangeAction.java;h=aafd0c9630eedd1c79a023201119eefab02b47f5;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=d0d03a7abdd63308a987cbcebe4067ce609bae9d;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/PassChangeAction.java b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/PassChangeAction.java index d0d03a7a..aafd0c96 100644 --- a/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/PassChangeAction.java +++ b/auth/auth-gui/src/main/java/org/onap/aaf/auth/gui/pages/PassChangeAction.java @@ -55,157 +55,157 @@ import aaf.v2_0.Users; public class PassChangeAction extends Page { - public PassChangeAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { - super(gui.env,PassChangeForm.NAME,PassChangeForm.HREF, PassChangeForm.fields, - new BreadCrumbs(breadcrumbs), - new NamedCode(true,"content") { - final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]); - final Slot sCurrPass = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[1]); - final Slot sPassword = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[2]); - final Slot sPassword2 = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[3]); - final Slot startDate = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[4]); - final Slot sNS = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[5]); - - @Override - public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { - cache.dynamic(hgen, new DynamicCode() { - @Override - public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache cache, final HTMLGen hgen) throws APIException, IOException { - final String id = trans.get(sID,null); - final String currPass = trans.get(sCurrPass,null); - final String password = trans.get(sPassword,null); - final String password2 = trans.get(sPassword2,null); - final String ns = trans.get(sNS, null); - - // Run Validations - boolean fail = true; - - if (id==null || id.indexOf('@')<=0) { - hgen.p("Data Entry Failure: Please enter a valid ID, including domain."); - } else if(password == null || password2 == null) { - hgen.p("Data Entry Failure: Both Password Fields need entries."); - } else if(!password.equals(password2)) { - hgen.p("Data Entry Failure: Passwords do not match."); - } else { // everything else is checked by Server - final CredRequest cred = new CredRequest(); - cred.setId(id); - cred.setPassword("".equals(currPass)?null:currPass); - try { - fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { - @Override - public Boolean code(Rcli client)throws CadiException, ConnectException, APIException { - boolean fail = true; - boolean go = false; - try { - Organization org = OrganizationFactory.obtain(trans.env(), id); - if(org!=null) { - go = PassChangeForm.skipCurrent(trans, org.getIdentity(trans, id)); - } - } catch(OrganizationException e) { - trans.error().log(e); - } + public PassChangeAction(final AAF_GUI gui, final Page ... breadcrumbs) throws APIException, IOException { + super(gui.env,PassChangeForm.NAME,PassChangeForm.HREF, PassChangeForm.fields, + new BreadCrumbs(breadcrumbs), + new NamedCode(true,"content") { + final Slot sID = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[0]); + final Slot sCurrPass = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[1]); + final Slot sPassword = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[2]); + final Slot sPassword2 = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[3]); + final Slot startDate = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[4]); + final Slot sNS = gui.env.slot(PassChangeForm.NAME+'.'+PassChangeForm.fields[5]); + + @Override + public void code(final Cache cache, final HTMLGen hgen) throws APIException, IOException { + cache.dynamic(hgen, new DynamicCode() { + @Override + public void code(final AAF_GUI gui, final AuthzTrans trans,final Cache cache, final HTMLGen hgen) throws APIException, IOException { + final String id = trans.get(sID,null); + final String currPass = trans.get(sCurrPass,null); + final String password = trans.get(sPassword,null); + final String password2 = trans.get(sPassword2,null); + final String ns = trans.get(sNS, null); + + // Run Validations + boolean fail = true; + + if (id==null || id.indexOf('@')<=0) { + hgen.p("Data Entry Failure: Please enter a valid ID, including domain."); + } else if(password == null || password2 == null) { + hgen.p("Data Entry Failure: Both Password Fields need entries."); + } else if(!password.equals(password2)) { + hgen.p("Data Entry Failure: Passwords do not match."); + } else { // everything else is checked by Server + final CredRequest cred = new CredRequest(); + cred.setId(id); + cred.setPassword("".equals(currPass)?null:currPass); + try { + fail = gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client)throws CadiException, ConnectException, APIException { + boolean fail = true; + boolean go = false; + try { + Organization org = OrganizationFactory.obtain(trans.env(), id); + if(org!=null) { + go = PassChangeForm.skipCurrent(trans, org.getIdentity(trans, id)); + } + } catch(OrganizationException e) { + trans.error().log(e); + } - if(cred.getPassword()==null) { - try { - if(!go) { - go=gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { - @Override - public Boolean code(Rcli client) throws CadiException, ConnectException, APIException { - Future fc = client.read("/authn/creds/id/"+id,gui.getDF(Users.class)); - if(fc.get(AAFcli.timeout())) { - GregorianCalendar now = new GregorianCalendar(); - for(aaf.v2_0.Users.User u : fc.value.getUser()) { - if(u.getType()<10 && u.getExpires().toGregorianCalendar().after(now)) { - return false; // an existing, non expired, password type exists - } - } - return true; // no existing, no expired password - } else { - if(fc.code()==404) { // not found... - return true; - } else { - trans.error().log(gui.aafCon.readableErrMsg(fc)); - } - } - return false; - } - }); - } - if(!go) { - hgen.p("Current Password required").br(); - } - } catch (LocatorException e) { - trans.error().log(e); - } + if(cred.getPassword()==null) { + try { + if(!go) { + go=gui.clientAsUser(trans.getUserPrincipal(), new Retryable() { + @Override + public Boolean code(Rcli client) throws CadiException, ConnectException, APIException { + Future fc = client.read("/authn/creds/id/"+id,gui.getDF(Users.class)); + if(fc.get(AAFcli.timeout())) { + GregorianCalendar now = new GregorianCalendar(); + for(aaf.v2_0.Users.User u : fc.value.getUser()) { + if(u.getType()<10 && u.getExpires().toGregorianCalendar().after(now)) { + return false; // an existing, non expired, password type exists + } + } + return true; // no existing, no expired password + } else { + if(fc.code()==404) { // not found... + return true; + } else { + trans.error().log(gui.aafCon.readableErrMsg(fc)); + } + } + return false; + } + }); + } + if(!go) { + hgen.p("Current Password required").br(); + } + } catch (LocatorException e) { + trans.error().log(e); + } - } else { - TimeTaken tt = trans.start("Check Current Password",Env.REMOTE); - try { - // Note: Need "Post", because of hiding password in SSL Data - Future fcr = client.create("/authn/validate",gui.getDF(CredRequest.class),cred); - fcr.get(5000); - if(fcr.code() == 200) { - hgen.p("Current Password validated").br(); - go = true; - } else { - hgen.p(Cred.ATTEMPT_FAILED_SPECIFICS_WITHELD).br(); - trans.info().log("Failed Validation",fcr.code(),fcr.body()); - go = false; - } - } finally { - tt.done(); - } - } - if(go) { - TimeTaken tt = trans.start("AAF Change Password",Env.REMOTE); - try { - // Change over Cred to reset mode - cred.setPassword(password); - String start = trans.get(startDate, null); - if(start!=null) { - try { - cred.setStart(Chrono.timeStamp(Chrono.dateOnlyFmt.parse(start))); - } catch (ParseException e) { - throw new CadiException(e); - } - } - - Future fcr = gui.clientAsUser(trans.getUserPrincipal()).create("/authn/cred",gui.getDF(CredRequest.class),cred); - if(fcr.get(AAFcli.timeout())) { - // Do Remote Call - hgen.p("New Password has been added. The previous one is still valid until Expiration."); - fail = false; - } else { - hgen.p(Cred.ATTEMPT_FAILED_SPECIFICS_WITHELD).br(); - trans.info().log("Failed Validation",fcr.code(),fcr.body()); - } - } finally { - tt.done(); - } - } - return fail; - } - - }); - } catch (Exception e) { - hgen.p("Unknown Error"); - e.printStackTrace(); - } - - } - hgen.br(); - if(fail) { - hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+PassChangeForm.HREF+"?id="+id).text("Try again").end(); - } else { - if(ns==null) { - hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+Home.HREF).text("Back").end(); - } else { - hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+CredDetail.HREF+"?id="+id+"&ns="+ns).text("Back").end(); - } - } - } - }); - } - }); - } + } else { + TimeTaken tt = trans.start("Check Current Password",Env.REMOTE); + try { + // Note: Need "Post", because of hiding password in SSL Data + Future fcr = client.create("/authn/validate",gui.getDF(CredRequest.class),cred); + fcr.get(5000); + if(fcr.code() == 200) { + hgen.p("Current Password validated").br(); + go = true; + } else { + hgen.p(Cred.ATTEMPT_FAILED_SPECIFICS_WITHELD).br(); + trans.info().log("Failed Validation",fcr.code(),fcr.body()); + go = false; + } + } finally { + tt.done(); + } + } + if(go) { + TimeTaken tt = trans.start("AAF Change Password",Env.REMOTE); + try { + // Change over Cred to reset mode + cred.setPassword(password); + String start = trans.get(startDate, null); + if(start!=null) { + try { + cred.setStart(Chrono.timeStamp(Chrono.dateOnlyFmt.parse(start))); + } catch (ParseException e) { + throw new CadiException(e); + } + } + + Future fcr = gui.clientAsUser(trans.getUserPrincipal()).create("/authn/cred",gui.getDF(CredRequest.class),cred); + if(fcr.get(AAFcli.timeout())) { + // Do Remote Call + hgen.p("New Password has been added. The previous one is still valid until Expiration."); + fail = false; + } else { + hgen.p(Cred.ATTEMPT_FAILED_SPECIFICS_WITHELD).br(); + trans.info().log("Failed Validation",fcr.code(),fcr.body()); + } + } finally { + tt.done(); + } + } + return fail; + } + + }); + } catch (Exception e) { + hgen.p("Unknown Error"); + e.printStackTrace(); + } + + } + hgen.br(); + if(fail) { + hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+PassChangeForm.HREF+"?id="+id).text("Try again").end(); + } else { + if(ns==null) { + hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+Home.HREF).text("Back").end(); + } else { + hgen.incr(HTMLGen.A,true,"class=greenbutton","href="+CredDetail.HREF+"?id="+id+"&ns="+ns).text("Back").end(); + } + } + } + }); + } + }); + } }