Search in sources :

Example 1 with AuthRequest

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

the class ZMailbox method authByAuthToken.

public ZAuthResult authByAuthToken(Options options) throws ServiceException {
    if (mTransport == null) {
        throw ZClientException.CLIENT_ERROR("must call setURI before calling authenticate", null);
    }
    AuthRequest req = new AuthRequest();
    // cannot be null here
    ZAuthToken zat = options.getAuthToken();
    req.setAuthToken(new AuthToken(zat.getValue(), false));
    req.setTwoFactorCode(options.getTwoFactorCode());
    req.setRequestedSkin(options.getRequestedSkin());
    req.setCsrfSupported(options.getCsrfSupported());
    req.setDeviceTrusted(options.getTrustedDevice());
    addAttrsAndPrefs(req, options);
    AuthResponse res = invokeJaxb(req);
    ZAuthResult r = new ZAuthResult(res);
    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) AuthToken(com.zimbra.soap.account.type.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) 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 2 with AuthRequest

use of com.zimbra.soap.account.message.AuthRequest 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 AuthRequest

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

the class AuthRequestTest method testBuildAuthRequestWithPassword.

@Test
public void testBuildAuthRequestWithPassword() {
    AuthRequest authRequest = new AuthRequest();
    authRequest.setAccount(AccountSelector.fromName(username));
    authRequest.setPassword(password);
    try {
        Element element = JaxbUtil.jaxbToElement(authRequest);
        String xml = element.toString();
        assertTrue(element.hasChildren());
        Element account = element.getElement("account");
        Element pwdE = element.getElement("password");
        assertEquals("Username embedded in request is incorrect", username, account.getText());
        assertEquals("Password embedded in request is incorrect", password, pwdE.getText());
    } catch (ServiceException e) {
        fail("Encountered an exception: " + e);
    }
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 4 with AuthRequest

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

the class SoapTest method authUser.

static SoapTransport authUser(String acctName, String password) throws Exception {
    com.zimbra.soap.type.AccountSelector acct = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acctName);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(soapDebugListener);
    AuthRequest req = new AuthRequest(acct, password);
    AuthResponse resp = invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    return transport;
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse)

Example 5 with AuthRequest

use of com.zimbra.soap.account.message.AuthRequest 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)

Aggregations

AuthRequest (com.zimbra.soap.account.message.AuthRequest)15 AuthResponse (com.zimbra.soap.account.message.AuthResponse)9 AccountSelector (com.zimbra.soap.type.AccountSelector)9 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)8 Element (com.zimbra.common.soap.Element)7 Test (org.junit.Test)6 Account (com.zimbra.cs.account.Account)5 ZAuthToken (com.zimbra.common.auth.ZAuthToken)4 ServiceException (com.zimbra.common.service.ServiceException)3 AuthToken (com.zimbra.cs.account.AuthToken)3 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)3 AuthToken (com.zimbra.soap.account.type.AuthToken)3 JSONElement (com.zimbra.common.soap.Element.JSONElement)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 DisableTwoFactorAuthRequest (com.zimbra.soap.account.message.DisableTwoFactorAuthRequest)2 DisableTwoFactorAuthResponse (com.zimbra.soap.account.message.DisableTwoFactorAuthResponse)2 EnableTwoFactorAuthRequest (com.zimbra.soap.account.message.EnableTwoFactorAuthRequest)2 EnableTwoFactorAuthResponse (com.zimbra.soap.account.message.EnableTwoFactorAuthResponse)2 PreAuth (com.zimbra.soap.account.type.PreAuth)2 LmcAdminAuthRequest (com.zimbra.cs.client.soap.LmcAdminAuthRequest)1