public static void removeUsersAndDevices(String alias) throws NotesException { Session session = null; Database dbUnplugged = null; String alias1 = "/" + alias.toLowerCase(); String alias2 = "/o=" + alias.toLowerCase(); Logger.debug("Remove Unplugged users and devices for alias \"" + alias + "\""); Configuration config = Configuration.get(); // open unplugged db session = Utils.getCurrentSession(); dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); // check if an app document for this app already exists and create it if not String q = "Form=\"User\":\"Device\" & ( @Contains(@LowerCase(UserName); \"" + alias1 + "\") | @Contains(@LowerCase(UserName); \"" + alias2 + "\") )"; DocumentCollection dcApp = dbUnplugged.search(q); Logger.info("- finding users and devices with query: " + q); if (dcApp.getCount() == 0) { Logger.info("- No Unplugged users/ devices found"); } else { Logger.info("- found " + dcApp.getCount() + " users and/or devices"); Document doc = dcApp.getFirstDocument(); while (null != doc) { Document t = dcApp.getNextDocument(doc); Logger.info( "- removing " + doc.getItemValueString("form") + " for " + doc.getItemValueString("UserName")); doc.remove(true); try { doc.recycle(); } catch (Exception e) { } doc = t; } } }
// removes the specified applications for the user from Unplugged @SuppressWarnings("unchecked") public static void deleteApplication(String userName, Vector<String> appPaths) { Session sessionAsSigner = null; Database dbUnplugged = null; Document docUser = null; View vwUsers = null; Name nmUser = null; Document docApp = null; try { Configuration config = Configuration.get(); // open unplugged db sessionAsSigner = Utils.getCurrentSessionAsSigner(); dbUnplugged = sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath()); nmUser = sessionAsSigner.createName(userName); // get all application documents for this user DocumentCollection dcApp = dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)"); Document docTemp = null; int numRemoved = 0; // update app documents docApp = dcApp.getFirstDocument(); while (null != docApp) { String path = docApp.getItemValueString("Path"); if (appPaths.contains(path)) { // remove application Vector<String> appUsers = docApp.getItemValue("UserName"); Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing"); appUsers.remove(nmUser.getCanonical()); docApp.replaceItemValue("UserName", appUsers); docApp.computeWithForm(true, true); docApp.save(); numRemoved++; } docTemp = dcApp.getNextDocument(docApp); docApp.recycle(); docApp = docTemp; } if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config Logger.info( "Unplugged user " + nmUser.getCanonical() + " removed from all applications - remove user config"); // check for user account vwUsers = dbUnplugged.getView(USERS_VIEW); docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true); if (docUser != null) { docUser.remove(true); Logger.info("removed Unplugged user " + nmUser.getCanonical()); } } } catch (Exception e) { Logger.error(e); } finally { Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner); } }