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());
}
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;
}
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());
}
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());
}
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);
}
}
Aggregations