public GridMapFilePlugin(Properties properties) { String path = properties.getProperty(GRIDMAP); checkArgument(path != null, "Undefined property: " + GRIDMAP); _gridMapFile = new GridMapFile(path); }
public GridMapFile(File file) { _file = file; refresh(); }
public synchronized void refresh() { try { long now = System.currentTimeMillis(); boolean readable = _file.canRead() || _loaded == 0; if (!readable) { _log.error("WARNING: Could not read grid-mapfile. Will use cached copy."); } else if (_loaded < _file.lastModified()) { _log.debug("GridMapFileHandler reading {}", _file); try (BufferedReader reader = new BufferedReader(new FileReader(_file))) { _map = read(reader); _loaded = now; } } } catch (IOException e) { _log.error("Failed to load grid-mapfile: {}", e.getMessage()); } }
private static ImmutableMultimap<String,String> read(BufferedReader reader) throws IOException { ImmutableMultimap.Builder<String,String> map = ImmutableMultimap.builder(); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length()==0 || line.charAt(0) != '\"') { continue; } line = line.substring(1); int last_quote = line.lastIndexOf('\"'); if (last_quote == -1) { continue; } String dn = line.substring(0, last_quote); String user = line.substring(last_quote + 1).trim(); if (user != null && user.length() > 0) { map.put(dn.trim(), removeQuotes(user.trim())); } } return map.build(); }
private Map.Entry<Principal,String> getMappingFor(Set<Principal> principals) { Principal loginName = find(principals, instanceOf(LoginNamePrincipal.class), null); for (Principal principal: principals) { if (principal instanceof GlobusPrincipal || principal instanceof KerberosPrincipal) { Collection<String> names = _gridMapFile.getMappedUsernames(principal.getName()); if (!names.isEmpty()) { String name; if (loginName == null) { name = get(names, 0); } else if (names.contains(loginName.getName())) { name = loginName.getName(); } else { continue; } return new SimpleImmutableEntry<>(principal, name); } } } return null; }
@Override public void map(Set<Principal> principals) throws AuthenticationException { if (any(principals, instanceOf(UserNamePrincipal.class))) { return; } _gridMapFile.refresh(); Map.Entry<Principal,String> entry = getMappingFor(principals); checkAuthentication(entry != null, "no mapping"); principals.add(new UserNamePrincipal(entry.getValue())); } }