Search in sources :

Example 1 with ResetPasswordRequest

use of com.zimbra.soap.account.message.ResetPasswordRequest in project zm-mailbox by Zimbra.

the class ResetPassword method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    if (!checkPasswordSecurity(context)) {
        throw ServiceException.INVALID_REQUEST("clear text password is not allowed", null);
    }
    Provisioning prov = Provisioning.getInstance();
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    ResetPasswordRequest req = JaxbUtil.elementToJaxb(request);
    req.validateResetPasswordRequest();
    AuthToken at = zsc.getAuthToken();
    AuthProvider.validateAuthToken(prov, at, false);
    Account acct = at.getAccount();
    boolean locked = acct.getBooleanAttr(Provisioning.A_zimbraPasswordLocked, false);
    if (locked) {
        throw AccountServiceException.PASSWORD_LOCKED();
    }
    ResetPasswordUtil.validateFeatureResetPasswordStatus(acct);
    String newPassword = req.getPassword();
    checkPasswordStrength(prov, acct, newPassword);
    // proxy if required
    if (!Provisioning.onLocalServer(acct)) {
        try {
            return proxyRequest(request, context, acct.getId());
        } catch (ServiceException e) {
            // if something went wrong proxying the request, just execute it locally
            if (ServiceException.PROXY_ERROR.equals(e.getCode())) {
                ZimbraLog.account.warn("encountered proxy error", e);
            } else {
                // but if it's a real error, it's a real error
                throw e;
            }
        }
    }
    setPasswordAndPurgeAuthTokens(prov, acct, newPassword);
    Element response = zsc.createElement(AccountConstants.E_RESET_PASSWORD_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ResetPasswordRequest(com.zimbra.soap.account.message.ResetPasswordRequest) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning)

Example 2 with ResetPasswordRequest

use of com.zimbra.soap.account.message.ResetPasswordRequest in project zm-mailbox by Zimbra.

the class TestResetPassword method testResetPassword.

@Test
public void testResetPassword() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    Account acct1 = prov.getAccount(USER_NAME);
    acct1.setFeatureResetPasswordStatus(FeatureResetPasswordStatus.enabled);
    ResetPassword resetPassword = new TestResetPassword();
    Map<String, Object> ctxt = ServiceTestUtil.getRequestContext(acct1);
    ResetPasswordRequest resetReq = new ResetPasswordRequest();
    resetReq.setPassword(NEW_PASSWORD);
    Element request = JaxbUtil.jaxbToElement(resetReq);
    try {
        resetPassword.handle(request, ctxt);
    } catch (ServiceException se) {
        Assert.fail("This should not happen");
    }
}
Also used : ResetPassword(com.zimbra.cs.service.account.ResetPassword) Account(com.zimbra.cs.account.Account) ResetPasswordRequest(com.zimbra.soap.account.message.ResetPasswordRequest) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Test(org.junit.Test)

Example 3 with ResetPasswordRequest

use of com.zimbra.soap.account.message.ResetPasswordRequest in project zm-mailbox by Zimbra.

the class TestResetPassword method testResetPassword_FeatureDisabled.

@Test
public void testResetPassword_FeatureDisabled() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    Account acct1 = prov.getAccount(USER_NAME);
    acct1.setFeatureResetPasswordStatus(FeatureResetPasswordStatus.enabled);
    ResetPassword resetPassword = new TestResetPassword();
    Map<String, Object> ctxt = ServiceTestUtil.getRequestContext(acct1);
    ResetPasswordRequest resetReq = new ResetPasswordRequest();
    resetReq.setPassword(NEW_PASSWORD);
    Element request = JaxbUtil.jaxbToElement(resetReq);
    try {
        resetPassword.handle(request, ctxt);
    } catch (ServiceException se) {
        Assert.assertEquals("permission denied: Reset password feature is disabled", se.getMessage());
    }
}
Also used : ResetPassword(com.zimbra.cs.service.account.ResetPassword) Account(com.zimbra.cs.account.Account) ResetPasswordRequest(com.zimbra.soap.account.message.ResetPasswordRequest) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Test(org.junit.Test)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)3 Element (com.zimbra.common.soap.Element)3 Account (com.zimbra.cs.account.Account)3 Provisioning (com.zimbra.cs.account.Provisioning)3 ResetPasswordRequest (com.zimbra.soap.account.message.ResetPasswordRequest)3 ResetPassword (com.zimbra.cs.service.account.ResetPassword)2 Test (org.junit.Test)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1