/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
1From e4eb19be3408a137d08942feddd569f8cf70ce73 Mon Sep 17 00:00:00 2001
2From: Marek Goldmann <mgoldman@redhat.com>
3Date: Tue, 17 Apr 2012 13:56:43 +0200
4Subject: [PATCH 11/25] [AS7-4536] add-user.sh mangles permissions of
5 mgmt-users.properties
6
7---
8 .../management/security/PropertiesFileLoader.java | 42 ++++++++++++--------
9 1 file changed, 25 insertions(+), 17 deletions(-)
10
11diff --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
12index 38737cb..9c4bad9 100644
13--- a/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java
14+++ b/domain-management/src/main/java/org/jboss/as/domain/management/security/PropertiesFileLoader.java
15@@ -38,7 +38,9 @@ import java.io.IOException;
16 import java.io.InputStreamReader;
17 import java.io.OutputStreamWriter;
18 import java.nio.charset.Charset;
19+import java.util.ArrayList;
20 import java.util.Arrays;
21+import java.util.List;
22 import java.util.Properties;
23
24 import static org.jboss.as.domain.management.DomainManagementLogger.ROOT_LOGGER;
25@@ -122,28 +124,36 @@ public abstract class PropertiesFileLoader {
26 return properties;
27 }
28
29+ /**
30+ * Saves changes in properties file. It reads the property file into memory,
31+ * modifies it and saves it back to the file.
32+ *
33+ * @throws IOException
34+ */
35 public synchronized void persistProperties() throws IOException {
36 Properties toSave = (Properties) properties.clone();
37
38- File backup = new File(propertiesFile.getCanonicalPath() + ".bak");
39- if (backup.exists()) {
40- if (backup.delete() == false) {
41- throw new IllegalStateException("Unable to delete backup properties file.");
42- }
43- }
44+ List<String> content = new ArrayList<String>();
45+ FileReader fileReader = new FileReader(propertiesFile);
46+ BufferedReader bufferedFileReader = new BufferedReader(fileReader);
47
48- if (propertiesFile.renameTo(backup) == false) {
49- throw new IllegalStateException("Unable to backup properties file.");
50+ // Read the properties file into memory
51+ // Shouldn't be so bad - it's a small file
52+ try {
53+ String line = null;
54+ int i = 0;
55+ while ((line = bufferedFileReader.readLine()) != null) {
56+ content.add(line);
57+ }
58+ } finally {
59+ safeClose(bufferedFileReader);
60+ safeClose(fileReader);
61 }
62
63- FileReader fr = new FileReader(backup);
64- BufferedReader br = new BufferedReader(fr);
65-
66- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(propertiesFile),"UTF8"));
67+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(propertiesFile), "UTF8"));
68
69 try {
70- String line;
71- while ((line = br.readLine()) != null) {
72+ for (String line : content) {
73 String trimmed = line.trim();
74 if (trimmed.startsWith("#")) {
75 bw.append(line);
76@@ -172,12 +182,9 @@ public abstract class PropertiesFileLoader {
77 }
78 } finally {
79 safeClose(bw);
80- safeClose(br);
81- safeClose(fr);
82 }
83 }
84
85-
86 public static String escapeString(String name, char[] escapeArray) {
87 Arrays.sort(escapeArray);
88 for(int i = 0; i < name.length(); ++i) {
89@@ -198,6 +205,7 @@ public abstract class PropertiesFileLoader {
90 }
91 return name;
92 }
93+
94 private void safeClose(final Closeable c) {
95 try {
96 c.close();
97--
981.7.10.4
99