Search in sources :

Example 1 with AuthToken

use of com.zimbra.soap.account.type.AuthToken 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 AuthToken

use of com.zimbra.soap.account.type.AuthToken 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 AuthToken

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

the class TestAuth method attrsReturnedInAuthResponse.

@Test
public void attrsReturnedInAuthResponse() throws Exception {
    String ATTR_NAME = Provisioning.A_zimbraFeatureExternalFeedbackEnabled;
    String ATTR_VALUE = ProvisioningConstants.TRUE;
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(ATTR_NAME, ATTR_VALUE);
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, attrs);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    com.zimbra.soap.type.AccountSelector acctSel = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    req.addAttr(ATTR_NAME);
    AuthResponse resp = invokeJaxb(transport, req);
    Set<String> result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
    /*
         * test the auth by auth toke npath
         */
    String authTokenStr = resp.getAuthToken();
    AuthToken authToken = new AuthToken(authTokenStr, Boolean.FALSE);
    req = new AuthRequest();
    req.setAuthToken(authToken);
    req.addAttr(ATTR_NAME);
    transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    transport.setHttpDebugListener(new SoapDebugListener());
    resp = invokeJaxb(transport, req);
    result = Sets.newHashSet();
    for (Attr attr : resp.getAttrs()) {
        String attrName = attr.getName();
        String attrValue = attr.getValue();
        result.add(Verify.makeResultStr(attrName, attrValue));
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(ATTR_NAME, ATTR_VALUE)), result);
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) Attr(com.zimbra.soap.account.type.Attr) AuthResponse(com.zimbra.soap.account.message.AuthResponse) AccountSelector(com.zimbra.soap.type.AccountSelector) ZAuthToken(com.zimbra.common.auth.ZAuthToken) AuthToken(com.zimbra.soap.account.type.AuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) Test(org.junit.Test)

Aggregations

ZAuthToken (com.zimbra.common.auth.ZAuthToken)3 AuthRequest (com.zimbra.soap.account.message.AuthRequest)3 AuthResponse (com.zimbra.soap.account.message.AuthResponse)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 AccountSelector (com.zimbra.soap.type.AccountSelector)2 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)1 Account (com.zimbra.cs.account.Account)1 Attr (com.zimbra.soap.account.type.Attr)1 Test (org.junit.Test)1