Search in sources :

Example 6 with AuthResponse

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

the class TestCookieReuse method testLoginClearAuthTokensException.

/**
     * Verify that when an expired authtoken has been removed from LDAP, login still succeeds
     * @throws Exception
     */
@Test
public void testLoginClearAuthTokensException() throws Exception {
    Account a = TestUtil.getAccount(USER_NAME);
    ZimbraAuthToken at1 = new ZimbraAuthToken(a, System.currentTimeMillis() + 1000);
    Assert.assertFalse("token should not be expired yet", at1.isExpired());
    Thread.sleep(2000);
    Assert.assertTrue("token should have expired by now", at1.isExpired());
    //explicitely clean up expired auth tokens
    a.purgeAuthTokens();
    //verify that AuthRequest still works
    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();
    Assert.assertNotNull("should have received a new authtoken", newAuthToken);
    AuthToken at = ZimbraAuthToken.getAuthToken(newAuthToken);
    Assert.assertTrue("new auth token should be registered", at.isRegistered());
    Assert.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) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) AccountSelector(com.zimbra.soap.type.AccountSelector) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZimbraAuthToken(com.zimbra.cs.account.ZimbraAuthToken) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) AuthResponse(com.zimbra.soap.account.message.AuthResponse) Test(org.junit.Test)

Example 7 with AuthResponse

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

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

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