@@ -702,7 +702,9 @@ public static ZChangePasswordResult changePassword(Options options) throws Servi
702
702
mailbox .mClientIp = options .getClientIp ();
703
703
mailbox .mNotifyPreference = SessionPreference .fromOptions (options );
704
704
mailbox .initPreAuth (options );
705
- return mailbox .changePassword (options .getAccount (), options .getAccountBy (), options .getPassword (), options .getNewPassword (), options .getVirtualHost (), options .getAuthToken (), options .getCsrfToken ());
705
+ return mailbox .changePassword (options .getAccount (), options .getAccountBy (), options .getPassword (),
706
+ options .getNewPassword (), options .getVirtualHost (), options .getAuthToken (),
707
+ options .getCsrfToken (), false );
706
708
}
707
709
708
710
public static ZMailbox getByName (String name , String password , String uri ) throws ServiceException {
@@ -744,7 +746,7 @@ public ZMailbox(Options options) throws ServiceException {
744
746
* always the case. */
745
747
initTargetAccountInfo (options .getTargetAccount (), options .getTargetAccountBy ());
746
748
}
747
- if (options .getAuthToken () != null ) {
749
+ if (options .getAuthToken () != null && options . getNewPassword () == null ) {
748
750
if (options .getAuthAuthToken ()) {
749
751
authByAuthToken (options );
750
752
} else {
@@ -753,8 +755,11 @@ public ZMailbox(Options options) throws ServiceException {
753
755
} else if (options .getAccount () != null ) {
754
756
String password ;
755
757
if (options .getNewPassword () != null ) {
756
- changePassword (options .getAccount (), options .getAccountBy (), options .getPassword (), options .getNewPassword (), options .getVirtualHost (), options .getAuthToken (), options .getCsrfToken ());
758
+ changePassword (options .getAccount (), options .getAccountBy (), options .getPassword (),
759
+ options .getNewPassword (), options .getVirtualHost (), options .getAuthToken (),
760
+ options .getCsrfToken (), true );
757
761
password = options .getNewPassword ();
762
+ options .setAuthToken ((ZAuthToken )null );
758
763
} else {
759
764
password = options .getPassword ();
760
765
}
@@ -828,15 +833,20 @@ public Element newRequestElement(QName name) {
828
833
}
829
834
}
830
835
831
- private ZChangePasswordResult changePassword (String key , AccountBy by , String oldPassword , String newPassword , String virtualHost , ZAuthToken zat , String csrfToken ) throws ServiceException {
836
+ private ZChangePasswordResult changePassword (String key , AccountBy by , String oldPassword , String newPassword ,
837
+ String virtualHost , ZAuthToken zat , String csrfToken , boolean authTokenAsAttr ) throws ServiceException {
832
838
if (mTransport == null ) {
833
839
throw ZClientException .CLIENT_ERROR ("must call setURI before calling changePassword" , null );
834
840
}
835
841
836
842
AccountSelector account = new AccountSelector (SoapConverter .TO_SOAP_ACCOUNT_BY .apply (by ), key );
837
843
ChangePasswordRequest req = new ChangePasswordRequest (account , oldPassword , newPassword );
838
844
req .setVirtualHost (virtualHost );
839
- initAuthToken (zat );
845
+ if (authTokenAsAttr ) {
846
+ req .setAuthToken (new AuthToken (zat .getValue (), false ));
847
+ } else {
848
+ initAuthToken (zat );
849
+ }
840
850
initCsrfToken (csrfToken );
841
851
842
852
ChangePasswordResponse res = invokeJaxb (req );
0 commit comments