Search in sources :

Example 1 with FileHelper

use of org.apache.qpid.server.util.FileHelper in project qpid-broker-j by apache.

the class FileGroupDatabase method writeGroupFile.

private synchronized void writeGroupFile(final String groupFile) throws IOException {
    final Properties propertiesFile = new Properties();
    for (String group : _groupToUserMap.keySet()) {
        Set<String> users = _groupToUserMap.get(group);
        final String userList = Joiner.on(",").useForNull("").join(users);
        propertiesFile.setProperty(group + ".users", userList);
    }
    new FileHelper().writeFileSafely(new File(groupFile).toPath(), new BaseAction<File, IOException>() {

        @Override
        public void performAction(File file) throws IOException {
            String comment = "Written " + new Date();
            try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
                propertiesFile.store(fileOutputStream, comment);
            }
        }
    });
}
Also used : FileHelper(org.apache.qpid.server.util.FileHelper) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) Date(java.util.Date)

Example 2 with FileHelper

use of org.apache.qpid.server.util.FileHelper in project qpid-broker-j by apache.

the class FileBasedGroupProviderImpl method onCreate.

@Override
protected void onCreate() {
    super.onCreate();
    File file = new File(_path);
    if (!file.exists()) {
        File parent = file.getAbsoluteFile().getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new IllegalConfigurationException(String.format("Cannot create groups file at '%s'", _path));
        }
        try {
            String posixFileAttributes = getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS);
            new FileHelper().createNewFile(file, posixFileAttributes);
        } catch (IOException e) {
            throw new IllegalConfigurationException(String.format("Cannot create groups file at '%s'", _path), e);
        }
    }
}
Also used : FileHelper(org.apache.qpid.server.util.FileHelper) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 3 with FileHelper

use of org.apache.qpid.server.util.FileHelper in project qpid-broker-j by apache.

the class PrincipalDatabaseAuthenticationManager method onCreate.

@Override
protected void onCreate() {
    super.onCreate();
    File passwordFile = new File(_path);
    if (!passwordFile.exists()) {
        try {
            Path path = new FileHelper().createNewFile(passwordFile, getContextValue(String.class, SystemConfig.POSIX_FILE_PERMISSIONS));
            if (!Files.exists(path)) {
                throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path));
            }
        } catch (IOException e) {
            throw new IllegalConfigurationException(String.format("Cannot create password file at '%s'", _path), e);
        }
    }
}
Also used : Path(java.nio.file.Path) FileHelper(org.apache.qpid.server.util.FileHelper) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)3 IOException (java.io.IOException)3 FileHelper (org.apache.qpid.server.util.FileHelper)3 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 Properties (java.util.Properties)1