1*4b5ab84dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*4b5ab84dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*4b5ab84dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*4b5ab84dSAndrew Rist * distributed with this work for additional information 6*4b5ab84dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*4b5ab84dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*4b5ab84dSAndrew Rist * "License"); you may not use this file except in compliance 9*4b5ab84dSAndrew Rist * with the License. You may obtain a copy of the License at 10*4b5ab84dSAndrew Rist * 11*4b5ab84dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*4b5ab84dSAndrew Rist * 13*4b5ab84dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*4b5ab84dSAndrew Rist * software distributed under the License is distributed on an 15*4b5ab84dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*4b5ab84dSAndrew Rist * KIND, either express or implied. See the License for the 17*4b5ab84dSAndrew Rist * specific language governing permissions and limitations 18*4b5ab84dSAndrew Rist * under the License. 19*4b5ab84dSAndrew Rist * 20*4b5ab84dSAndrew Rist *************************************************************/ 21*4b5ab84dSAndrew Rist 22*4b5ab84dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package complex.passwordcontainer; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 27cdf0e10cSrcweir import com.sun.star.task.UrlRecord; 28cdf0e10cSrcweir import com.sun.star.task.UserRecord; 29cdf0e10cSrcweir import com.sun.star.task.XPasswordContainer; 30cdf0e10cSrcweir import com.sun.star.task.XMasterPasswordHandling; 31cdf0e10cSrcweir import com.sun.star.task.XInteractionHandler; 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir public class Test03 implements PasswordContainerTest { 38cdf0e10cSrcweir XMultiServiceFactory m_xMSF = null; 39cdf0e10cSrcweir XPasswordContainer m_xPasswordContainer = null; 40cdf0e10cSrcweir TestHelper m_aTestHelper = null; 41cdf0e10cSrcweir Test03( XMultiServiceFactory xMSF )42cdf0e10cSrcweir public Test03 ( XMultiServiceFactory xMSF ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir m_xMSF = xMSF; 45cdf0e10cSrcweir m_aTestHelper = new TestHelper ( "Test03: "); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir test()48cdf0e10cSrcweir public boolean test() { 49cdf0e10cSrcweir final String sURL = "http://www.openoffice.org"; 50cdf0e10cSrcweir final String sUserPre = "OOoUser"; 51cdf0e10cSrcweir final String sPwdPre = "Password"; 52cdf0e10cSrcweir final int iPersistentUserNum = 10; 53cdf0e10cSrcweir final int iRuntimeUserNum = 5; 54cdf0e10cSrcweir 55cdf0e10cSrcweir UserRecord aInputUserList[] = new UserRecord[iPersistentUserNum+iRuntimeUserNum]; 56cdf0e10cSrcweir for(int i = 0; i < iPersistentUserNum; i++) { 57cdf0e10cSrcweir String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user 58cdf0e10cSrcweir aInputUserList[i] = new UserRecord(sUserPre + "_1_" + i, sTemp); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir for(int i = 0; i < iRuntimeUserNum; i++) { 61cdf0e10cSrcweir String sTemp[] = {sPwdPre + "_2_" + i}; 62cdf0e10cSrcweir aInputUserList[i+iPersistentUserNum] = new UserRecord(sUserPre + "_2_" + i, sTemp); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir try { 66cdf0e10cSrcweir Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer"); 67cdf0e10cSrcweir XPasswordContainer xContainer = UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); 68cdf0e10cSrcweir Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler"); 69cdf0e10cSrcweir XInteractionHandler xHandler = UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); 70cdf0e10cSrcweir MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler); 71cdf0e10cSrcweir XMasterPasswordHandling xMHandling = UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer); 72cdf0e10cSrcweir 73cdf0e10cSrcweir // allow the storing of the passwords 74cdf0e10cSrcweir xMHandling.allowPersistentStoring(true); 75cdf0e10cSrcweir 76cdf0e10cSrcweir // add a set of users and passwords for the same URL persistently 77cdf0e10cSrcweir for(int i = 0; i < iPersistentUserNum; i++) { 78cdf0e10cSrcweir xContainer.addPersistent(sURL, aInputUserList[i].UserName, aInputUserList[i].Passwords, aMHandler); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir // add a set of users and passwords for the same URL for runtime 82cdf0e10cSrcweir for(int i = 0; i < iRuntimeUserNum; i++) { 83cdf0e10cSrcweir xContainer.add(sURL, aInputUserList[i+iPersistentUserNum].UserName, aInputUserList[i+iPersistentUserNum].Passwords, aMHandler); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir // get the result for the URL and check that it contains persistent and runtime passwords 87cdf0e10cSrcweir UrlRecord aRecord = xContainer.find(sURL, aMHandler); 88cdf0e10cSrcweir if(!aRecord.Url.equals(sURL)) { 89cdf0e10cSrcweir m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL); 90cdf0e10cSrcweir return false; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList)) { 93cdf0e10cSrcweir m_aTestHelper.Error("User list is not the expected"); 94cdf0e10cSrcweir return false; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // remove all the persistent passwords 98cdf0e10cSrcweir xContainer.removeAllPersistent(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir // remove the runtime passwords 101cdf0e10cSrcweir aRecord = xContainer.find(sURL, aMHandler); 102cdf0e10cSrcweir for(int i = 0; i < aRecord.UserList.length; i++) { 103cdf0e10cSrcweir xContainer.remove(sURL, aRecord.UserList[i].UserName); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir // disallow the storing of the passwords 107cdf0e10cSrcweir xMHandling.allowPersistentStoring(false); 108cdf0e10cSrcweir }catch(Exception e){ 109cdf0e10cSrcweir m_aTestHelper.Error("Exception: " + e); 110cdf0e10cSrcweir return false; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir return true; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115