use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestAutoProvision method authRequestByPreauth.
/*
* Note: need to restart server each time before re-run. Otherwise server would still
* have the account created in previous run cached.
*/
@Test
public void authRequestByPreauth() throws Exception {
String testName = getTestName();
String externalPassword = "test456";
String extAcctLocalPart = testName;
String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
Map<String, Object> zimbraDomainAttrs = commonZimbraDomainAttrs();
// setup auto prov
// commonZimbraDomainAttrs added only LDAP, add preauth here
StringUtil.addToMultiMap(zimbraDomainAttrs, Provisioning.A_zimbraAutoProvAuthMech, AutoProvAuthMech.PREAUTH.name());
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(uid=%u)");
// setup external LDAP auth
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthMech, AuthMech.ldap.name());
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapURL, "ldap://localhost:389");
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapBindDn, "uid=%u,ou=people," + extDomainDn);
// setup preauth
String preAuthKey = PreAuthKey.generateRandomPreAuthKey();
zimbraDomainAttrs.put(Provisioning.A_zimbraPreAuthKey, preAuthKey);
Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
String loginName = extAcctLocalPart + "@" + zimbraDomain.getName();
// preauth data
HashMap<String, String> params = new HashMap<String, String>();
String authBy = "name";
long timestamp = System.currentTimeMillis();
long expires = 0;
params.put("account", loginName);
params.put("by", authBy);
params.put("timestamp", timestamp + "");
params.put("expires", expires + "");
String preAuth = PreAuthKey.computePreAuth(params, preAuthKey);
// make the soap request
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, authBy).setText(loginName);
Element ePreAuth = request.addElement(AccountConstants.E_PREAUTH).setText(preAuth);
ePreAuth.addAttribute(AccountConstants.A_TIMESTAMP, timestamp);
ePreAuth.addAttribute(AccountConstants.A_EXPIRES, expires);
Element response = transport.invoke(request);
String encodedAuthToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
assertNotNull(encodedAuthToken);
String acctId = getAuthTokenAcctId(encodedAuthToken);
Account acct = prov.get(AccountBy.id, acctId);
verifyAcctAutoProvisioned(acct, loginName.toLowerCase());
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestAutoProvision method authRequestByPassword.
/* ========================
* SOAP and servlets tests
* ========================
*/
/*
* Note: need to restart server each time before re-run. Otherwise server would still
* have the account created in previous run cached.
*/
@Test
public void authRequestByPassword() throws Exception {
String testName = getTestName();
String externalPassword = "test456";
String extAcctLocalPart = testName;
String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
Map<String, Object> zimbraDomainAttrs = commonZimbraDomainAttrs();
// setup auto prov
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(uid=%u)");
// setup external LDAP auth
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthMech, AuthMech.ldap.name());
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapURL, "ldap://localhost:389");
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthLdapBindDn, "uid=%u,ou=people," + extDomainDn);
Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
String loginName = extAcctLocalPart + "@" + zimbraDomain.getName();
// make the soap request
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, AccountBy.name.name()).setText(loginName);
request.addElement(AccountConstants.E_PASSWORD).setText(externalPassword);
Element response = transport.invoke(request);
String encodedAuthToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
assertNotNull(encodedAuthToken);
String acctId = getAuthTokenAcctId(encodedAuthToken);
Account acct = prov.get(AccountBy.id, acctId);
verifyAcctAutoProvisioned(acct, loginName.toLowerCase());
}
use of com.zimbra.common.soap.SoapHttpTransport 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.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class SoapTest method authAdmin.
public static SoapTransport authAdmin(String acctName, String password) throws Exception {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
transport.setHttpDebugListener(soapDebugListener);
com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(acctName, password);
com.zimbra.soap.admin.message.AuthResponse resp = invokeJaxb(transport, req);
transport.setAuthToken(resp.getAuthToken());
return transport;
}
use of com.zimbra.common.soap.SoapHttpTransport 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