X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fuseradmin%2FLdifUserAdmin.java;h=c32bbc53fa9236f3f81211dfb8d6730a63ba746d;hb=f9efbe5228615951dd8482a4582aa24e00c10ce5;hp=970ab7162949aa5ad82e12fcf3727679476785c9;hpb=02598cbf70f6e38df5c06cba8bc322dfbb082419;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..c32bbc53f 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; @@ -23,7 +24,6 @@ import javax.naming.NameNotFoundException; import javax.naming.NamingEnumeration; import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; -import javax.transaction.TransactionManager; import org.argeo.naming.LdifParser; import org.argeo.naming.LdifWriter; @@ -31,24 +31,25 @@ import org.osgi.framework.Filter; import org.osgi.service.useradmin.Role; import org.osgi.service.useradmin.User; -/** - * A user admin based on a LDIF files. Requires a {@link TransactionManager} and - * an open transaction for write access. - */ +/** A user admin based on a LDIF files. */ public class LdifUserAdmin extends AbstractUserDirectory { private SortedMap users = new TreeMap(); 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 +70,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 +84,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 +103,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); } }