@Test public void testStaticMapParsing() throws IOException { File tempStaticMapFile = File.createTempFile("nfs-", ".map"); final String staticMapFileContents = "uid 10 100\n" + "gid 10 200\n" + "uid 11 201 # comment at the end of a line\n" + "uid 12 301\n" + "# Comment at the beginning of a line\n" + " # Comment that starts late in the line\n" + "uid 10000 10001# line without whitespace before comment\n" + "uid 13 302\n" + "gid\t11\t201\n" + "\n" + "gid 12 202"; OutputStream out = new FileOutputStream(tempStaticMapFile); out.write(staticMapFileContents.getBytes()); out.close(); StaticMapping parsedMap = ShellBasedIdMapping.parseStaticMap(tempStaticMapFile); assertEquals(10, (int)parsedMap.uidMapping.get(100)); assertEquals(11, (int)parsedMap.uidMapping.get(201)); assertEquals(12, (int)parsedMap.uidMapping.get(301)); assertEquals(13, (int)parsedMap.uidMapping.get(302)); assertEquals(10, (int)parsedMap.gidMapping.get(200)); assertEquals(11, (int)parsedMap.gidMapping.get(201)); assertEquals(12, (int)parsedMap.gidMapping.get(202)); assertEquals(10000, (int)parsedMap.uidMapping.get(10001)); assertEquals(1000, (int)parsedMap.uidMapping.get(1000)); }
static StaticMapping parseStaticMap(File staticMapFile) throws IOException { Map<Integer, Integer> uidMapping = new HashMap<Integer, Integer>(); Map<Integer, Integer> gidMapping = new HashMap<Integer, Integer>(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(staticMapFile))); try { String line = null; while ((line = in.readLine()) != null) { if (EMPTY_LINE.matcher(line).matches() || COMMENT_LINE.matcher(line).matches()) { continue; } Matcher lineMatcher = MAPPING_LINE.matcher(line); if (!lineMatcher.matches()) { LOG.warn("Could not parse line '" + line + "'. Lines should be of " + "the form '[uid|gid] [remote id] [local id]'. Blank lines and " + "everything following a '#' on a line will be ignored."); continue; } String firstComponent = lineMatcher.group(1); int remoteId = Integer.parseInt(lineMatcher.group(2)); int localId = Integer.parseInt(lineMatcher.group(3)); if (firstComponent.equals("uid")) { uidMapping.put(localId, remoteId); } else { gidMapping.put(localId, remoteId); } } } finally { in.close(); } return new StaticMapping(uidMapping, gidMapping); }
ShellBasedIdMapping implements IdMappingServiceProvider { static StaticMapping parseStaticMap(File staticMapFile) throws IOException { Map<Integer, Integer> uidMapping = new HashMap<Integer, Integer>(); Map<Integer, Integer> gidMapping = new HashMap<Integer, Integer>(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(staticMapFile))); try { String line = null; while ((line = in.readLine()) != null) { if (EMPTY_LINE.matcher(line).matches() || COMMENT_LINE.matcher(line).matches()) { continue; } Matcher lineMatcher = MAPPING_LINE.matcher(line); if (!lineMatcher.matches()) { LOG.warn("Could not parse line '" + line + "'. Lines should be of " + "the form '[uid|gid] [remote id] [local id]'. Blank lines and " + "everything following a '#' on a line will be ignored."); continue; } String firstComponent = lineMatcher.group(1); int remoteId = Integer.parseInt(lineMatcher.group(2)); int localId = Integer.parseInt(lineMatcher.group(3)); if (firstComponent.equals("uid")) { uidMapping.put(localId, remoteId); } else { gidMapping.put(localId, remoteId); } } } finally { in.close(); } return new StaticMapping(uidMapping, gidMapping); } }
ShellBasedIdMapping implements IdMappingServiceProvider { static StaticMapping parseStaticMap(File staticMapFile) throws IOException { Map<Integer, Integer> uidMapping = new HashMap<Integer, Integer>(); Map<Integer, Integer> gidMapping = new HashMap<Integer, Integer>(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(staticMapFile))); try { String line = null; while ((line = in.readLine()) != null) { if (EMPTY_LINE.matcher(line).matches() || COMMENT_LINE.matcher(line).matches()) { continue; } Matcher lineMatcher = MAPPING_LINE.matcher(line); if (!lineMatcher.matches()) { LOG.warn("Could not parse line '" + line + "'. Lines should be of " + "the form '[uid|gid] [remote id] [local id]'. Blank lines and " + "everything following a '#' on a line will be ignored."); continue; } String firstComponent = lineMatcher.group(1); int remoteId = Integer.parseInt(lineMatcher.group(2)); int localId = Integer.parseInt(lineMatcher.group(3)); if (firstComponent.equals("uid")) { uidMapping.put(localId, remoteId); } else { gidMapping.put(localId, remoteId); } } } finally { in.close(); } return new StaticMapping(uidMapping, gidMapping); } ShellBasedIdMapping(Configuration conf,
      final String defaultStaticIdMappingFile);  ShellBasedIdMapping(Configuration conf); }
