/** * Put all the policy files together into a single properties instance. * @param policyDir The source directory where to read the policy files from. * @return An {@link NonEscapedProperties} instance containing all the properties read from the policy files found * @throws IOException When an IO error occurs reading any of the policy files */ public NonEscapedProperties readPolicyProperties(Path policyDir) throws IOException { NonEscapedProperties properties = new NonEscapedProperties(); Files.list(policyDir) .filter(this::isPolicyFile) .forEach(path -> loadPolicyFile(properties, path)); return properties; }
public void loadPolicyFile(NonEscapedProperties properties, Path path) { try { properties.load(path); } catch (IOException e) { logger.error("Security policy file load error: " + path, e); } } }
public void store(Writer writer, String... comments) throws IOException { StringBuilder out = new StringBuilder(); if (comments != null) { for (String comment : comments) { out.append("# ").append(comment).append("\n"); } out.append("\n"); } this.forEach((key, value) -> { out.append(key).append("=").append(value).append("\n"); }); writer.write(out.toString()); writer.flush(); }
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { try { checkNotNull("file", file); checkNotNull("attrs", attrs); if (isPolicyFile(file)) { String content = ioService.readAllString(file); NonEscapedProperties props = new NonEscapedProperties(); props.load(new StringReader(content)); marshaller.read(builder, props); } } catch (final Exception e) { logger.error("Authz policy file VFS read error: " + file.getFileName(), e); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } });
NonEscapedProperties entries = new NonEscapedProperties(); marshaller.write(policy, entries); entries.store(sw, "Authorization Policy", "Last update: " + new Date().toString());
public void load(Path file) throws IOException { for (String line : Files.readAllLines(file)) { putLine(line); } }
URL fileURL = Thread.currentThread().getContextClassLoader().getResource("WEB-INF/classes/security-policy.properties"); Path policyPath = Paths.get(fileURL.toURI()); NonEscapedProperties input = new NonEscapedProperties(); input.load(Files.newBufferedReader(policyPath)); marshaller.read(builder, input);
public void load(Reader reader) throws IOException { BufferedReader br = new BufferedReader(reader); String line; while ((line = br.readLine()) != null) { putLine(line); } }
URL fileURL = Thread.currentThread().getContextClassLoader().getResource("WEB-INF/classes/security-policy.properties"); Path policyPath = Paths.get(fileURL.toURI()); NonEscapedProperties input = new NonEscapedProperties(); input.load(Files.newBufferedReader(policyPath)); marshaller.read(builder, input);
NonEscapedProperties props = new NonEscapedProperties(); props.load(new StringReader(content)); marshaller.read(builder,