Search in sources :

Example 11 with AuthRequest

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

the class SoapTest method authUser.

/**
     * @param name
     * @param csrfEnabled
     * @return
     * @throws IOException
     * @throws ServiceException
     */
public static SoapTransport authUser(String acctName, boolean csrfEnabled, boolean setCsrfToken) throws ServiceException, IOException {
    com.zimbra.soap.type.AccountSelector acct = new com.zimbra.soap.type.AccountSelector(com.zimbra.soap.type.AccountBy.name, acctName);
    SoapHttpTransport transport = new SoapHttpTransport("http://localhost:7070/service/soap/");
    transport.setHttpDebugListener(soapDebugListener);
    AuthRequest req = new AuthRequest(acct, PASSWORD);
    req.setCsrfSupported(csrfEnabled);
    AuthResponse resp = invokeJaxb(transport, req);
    transport.setAuthToken(resp.getAuthToken());
    if (setCsrfToken) {
        transport.setCsrfToken(resp.getCsrfToken());
    }
    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 12 with AuthRequest

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

the class TestAccess method Auth.

// ================= APIs ================
@Test
public void Auth() throws Exception {
    AccountSelector acct = new AccountSelector(com.zimbra.soap.type.AccountBy.name, OTHER_ACCT_NAME);
    AuthRequest req = new AuthRequest(acct, PASSWORD);
    accessTest(Perm.PERM_AUTH_TOKEN_IGNORED, req);
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector) Test(org.junit.Test)

Example 13 with AuthRequest

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

Example 14 with AuthRequest

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

the class TestAuthentication method verifyLockedoutAndReactivateAccount.

static boolean verifyLockedoutAndReactivateAccount(Account acct, SoapHttpTransport transport) throws Exception {
    boolean isLockedOut = acct.getAccountStatus().equals(AccountStatus.lockout);
    if (isLockedOut) {
        acct.setAccountStatusAsString("active");
        AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
        AuthRequest req = new AuthRequest(acctSel, "test123");
        transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    }
    return isLockedOut;
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) AccountSelector(com.zimbra.soap.type.AccountSelector)

Example 15 with AuthRequest

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

the class TestAuthentication method testSimpleAuth.

/**
     * test detault auth request with login/password
     * @throws Exception
     */
public void testSimpleAuth() throws Exception {
    //regular auth request
    Account a = TestUtil.getAccount(USER_NAME);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, a.getName());
    AuthRequest req = new AuthRequest(acctSel, "test123");
    Element resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    AuthResponse authResp = JaxbUtil.elementToJaxb(resp);
    String newAuthToken = authResp.getAuthToken();
    assertNotNull("should have received a new authtoken", newAuthToken);
    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) 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

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