Skip to content

Commit c34b295

Browse files
k-katodasiyogesh
authored andcommitted
ZCS-15589: fixed change password
1 parent 17d7281 commit c34b295

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

client/src/java/com/zimbra/client/ZAuthResult.java

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ZAuthResult {
3737
private List<String> twoFactorAuthMethodEnabled;
3838
private String primaryTwoFactorAuthMethod;
3939
private String maskedPasswordRecoveryAddress;
40+
private boolean resetPassword;
4041

4142
/*
4243
public ZAuthResult(Element e) throws ServiceException {
@@ -63,6 +64,7 @@ public ZAuthResult(AuthResponse res) {
6364
twoFactorAuthMethodEnabled = data.getTwoFactorAuthMethodEnabled();
6465
primaryTwoFactorAuthMethod = data.getPrefPrimaryTwoFactorAuthMethod();
6566
maskedPasswordRecoveryAddress = data.getPrefPasswordRecoveryAddress();
67+
resetPassword = ZmBoolean.toBool(data.getResetPassword(), false);
6668
}
6769

6870
public ZAuthToken getAuthToken() {
@@ -149,4 +151,8 @@ public String getPrimaryTwoFactorAuthMethod() {
149151
public String getMaskedPasswordRecoveryAddress() {
150152
return maskedPasswordRecoveryAddress;
151153
}
154+
155+
public boolean getResetPassword() {
156+
return resetPassword;
157+
}
152158
}

client/src/java/com/zimbra/client/ZMailbox.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,9 @@ public static ZChangePasswordResult changePassword(Options options) throws Servi
702702
mailbox.mClientIp = options.getClientIp();
703703
mailbox.mNotifyPreference = SessionPreference.fromOptions(options);
704704
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);
706708
}
707709

708710
public static ZMailbox getByName(String name, String password, String uri) throws ServiceException {
@@ -744,7 +746,7 @@ public ZMailbox(Options options) throws ServiceException {
744746
* always the case. */
745747
initTargetAccountInfo(options.getTargetAccount(), options.getTargetAccountBy());
746748
}
747-
if (options.getAuthToken() != null) {
749+
if (options.getAuthToken() != null && options.getNewPassword() == null) {
748750
if (options.getAuthAuthToken()) {
749751
authByAuthToken(options);
750752
} else {
@@ -753,8 +755,11 @@ public ZMailbox(Options options) throws ServiceException {
753755
} else if (options.getAccount() != null) {
754756
String password;
755757
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);
757761
password = options.getNewPassword();
762+
options.setAuthToken((ZAuthToken)null);
758763
} else {
759764
password = options.getPassword();
760765
}
@@ -828,15 +833,20 @@ public Element newRequestElement(QName name) {
828833
}
829834
}
830835

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 {
832838
if (mTransport == null) {
833839
throw ZClientException.CLIENT_ERROR("must call setURI before calling changePassword", null);
834840
}
835841

836842
AccountSelector account = new AccountSelector(SoapConverter.TO_SOAP_ACCOUNT_BY.apply(by), key);
837843
ChangePasswordRequest req = new ChangePasswordRequest(account, oldPassword, newPassword);
838844
req.setVirtualHost(virtualHost);
839-
initAuthToken(zat);
845+
if (authTokenAsAttr) {
846+
req.setAuthToken(new AuthToken(zat.getValue(), false));
847+
} else {
848+
initAuthToken(zat);
849+
}
840850
initCsrfToken(csrfToken);
841851

842852
ChangePasswordResponse res = invokeJaxb(req);

0 commit comments

Comments
 (0)