Search in sources :

Example 1 with AccountSelector

use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.

the class ZMailbox method changePassword.

private ZChangePasswordResult changePassword(String key, AccountBy by, String oldPassword, String newPassword, String virtualHost) throws ServiceException {
    if (mTransport == null) {
        throw ZClientException.CLIENT_ERROR("must call setURI before calling changePassword", null);
    }
    AccountSelector account = new AccountSelector(SoapConverter.TO_SOAP_ACCOUNT_BY.apply(by), key);
    ChangePasswordRequest req = new ChangePasswordRequest(account, oldPassword, newPassword);
    req.setVirtualHost(virtualHost);
    ChangePasswordResponse res = invokeJaxb(req);
    return new ZChangePasswordResult(res);
}
Also used : AccountSelector(com.zimbra.soap.type.AccountSelector) ChangePasswordResponse(com.zimbra.soap.account.message.ChangePasswordResponse) ChangePasswordRequest(com.zimbra.soap.account.message.ChangePasswordRequest)

Example 2 with AccountSelector

use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.

the class ZMailbox method authByPassword.

public ZAuthResult authByPassword(Options options, String password) throws ServiceException {
    if (mTransport == null) {
        throw ZClientException.CLIENT_ERROR("must call setURI before calling authenticate", null);
    }
    AccountSelector account = new AccountSelector(com.zimbra.soap.type.AccountBy.name, options.getAccount());
    AuthRequest auth = new AuthRequest(account, password);
    auth.setPassword(password);
    auth.setTwoFactorCode(options.getTwoFactorCode());
    auth.setVirtualHost(options.getVirtualHost());
    auth.setRequestedSkin(options.getRequestedSkin());
    auth.setCsrfSupported(options.getCsrfSupported());
    auth.setDeviceTrusted(options.getTrustedDevice());
    if (options.getTrustedDevice()) {
        auth.setDeviceTrusted(true);
    }
    if (options.getAuthToken() != null) {
        auth.setAuthToken(new AuthToken(options.getAuthToken().getValue(), false));
    }
    if (options.getDeviceId() != null) {
        auth.setDeviceId(options.getDeviceId());
    }
    if (options.getTrustedDeviceToken() != null) {
        auth.setTrustedDeviceToken(options.getTrustedDeviceToken());
    }
    if (options.getGenerateDeviceId()) {
        auth.setGenerateDeviceId(true);
    }
    addAttrsAndPrefs(auth, options);
    AuthResponse authRes = invokeJaxb(auth);
    ZAuthResult r = new ZAuthResult(authRes);
    r.setSessionId(mTransport.getSessionId());
    return r;
}
Also used : EnableTwoFactorAuthRequest(com.zimbra.soap.account.message.EnableTwoFactorAuthRequest) DisableTwoFactorAuthRequest(com.zimbra.soap.account.message.DisableTwoFactorAuthRequest) AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) AuthToken(com.zimbra.soap.account.type.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) AuthResponse(com.zimbra.soap.account.message.AuthResponse) EnableTwoFactorAuthResponse(com.zimbra.soap.account.message.EnableTwoFactorAuthResponse) DisableTwoFactorAuthResponse(com.zimbra.soap.account.message.DisableTwoFactorAuthResponse)

Example 3 with AccountSelector

use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.

the class GetAdminConsoleUIComp method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAdminConsoleUICompRequest req = JaxbUtil.elementToJaxb(request);
    AccountSelector accountSel = req.getAccount();
    DistributionListSelector dlSel = req.getDl();
    Element resp = zsc.createElement(AdminConstants.GET_ADMIN_CONSOLE_UI_COMP_RESPONSE);
    if ((null != accountSel) && (null != dlSel)) {
        throw ServiceException.INVALID_REQUEST("can only specify eith account or dl", null);
    }
    Account authedAcct = getAuthenticatedAccount(zsc);
    Set<String> added = new HashSet<String>();
    GroupMembership aclGroups = null;
    if (accountSel != null) {
        AccountBy by = accountSel.getBy().toKeyAccountBy();
        String key = accountSel.getKey();
        Account acct = prov.get(by, key);
        AccountHarvestingCheckerUsingCheckRight checker = new AccountHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewAccountAdminUI);
        if (acct == null) {
            defendAgainstAccountHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            if (!authedAcct.getId().equals(acct.getId())) {
                defendAgainstAccountHarvesting(acct, by, key, zsc, checker);
            }
            addValues(acct, resp, added, false);
            aclGroups = prov.getGroupMembership(acct, true);
        }
    } else if (dlSel != null) {
        Key.DistributionListBy by = dlSel.getBy().toKeyDistributionListBy();
        String key = dlSel.getKey();
        DistributionList dl = prov.getDLBasic(by, key);
        GroupHarvestingCheckerUsingCheckRight checker = new GroupHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewDistributionListAdminUI);
        if (dl == null) {
            defendAgainstGroupHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            defendAgainstGroupHarvesting(dl, by, key, zsc, checker);
            addValues(dl, resp, added, false);
            aclGroups = prov.getGroupMembership(dl, true);
        }
    } else {
        // use the authed account
        addValues(authedAcct, resp, added, false);
        aclGroups = prov.getGroupMembership(authedAcct, true);
    }
    if (aclGroups != null) {
        for (String groupId : aclGroups.groupIds()) {
            DistributionList dl = prov.get(Key.DistributionListBy.id, groupId);
            addValues(dl, resp, added, true);
        }
    }
    return resp;
}
Also used : Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAdminConsoleUICompRequest(com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest) HashSet(java.util.HashSet) DistributionList(com.zimbra.cs.account.DistributionList)

