import java.io.File;
import java.io.IOException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsException;
import org.argeo.cms.KernelHeader;
-import org.argeo.osgi.useradmin.UserDirectory;
-import org.argeo.osgi.useradmin.UserAdminConf;
import org.argeo.osgi.useradmin.LdapUserAdmin;
import org.argeo.osgi.useradmin.LdifUserAdmin;
+import org.argeo.osgi.useradmin.UserAdminConf;
+import org.argeo.osgi.useradmin.UserDirectory;
import org.argeo.osgi.useradmin.UserDirectoryException;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.service.useradmin.Authorization;
URI u;
try {
u = new URI(uri);
+ if (u.getPath() == null)
+ throw new CmsException("URI " + uri
+ + " must have a path in order to determine base DN");
if (u.getScheme() == null) {
- if (uri.startsWith("/"))
- u = new File(uri).getAbsoluteFile().toURI();
+ if (uri.startsWith("/") || uri.startsWith("./")
+ || uri.startsWith("../"))
+ u = new File(uri).getCanonicalFile().toURI();
else if (!uri.contains("/"))
- u = new File(nodeBaseDir, uri).getAbsoluteFile()
+ u = new File(nodeBaseDir, uri).getCanonicalFile()
.toURI();
else
throw new CmsException("Cannot interpret " + uri
+ " as an uri");
+ } else if (u.getScheme().equals("file")) {
+ u = new File(u).getCanonicalFile().toURI();
}
- } catch (URISyntaxException e) {
+ } catch (Exception e) {
throw new CmsException(
"Cannot interpret " + uri + " as an uri", e);
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
private final static Log log = LogFactory
.getLog(AbstractUserDirectory.class);
- private Dictionary<String, ?> properties;
- private String baseDn = "dc=example,dc=com";
- private String userObjectClass;
- private String groupObjectClass;
+ private final Hashtable<String, Object> properties;
+ private final String baseDn;
+ private final String userObjectClass;
+ private final String groupObjectClass;
- private boolean isReadOnly;
- private URI uri;
+ private final boolean readOnly;
+ private final URI uri;
private UserAdmin externalRoles;
private List<String> indexedUserProperties = Arrays.asList(new String[] {
private ThreadLocal<WorkingCopy> workingCopy = new ThreadLocal<AbstractUserDirectory.WorkingCopy>();
private Xid editingTransactionXid = null;
- AbstractUserDirectory(Dictionary<String, ?> properties) {
- // TODO make a copy?
- this.properties = properties;
+ AbstractUserDirectory(Dictionary<String, ?> props) {
+ properties = new Hashtable<String, Object>();
+ for (Enumeration<String> keys = props.keys(); keys.hasMoreElements();) {
+ String key = keys.nextElement();
+ properties.put(key, props.get(key));
+ }
String uriStr = UserAdminConf.uri.getValue(properties);
if (uriStr == null)
try {
uri = new URI(uriStr);
} catch (URISyntaxException e) {
- throw new UserDirectoryException("Badly formatted URI", e);
+ throw new UserDirectoryException("Badly formatted URI "
+ + uriStr, e);
}
baseDn = UserAdminConf.baseDn.getValue(properties).toString();
- String isReadOnly = UserAdminConf.readOnly.getValue(properties);
- if (isReadOnly == null)
- this.isReadOnly = readOnlyDefault(uri);
- else
- this.isReadOnly = new Boolean(isReadOnly);
+ String readOnlyStr = UserAdminConf.readOnly.getValue(properties);
+ if (readOnlyStr == null) {
+ readOnly = readOnlyDefault(uri);
+ properties.put(UserAdminConf.readOnly.property(),
+ Boolean.toString(readOnly));
+ } else
+ readOnly = new Boolean(readOnlyStr);
- this.userObjectClass = UserAdminConf.userObjectClass
- .getValue(properties);
- this.groupObjectClass = UserAdminConf.groupObjectClass
- .getValue(properties);
+ userObjectClass = UserAdminConf.userObjectClass.getValue(properties);
+ groupObjectClass = UserAdminConf.groupObjectClass.getValue(properties);
}
/** Returns the groups this user is a direct member of. */
return uri;
}
- protected void setUri(URI uri) {
- this.uri = uri;
- }
-
protected List<String> getIndexedUserProperties() {
return indexedUserProperties;
}
this.indexedUserProperties = indexedUserProperties;
}
- protected void setReadOnly(boolean isReadOnly) {
- this.isReadOnly = isReadOnly;
- }
-
private static boolean readOnlyDefault(URI uri) {
if (uri == null)
return true;
if (uri.getScheme().equals("file")) {
File file = new File(uri);
- return !file.canWrite();
+ if (file.exists())
+ return !file.canWrite();
+ else
+ return !file.getParentFile().canWrite();
}
return true;
}
public boolean isReadOnly() {
- return isReadOnly;
+ return readOnly;
}
UserAdmin getExternalRoles() {