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