Search in sources :

Example 6 with AuthRequest

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

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

Example 8 with AuthRequest

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

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

the class JaxbToElementTest method jaxbWrapperFixupTest.

/**
     * Check that @{link JaxbUtil.elementToJaxb} will accept XML where
     * JAXB expects various attributes that have been specified as elements.
     * Ensure that attributes in wrapped elements are handled
     * @throws Exception
     */
@Test
public void jaxbWrapperFixupTest() throws Exception {
    Element rootElem = Element.XMLElement.mFactory.createElement(AccountConstants.AUTH_REQUEST);
    // JAXB wrapper element name E_PREFS
    Element prefsE = rootElem.addNonUniqueElement(AccountConstants.E_PREFS);
    // JAXB element E_PREF with attribute "name"
    Element prefE = prefsE.addNonUniqueElement(AccountConstants.E_PREF);
    prefE.addNonUniqueElement("name").addText("pref name");
    AuthRequest req = JaxbUtil.elementToJaxb(rootElem);
    List<Pref> prefs = req.getPrefs();
    Assert.assertEquals("Number of prefs", 1, prefs.size());
    Assert.assertEquals("Pref name", "pref name", prefs.get(0).getName());
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) Pref(com.zimbra.soap.account.type.Pref) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 10 with AuthRequest

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

the class AuthRequestTest method testBuildAuthRequestWithPreAuth.

@Test
public void testBuildAuthRequestWithPreAuth() {
    AuthRequest authRequest = new AuthRequest();
    authRequest.setAccount(AccountSelector.fromName(username));
    PreAuth preAuth = new PreAuth().setExpires(expires).setTimestamp(timestamp);
    authRequest.setPreauth(preAuth);
    try {
        Element element = JaxbUtil.jaxbToElement(authRequest);
        String xml = element.toString();
        Element account = element.getElement("account");
        assertEquals("Username embedded in request is incorrect", username, account.getText());
        Element preauth = element.getElement("preauth");
        assertEquals("'expires' embedded in preauth is incorrect", Long.toString(expires), preauth.getAttribute("expires"));
        assertEquals("'timestamp' embedded in preauth is incorrect", Long.toString(timestamp), preauth.getAttribute("timestamp"));
    } catch (ServiceException e) {
        fail("Encountered a problem: " + e);
    }
}
Also used : AuthRequest(com.zimbra.soap.account.message.AuthRequest) PreAuth(com.zimbra.soap.account.type.PreAuth) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

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