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