use of com.zimbra.cs.client.LmcSession in project zm-mailbox by Zimbra.
the class SoapCLI method auth.
/**
* Authenticates using the provided ZAuthToken
* @throws IOException
* @throws com.zimbra.common.soap.SoapFaultException
* @throws ServiceException
*/
protected LmcSession auth(ZAuthToken zAuthToken) throws SoapFaultException, IOException, ServiceException {
if (zAuthToken == null)
return auth();
URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
mServerUrl = url.toExternalForm();
SoapTransport trans = getTransport();
mAuth = false;
Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
zAuthToken.encodeAuthReq(authReq, true);
try {
Element authResp = trans.invokeWithoutSession(authReq);
ZAuthToken zat = new ZAuthToken(authResp.getElement(AdminConstants.E_AUTH_TOKEN), true);
trans.setAuthToken(zat);
mAuth = true;
return new LmcSession(zat, null);
} catch (UnknownHostException e) {
// UnknownHostException's error message is not clear; rethrow with a more descriptive message
throw new IOException("Unknown host: " + mHost);
}
}
use of com.zimbra.cs.client.LmcSession in project zm-mailbox by Zimbra.
the class SoapCLI method auth.
/**
* Authenticates using the username and password from the local config.
* @throws IOException
* @throws com.zimbra.common.soap.SoapFaultException
* @throws ServiceException
*/
protected LmcSession auth() throws SoapFaultException, IOException, ServiceException {
URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
mServerUrl = url.toExternalForm();
SoapTransport trans = getTransport();
mAuth = false;
Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
authReq.addAttribute(AdminConstants.E_NAME, mUser, Element.Disposition.CONTENT);
authReq.addAttribute(AdminConstants.E_PASSWORD, mPassword, Element.Disposition.CONTENT);
try {
Element authResp = trans.invokeWithoutSession(authReq);
String authToken = authResp.getAttribute(AdminConstants.E_AUTH_TOKEN);
ZAuthToken zat = new ZAuthToken(null, authToken, null);
trans.setAuthToken(authToken);
mAuth = true;
return new LmcSession(zat, null);
} catch (UnknownHostException e) {
// UnknownHostException's error message is not clear; rethrow with a more descriptive message
throw new IOException("Unknown host: " + mHost);
}
}
use of com.zimbra.cs.client.LmcSession in project zm-mailbox by Zimbra.
the class TestAccount method testDeleteAccount.
public void testDeleteAccount() throws Exception {
ZimbraLog.test.debug("testDeleteAccount()");
// Get the account and mailbox
Account account = TestUtil.getAccount(USER_NAME);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String dbName = DbMailbox.getDatabaseName(mbox);
ZimbraLog.test.debug("Account=" + account.getId() + ", mbox=" + mbox.getId());
// Confirm that the mailbox database exists
DbResults results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
assertEquals("Could not find row in mailbox table", 1, results.getInt(1));
results = DbUtil.executeQuery("SHOW DATABASES LIKE '" + dbName + "'");
assertEquals("Could not find mailbox database", 1, results.size());
// Add a message to the account and confirm that the message directory exists
TestUtil.addMessage(mbox, "TestAccount testDeleteAccount");
String storePath = VolumeManager.getInstance().getCurrentMessageVolume().getMessageRootDir(mbox.getId());
File storeDir = new File(storePath);
if (TestUtil.checkLocalBlobs()) {
assertTrue(storePath + " does not exist", storeDir.exists());
assertTrue(storePath + " is not a directory", storeDir.isDirectory());
}
// Delete the account
LmcSession session = TestUtil.getAdminSoapSession();
LmcDeleteAccountRequest req = new LmcDeleteAccountRequest(account.getId());
req.setSession(session);
req.invoke(TestUtil.getAdminSoapUrl());
// Confirm that the mailbox was deleted
results = DbUtil.executeQuery("SELECT COUNT(*) FROM mailbox WHERE id = " + mbox.getId());
assertEquals("Unexpected row in mailbox table", 0, results.getInt(1));
if (TestUtil.checkLocalBlobs()) {
// Confirm that the message directory was deleted
assertFalse(storePath + " exists", storeDir.exists());
}
}
use of com.zimbra.cs.client.LmcSession in project zm-mailbox by Zimbra.
the class TestAuthentication method testAccessDeletedAccount.
/**
* Attempts to access a deleted account and confirms that the attempt
* fails with an auth error.
*/
public void testAccessDeletedAccount() throws Exception {
// Log in and check the inbox
LmcSession session = TestUtil.getSoapSession(USER_NAME);
LmcSearchRequest req = new LmcSearchRequest();
req.setQuery("in:inbox");
req.setSession(session);
req.invoke(TestUtil.getSoapUrl());
// Delete the account
Account account = getAccount();
assertNotNull("Account does not exist", account);
mProv.deleteAccount(account.getId());
// Submit another request and make sure it fails with an auth error
try {
req.invoke(TestUtil.getSoapUrl());
} catch (SoapFaultException ex) {
assertTrue("Unexpected error: " + ex.getMessage(), ex.getMessage().indexOf("auth credentials have expired") >= 0);
}
}
use of com.zimbra.cs.client.LmcSession in project zm-mailbox by Zimbra.
the class TestAuthentication method testAccessInactiveAccount.
/**
* Attempts to access a deleted account and confirms that the attempt
* fails with an auth error.
*/
public void testAccessInactiveAccount() throws Exception {
// Log in and check the inbox
LmcSession session = TestUtil.getSoapSession(USER_NAME);
LmcSearchRequest req = new LmcSearchRequest();
req.setQuery("in:inbox");
req.setSession(session);
req.invoke(TestUtil.getSoapUrl());
// Deactivate the account
Account account = getAccount();
mProv.modifyAccountStatus(account, Provisioning.ACCOUNT_STATUS_MAINTENANCE);
// Submit another request and make sure it fails with an auth error
try {
req.invoke(TestUtil.getSoapUrl());
} catch (SoapFaultException ex) {
String substring = "auth credentials have expired";
String msg = String.format("Error message '%s' does not contain '%s'", ex.getMessage(), substring);
assertTrue(msg, ex.getMessage().contains(substring));
}
}
Aggregations