/0011-AS7-4536-add-user.sh-mangles-permissions-of-mgmt-use.patch
Patch | 99 lines | 89 code | 10 blank | 0 comment | 0 complexity | 3b9be9182f9b2170b4efa1a46b614edc MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
- From e4eb19be3408a137d08942feddd569f8cf70ce73 Mon Sep 17 00:00:00 2001
- From: Marek Goldmann <mgoldman@redhat.com>
- Date: Tue, 17 Apr 2012 13:56:43 +0200
- Subject: [PATCH 11/25] [AS7-4536] add-user.sh mangles permissions of
- mgmt-users.properties
- ---
- .../management/security/PropertiesFileLoader.java | 42 ++++++++++++--------
- 1 file changed, 25 insertions(+), 17 deletions(-)
- diff --git a/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java b/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java
- index 38737cb..9c4bad9 100644
- --- a/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java
- +++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java
- @@ -38,7 +38,9 @@ import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.nio.charset.Charset;
- +import java.util.ArrayList;
- import java.util.Arrays;
- +import java.util.List;
- import java.util.Properties;
-
- import static org.jboss.as.domain.management.DomainManagementLogger.ROOT_LOGGER;
- @@ -122,28 +124,36 @@ public abstract class PropertiesFileLoader {
- return properties;
- }
-
- + /**
- + * Saves changes in properties file. It reads the property file into memory,
- + * modifies it and saves it back to the file.
- + *
- + * @throws IOException
- + */
- public synchronized void persistProperties() throws IOException {
- Properties toSave = (Properties) properties.clone();
-
- - File backup = new File(propertiesFile.getCanonicalPath() + ".bak");
- - if (backup.exists()) {
- - if (backup.delete() == false) {
- - throw new IllegalStateException("Unable to delete backup properties file.");
- - }
- - }
- + List<String> content = new ArrayList<String>();
- + FileReader fileReader = new FileReader(propertiesFile);
- + BufferedReader bufferedFileReader = new BufferedReader(fileReader);
-
- - if (propertiesFile.renameTo(backup) == false) {
- - throw new IllegalStateException("Unable to backup properties file.");
- + // Read the properties file into memory
- + // Shouldn't be so bad - it's a small file
- + try {
- + String line = null;
- + int i = 0;
- + while ((line = bufferedFileReader.readLine()) != null) {
- + content.add(line);
- + }
- + } finally {
- + safeClose(bufferedFileReader);
- + safeClose(fileReader);
- }
-
- - FileReader fr = new FileReader(backup);
- - BufferedReader br = new BufferedReader(fr);
- -
- - BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(propertiesFile),"UTF8"));
- + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(propertiesFile), "UTF8"));
-
- try {
- - String line;
- - while ((line = br.readLine()) != null) {
- + for (String line : content) {
- String trimmed = line.trim();
- if (trimmed.startsWith("#")) {
- bw.append(line);
- @@ -172,12 +182,9 @@ public abstract class PropertiesFileLoader {
- }
- } finally {
- safeClose(bw);
- - safeClose(br);
- - safeClose(fr);
- }
- }
-
- -
- public static String escapeString(String name, char[] escapeArray) {
- Arrays.sort(escapeArray);
- for(int i = 0; i < name.length(); ++i) {
- @@ -198,6 +205,7 @@ public abstract class PropertiesFileLoader {
- }
- return name;
- }
- +
- private void safeClose(final Closeable c) {
- try {
- c.close();
- --
- 1.7.10.4