Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer");
XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer);
Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler");
XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler);
MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler);
XMasterPasswordHandling xMHandling = (XMasterPasswordHandling)UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer);
// allow the storing of the passwords
xMHandling.allowPersistentStoring(true);
// add a set of users and passwords for the same URL persistently
for(int i = 0; i < iUserNum1; ++i) {
xContainer.addPersistent(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler);
}
for(int i = 0; i < iUserNum2; ++i) {
xContainer.addPersistent(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler);
}
// remove some of the passwords
for(int i = 0; i < iUserNum1; ++i) {
xContainer.remove(sURL, aInputUserList1[i].UserName);
}
// get the result with find() and check it with the expected one
UrlRecord aRecord = xContainer.find(sURL, aMHandler);
if(!aRecord.Url.equals(sURL)) {
m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL);
return false;
}
if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) {
m_aTestHelper.Error("User list is not the expected");
return false;
}
// get the result with getAllPersistent() and check
UrlRecord aRecords[] = xContainer.getAllPersistent(aMHandler);
if(!aRecords[0].Url.equals(sURL)) {
m_aTestHelper.Error("URL mismatch");
return false;
}
if(!m_aTestHelper.sameLists(aRecords[0].UserList, aInputUserList2)) {
m_aTestHelper.Error("User list is not the expected");
return false;
}
// remove all the persistent passwords
xContainer.removeAllPersistent();
// remove the runtime passwords
for(int i = 0; i < aRecords[0].UserList.length; ++i) {
xContainer.remove(sURL, aRecords[0].UserList[i].UserName);
}
// disallow the storing of the passwords
xMHandling.allowPersistentStoring(false);
} catch(Exception e) {
m_aTestHelper.Error("Exception: " + e);
return false;
}
return true;