Search in sources :

Example 1 with AuthResponse

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

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

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

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

Example 5 with AuthResponse

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

the class TestUtil method authUser.

public 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());
    AuthRequest req = new AuthRequest(acct, password);
    AuthResponse resp = SoapTest.invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    return transport;
}
Also used : AccountSelector(com.zimbra.soap.type.AccountSelector) LmcAuthRequest(com.zimbra.cs.client.soap.LmcAuthRequest) AuthRequest(com.zimbra.soap.account.message.AuthRequest) LmcAdminAuthRequest(com.zimbra.cs.client.soap.LmcAdminAuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse) LmcAuthResponse(com.zimbra.cs.client.soap.LmcAuthResponse) LmcAdminAuthResponse(com.zimbra.cs.client.soap.LmcAdminAuthResponse)

Aggregations

AuthRequest (com.zimbra.soap.account.message.AuthRequest)9 AuthResponse (com.zimbra.soap.account.message.AuthResponse)9 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)7 AccountSelector (com.zimbra.soap.type.AccountSelector)6 ZAuthToken (com.zimbra.common.auth.ZAuthToken)4 Account (com.zimbra.cs.account.Account)4 Element (com.zimbra.common.soap.Element)3 AuthToken (com.zimbra.cs.account.AuthToken)3 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)3 AuthToken (com.zimbra.soap.account.type.AuthToken)3 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 Test (org.junit.Test)2 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 LmcAdminAuthRequest (com.zimbra.cs.client.soap.LmcAdminAuthRequest)1 LmcAdminAuthResponse (com.zimbra.cs.client.soap.LmcAdminAuthResponse)1 LmcAuthRequest (com.zimbra.cs.client.soap.LmcAuthRequest)1