X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifUserAdmin.java;fp=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifUserAdmin.java;h=832e8e57819a87eaf72f261057615a1c312a544d;hb=043d226a5504a212eb5673c3ed4441c1167724d7;hp=970ab7162949aa5ad82e12fcf3727679476785c9;hpb=cdc0e2725f4ec174309c3fdcd060f80753210c00;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java index 970ab7162..832e8e578 100644 --- a/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java +++ b/org.argeo.enterprise/src/org/argeo/osgi/useradmin/LdifUserAdmin.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Collections; import java.util.Dictionary; @@ -40,15 +41,19 @@ public class LdifUserAdmin extends AbstractUserDirectory { private SortedMap groups = new TreeMap(); public LdifUserAdmin(String uri, String baseDn) { - this(fromUri(uri, baseDn)); + this(fromUri(uri, baseDn), false); } public LdifUserAdmin(Dictionary properties) { - super(null, properties); + this(properties, false); + } + + protected LdifUserAdmin(Dictionary properties, boolean scoped) { + super(null, properties, scoped); } public LdifUserAdmin(URI uri, Dictionary properties) { - super(uri, properties); + super(uri, properties, false); } @Override @@ -69,7 +74,7 @@ public class LdifUserAdmin extends AbstractUserDirectory { } Dictionary properties = cloneProperties(); properties.put(UserAdminConf.readOnly.name(), "true"); - LdifUserAdmin scopedUserAdmin = new LdifUserAdmin(properties); + LdifUserAdmin scopedUserAdmin = new LdifUserAdmin(properties, true); scopedUserAdmin.groups = Collections.unmodifiableSortedMap(groups); scopedUserAdmin.users = Collections.unmodifiableSortedMap(users); return scopedUserAdmin; @@ -83,13 +88,15 @@ public class LdifUserAdmin extends AbstractUserDirectory { } public void init() { + try { - if (getUri().getScheme().equals("file")) { - File file = new File(getUri()); + URI u = new URI(getUri()); + if (u.getScheme().equals("file")) { + File file = new File(u); if (!file.exists()) return; } - load(getUri().toURL().openStream()); + load(u.toURL().openStream()); } catch (Exception e) { throw new UserDirectoryException("Cannot open URL " + getUri(), e); } @@ -100,9 +107,9 @@ public class LdifUserAdmin extends AbstractUserDirectory { throw new UserDirectoryException("Cannot save LDIF user admin: no URI is set"); if (isReadOnly()) throw new UserDirectoryException("Cannot save LDIF user admin: " + getUri() + " is read-only"); - try (FileOutputStream out = new FileOutputStream(new File(getUri()))) { + try (FileOutputStream out = new FileOutputStream(new File(new URI(getUri())))) { save(out); - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { throw new UserDirectoryException("Cannot save user admin to " + getUri(), e); } }