ShellBasedIdMapping implements IdMappingServiceProvider { static StaticMapping parseStaticMap(File staticMapFile) throws IOException { Map<Integer, Integer> uidMapping = new HashMap<Integer, Integer>(); Map<Integer, Integer> gidMapping = new HashMap<Integer, Integer>(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(staticMapFile))); try { String line = null; while ((line = in.readLine()) != null) { if (EMPTY_LINE.matcher(line).matches() || COMMENT_LINE.matcher(line).matches()) { continue; } Matcher lineMatcher = MAPPING_LINE.matcher(line); if (!lineMatcher.matches()) { LOG.warn("Could not parse line '" + line + "'. Lines should be of " + "the form '[uid|gid] [remote id] [local id]'. Blank lines and " + "everything following a '#' on a line will be ignored."); continue; } String firstComponent = lineMatcher.group(1); int remoteId = Integer.parseInt(lineMatcher.group(2)); int localId = Integer.parseInt(lineMatcher.group(3)); if (firstComponent.equals("uid")) { uidMapping.put(localId, remoteId); } else { gidMapping.put(localId, remoteId); } } } finally { in.close(); } return new StaticMapping(uidMapping, gidMapping); } ShellBasedIdMapping(Configuration conf,
      final String defaultStaticIdMappingFile);  ShellBasedIdMapping(Configuration conf); @VisibleForTesting long getTimeout(); @VisibleForTesting static void updateMapInternal(BiMap<Integer, String> map, String mapName,
      String command, String regex, Map<Integer, Integer> staticMapping); synchronized void updateMaps(); synchronized int getUid(String user); synchronized int getGid(String group); synchronized String getUserName(int uid, String unknown); synchronized String getGroupName(int gid, String unknown); int getUidAllowingUnknown(String user); int getGidAllowingUnknown(String group); }
ShellBasedIdMapping implements IdMappingServiceProvider { static StaticMapping parseStaticMap(File staticMapFile) throws IOException { Map<Integer, Integer> uidMapping = new HashMap<Integer, Integer>(); Map<Integer, Integer> gidMapping = new HashMap<Integer, Integer>(); BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream(staticMapFile))); try { String line = null; while ((line = in.readLine()) != null) { if (EMPTY_LINE.matcher(line).matches() || COMMENT_LINE.matcher(line).matches()) { continue; } Matcher lineMatcher = MAPPING_LINE.matcher(line); if (!lineMatcher.matches()) { LOG.warn("Could not parse line '" + line + "'. Lines should be of " + "the form '[uid|gid] [remote id] [local id]'. Blank lines and " + "everything following a '#' on a line will be ignored."); continue; } String firstComponent = lineMatcher.group(1); int remoteId = Integer.parseInt(lineMatcher.group(2)); int localId = Integer.parseInt(lineMatcher.group(3)); if (firstComponent.equals("uid")) { uidMapping.put(localId, remoteId); } else { gidMapping.put(localId, remoteId); } } } finally { in.close(); } return new StaticMapping(uidMapping, gidMapping); } ShellBasedIdMapping(Configuration conf,
      final String defaultStaticIdMappingFile);  ShellBasedIdMapping(Configuration conf); @VisibleForTesting long getTimeout(); @VisibleForTesting static void updateMapInternal(BiMap<Integer, String> map, String mapName,
      String command, String regex, Map<Integer, Integer> staticMapping); synchronized void updateMaps(); synchronized int getUid(String user); synchronized int getGid(String group); synchronized String getUserName(int uid, String unknown); synchronized String getGroupName(int gid, String unknown); int getUidAllowingUnknown(String user); int getGidAllowingUnknown(String group);  }