use of com.zimbra.soap.account.type.AuthToken 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.type.AuthToken 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.type.AuthToken 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);
}
Aggregations