private static Map<String, WindowsAccount> getGroups(IWindowsAccount[] groups) { Map<String, WindowsAccount> groupMap = new HashMap<String, WindowsAccount>(); for (IWindowsAccount group : groups) { groupMap.put(group.getFqn(), new WindowsAccount(group)); } return groupMap; }
/** * Returns a list of role principal objects. * * @param group Windows group. * @param principalFormat Principal format. * @return List of role principal objects. */ private static List<String> getRoleNames(IWindowsAccount group, PrincipalFormat principalFormat) { List<String> principals = new ArrayList<String>(); switch (principalFormat) { case fqn: principals.add(group.getFqn()); break; case sid: principals.add(group.getSidString()); break; case both: principals.add(group.getFqn()); principals.add(group.getSidString()); break; case none: break; } return principals; }
@Test public void testWaffleInfo() throws ParserConfigurationException { WaffleInfo helper = new WaffleInfo(); Document info = helper.getWaffleInfo(); // Make sure JNA Version is properly noted assertEquals( Platform.class.getPackage().getImplementationVersion(), info.getDocumentElement().getAttribute("jna")); Node node = info.getDocumentElement() // waffle .getFirstChild() // auth .getFirstChild() // currentUser .getNextSibling(); // computer assertEquals("computer", node.getNodeName()); IWindowsAuthProvider auth = new WindowsAuthProviderImpl(); IWindowsComputer computer = auth.getCurrentComputer(); NodeList nodes = node.getChildNodes(); assertEquals(computer.getComputerName(), nodes.item(0).getTextContent()); assertEquals(computer.getMemberOf(), nodes.item(1).getTextContent()); assertEquals(computer.getJoinStatus(), nodes.item(2).getTextContent()); // Add Lookup Info for Various accounts String lookup = WindowsAccountImpl.getCurrentUsername(); IWindowsAccount account = new WindowsAccountImpl(lookup); Element elem = helper.getLookupInfo(info, lookup); assertEquals(lookup, elem.getAttribute("name")); assertEquals(account.getName(), elem.getFirstChild().getTextContent()); // Report an error when unknown name lookup = "__UNKNOWN_ACCOUNT_NAME___"; elem = helper.getLookupInfo(info, lookup); assertEquals(lookup, elem.getAttribute("name")); assertEquals("exception", elem.getFirstChild().getNodeName()); }