Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2017-05-21 01:36:42 -0400
committerEike Stepper2017-05-21 01:36:42 -0400
commit2fcbde92d9cad912cbcc68c81a14a04bb849a5ea (patch)
treee42399cd78be272ae63d6fc8a1846e9c1e7ca23f
parent841e207ecfbccab5ed6ac0d378bd0d5c719d48d4 (diff)
downloadcdo-2fcbde92d9cad912cbcc68c81a14a04bb849a5ea.tar.gz
cdo-2fcbde92d9cad912cbcc68c81a14a04bb849a5ea.tar.xz
cdo-2fcbde92d9cad912cbcc68c81a14a04bb849a5ea.zip
[517027] Add FileUserManager option to "fail if file does not exist"
https://bugs.eclipse.org/bugs/show_bug.cgi?id=517027
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/FileUserManager.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/FileUserManager.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/FileUserManager.java
index d082c8954c..6e6ce79b57 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/FileUserManager.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/security/FileUserManager.java
@@ -32,6 +32,8 @@ public class FileUserManager extends UserManager
{
private static final boolean FALL_BACK_TO_CONFIG_FOLDER = OMPlatform.INSTANCE.isProperty("net4j.security.FileUserManager.fallBackToConfigFolder");
+ private static final boolean FAIL_IF_FILE_DOES_NOT_EXIST = OMPlatform.INSTANCE.isProperty("net4j.security.FileUserManager.failIfFileDoesNotExist");
+
private static final String CONFIG_FOLDER_PREFIX = "@config/";
protected String fileName;
@@ -56,8 +58,8 @@ public class FileUserManager extends UserManager
* <li> If it is relative it is interpreted as relative to the application's current directory.
* <li> Otherwise it is interpreted as absolute.
* </ol>
- * The resolved file is not required to exist when this user manager is activated. In this case it will be created when {@link #addUser(String, char[]) addUser()}
- * or {@link #removeUser(String) removeUser()} are called.
+ * Unless &quot;-Dnet4j.security.FileUserManager.failIfFileDoesNotExist=true&quot; is specified the resolved file is not required to exist when this user manager is activated.
+ * In this case it will be created when {@link #addUser(String, char[]) addUser()} or {@link #removeUser(String) removeUser()} are called.
* <p>
* With &quot;-Dnet4j.security.FileUserManager.fallBackToConfigFolder=true&quot; a relative path is resolved in both the application's current folder
* and the config folder (in this order).
@@ -127,21 +129,24 @@ public class FileUserManager extends UserManager
@Override
protected void load(Map<String, char[]> users) throws IORuntimeException
{
- if (file != null && file.isFile())
+ if (file != null)
{
- FileInputStream stream = IOUtil.openInputStream(file);
-
- try
- {
- load(users, stream);
- }
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
- finally
+ if (FAIL_IF_FILE_DOES_NOT_EXIST || file.isFile())
{
- IOUtil.closeSilent(stream);
+ FileInputStream stream = IOUtil.openInputStream(file);
+
+ try
+ {
+ load(users, stream);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ IOUtil.closeSilent(stream);
+ }
}
}
}

Back to the top