use of com.zimbra.soap.account.message.AuthRequest in project zm-mailbox by Zimbra.
the class ZMailbox method authByAuthToken.
public ZAuthResult authByAuthToken(Options options) throws ServiceException {
if (mTransport == null) {
throw ZClientException.CLIENT_ERROR("must call setURI before calling authenticate", null);
}
AuthRequest req = new AuthRequest();
// cannot be null here
ZAuthToken zat = options.getAuthToken();
req.setAuthToken(new AuthToken(zat.getValue(), false));
req.setTwoFactorCode(options.getTwoFactorCode());
req.setRequestedSkin(options.getRequestedSkin());
req.setCsrfSupported(options.getCsrfSupported());
req.setDeviceTrusted(options.getTrustedDevice());
addAttrsAndPrefs(req, options);
AuthResponse res = invokeJaxb(req);
ZAuthResult r = new ZAuthResult(res);
r.setSessionId(mTransport.getSessionId());
return r;
}
use of com.zimbra.soap.account.message.AuthRequest in project zm-mailbox by Zimbra.
the class ZMailbox method authByPassword.
public ZAuthResult authByPassword(Options options, String password) throws ServiceException {
if (mTransport == null) {
throw ZClientException.CLIENT_ERROR("must call setURI before calling authenticate", null);
}
AccountSelector account = new AccountSelector(com.zimbra.soap.type.AccountBy.name, options.getAccount());
AuthRequest auth = new AuthRequest(account, password);
auth.setPassword(password);
auth.setTwoFactorCode(options.getTwoFactorCode());
auth.setVirtualHost(options.getVirtualHost());
auth.setRequestedSkin(options.getRequestedSkin());
auth.setCsrfSupported(options.getCsrfSupported());
auth.setDeviceTrusted(options.getTrustedDevice());
if (options.getTrustedDevice()) {
auth.setDeviceTrusted(true);
}
if (options.getAuthToken() != null) {
auth.setAuthToken(new AuthToken(options.getAuthToken().getValue(), false));
}
if (options.getDeviceId() != null) {
auth.setDeviceId(options.getDeviceId());
}
if (options.getTrustedDeviceToken() != null) {
auth.setTrustedDeviceToken(options.getTrustedDeviceToken());
}
if (options.getGenerateDeviceId()) {
auth.setGenerateDeviceId(true);
}
addAttrsAndPrefs(auth, options);
AuthResponse authRes = invokeJaxb(auth);
ZAuthResult r = new ZAuthResult(authRes);
r.setSessionId(mTransport.getSessionId());
return r;
}
use of com.zimbra.soap.account.message.AuthRequest in project zm-mailbox by Zimbra.
the class AuthRequestTest method testBuildAuthRequestWithPassword.
@Test
public void testBuildAuthRequestWithPassword() {
AuthRequest authRequest = new AuthRequest();
authRequest.setAccount(AccountSelector.fromName(username));
authRequest.setPassword(password);
try {
Element element = JaxbUtil.jaxbToElement(authRequest);
String xml = element.toString();
assertTrue(element.hasChildren());
Element account = element.getElement("account");
Element pwdE = element.getElement("password");
assertEquals("Username embedded in request is incorrect", username, account.getText());
assertEquals("Password embedded in request is incorrect", password, pwdE.getText());
} catch (ServiceException e) {
fail("Encountered an exception: " + e);
}
}
use of com.zimbra.soap.account.message.AuthRequest in project zm-mailbox by Zimbra.
the class SoapTest method authUser.
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());
transport.setHttpDebugListener(soapDebugListener);
AuthRequest req = new AuthRequest(acct, password);
AuthResponse resp = 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 TestAuthentication method testAccountLockout.
public void testAccountLockout() throws Exception {
String wrongPassword1 = "test1234";
String wrongPassword2 = "test12345";
Account acct = TestUtil.getAccount(USER_NAME);
acct.setPasswordLockoutMaxFailures(2);
acct.setPasswordLockoutEnabled(true);
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
AuthRequest req = new AuthRequest(acctSel, wrongPassword1);
// Verify lockout happen after 2 invalid login using same password.
Element resp;
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
// Add Soap protocol to PasswordLockoutSuppressionProtocols
acct.setPasswordLockoutSuppressionProtocols(PasswordLockoutSuppressionProtocols.soap);
// Verify lock out should not happen after 2 invalid login using same password and next login with different invalid password should be locked out.
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
Assert.assertTrue("account is not active", acct.getAccountStatus().equals(AccountStatus.active));
req = new AuthRequest(acctSel, wrongPassword2);
try {
resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
} catch (ServiceException e) {
}
Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
acct.setPasswordLockoutSuppressionEnabled(false);
}
Aggregations