Example 4 with AccountSelector

use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.

the class TestAuthentication method testAccountLockout.

public void testAccountLockout() throws Exception {
    String wrongPassword1 = "test1234";
    String wrongPassword2 = "test12345";
    Account acct = TestUtil.getAccount(USER_NAME);
    acct.setPasswordLockoutMaxFailures(2);
    acct.setPasswordLockoutEnabled(true);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
    AuthRequest req = new AuthRequest(acctSel, wrongPassword1);
    // Verify lockout happen after 2 invalid login using same password.
    Element resp;
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
    // Add Soap protocol to PasswordLockoutSuppressionProtocols
    acct.setPasswordLockoutSuppressionProtocols(PasswordLockoutSuppressionProtocols.soap);
    // Verify lock out should not happen after 2 invalid login using same password and next login with different invalid password should be locked out.
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not active", acct.getAccountStatus().equals(AccountStatus.active));
    req = new AuthRequest(acctSel, wrongPassword2);
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
    acct.setPasswordLockoutSuppressionEnabled(false);
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 5 with AccountSelector

use of com.zimbra.soap.type.AccountSelector in project zm-mailbox by Zimbra.

the class TestAuthentication method testAuthViaPreauthToken.

/**
     * test auth request with preauth in SOAP instead of login/password
     * @throws Exception
     */
public void testAuthViaPreauthToken() throws Exception {
    long timestamp = System.currentTimeMillis();
    long expires = timestamp + 60000;
    String domainPreAuthKey = setUpAndReturnDomainAuthKey();
    Account a = TestUtil.getAccount(USER_NAME);
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AuthRequest req = new AuthRequest(acctSel);
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("account", a.getName());
    params.put("by", "name");
    params.put("timestamp", timestamp + "");
    params.put("expires", expires + "");
    PreAuth preAuth = new PreAuth().setExpires(expires).setTimestamp(timestamp).setValue(PreAuthKey.computePreAuth(params, domainPreAuthKey));
    req = req.setPreauth(preAuth);
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    assertTrue("Lifetime is invalid", authResp.getLifetime() < expires - timestamp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    assertTrue("should have a received a non-empty authtoken", newAuthToken.length() > 0);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    assertTrue("new auth token should be registered", at.isRegistered());
    assertFalse("new auth token should not be expired yet", at.isExpired());
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) PreAuth(com.zimbra.soap.account.type.PreAuth) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) AuthToken(com.zimbra.cs.account.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Aggregations

AccountSelector (com.zimbra.soap.type.AccountSelector)14 Account (com.zimbra.cs.account.Account)9 Element (com.zimbra.common.soap.Element)8 AuthRequest (com.zimbra.soap.account.message.AuthRequest)7 Provisioning (com.zimbra.cs.account.Provisioning)5 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 AuthResponse (com.zimbra.soap.account.message.AuthResponse)4 ServiceException (com.zimbra.common.service.ServiceException)3 AuthToken (com.zimbra.cs.account.AuthToken)3 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)3 Test (org.junit.Test)3 AccountBy (com.zimbra.common.account.Key.AccountBy)2 ZAuthToken (com.zimbra.common.auth.ZAuthToken)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Domain (com.zimbra.cs.account.Domain)2 Server (com.zimbra.cs.account.Server)2 ChangePasswordRequest (com.zimbra.soap.account.message.ChangePasswordRequest)2 GalMode (com.zimbra.soap.admin.type.GalMode)2 AccountBy (com.zimbra.soap.type.AccountBy)2