package org.argeo.osgi.useradmin;
import static org.argeo.naming.LdapAttrs.objectClass;
+import static org.argeo.naming.LdapObjs.extensibleObject;
import static org.argeo.naming.LdapObjs.inetOrgPerson;
import static org.argeo.naming.LdapObjs.organizationalPerson;
import static org.argeo.naming.LdapObjs.person;
import java.util.List;
import javax.naming.InvalidNameException;
+import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.naming.LdapAttrs;
+import org.argeo.naming.LdapObjs;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
private TransactionManager transactionManager;
private WcXaResource xaResource = new WcXaResource(this);
- public AbstractUserDirectory(Dictionary<String, ?> props) {
+ public AbstractUserDirectory(URI uriArg, 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)
- uri = null;
- else
- try {
- uri = new URI(uriStr);
- } catch (URISyntaxException e) {
- throw new UserDirectoryException("Badly formatted URI " + uriStr, e);
- }
+ if (uriArg != null) {
+ uri = uriArg;
+ // uri from properties is ignored
+ } else {
+ String uriStr = UserAdminConf.uri.getValue(properties);
+ if (uriStr == null)
+ uri = null;
+ else
+ try {
+ uri = new URI(uriStr);
+ } catch (URISyntaxException e) {
+ throw new UserDirectoryException("Badly formatted URI " + uriStr, e);
+ }
+ }
userObjectClass = UserAdminConf.userObjectClass.getValue(properties);
userBase = UserAdminConf.userBase.getValue(properties);
protected abstract Boolean daoHasRole(LdapName dn);
- protected abstract DirectoryUser daoGetRole(LdapName key);
+ protected abstract DirectoryUser daoGetRole(LdapName key) throws NameNotFoundException;
protected abstract List<DirectoryUser> doGetRoles(Filter f);
private void collectRoles(DirectoryUser user, List<Role> allRoles) {
Attributes attrs = user.getAttributes();
// TODO centralize attribute name
- Attribute memberOf = attrs.get("memberOf");
+ Attribute memberOf = attrs.get(LdapAttrs.memberOf.name());
if (memberOf != null) {
try {
NamingEnumeration<?> values = memberOf.getAll();
protected DirectoryUser doGetRole(LdapName dn) {
UserDirectoryWorkingCopy wc = getWorkingCopy();
- DirectoryUser user = daoGetRole(dn);
+ DirectoryUser user;
+ try {
+ user = daoGetRole(dn);
+ } catch (NameNotFoundException e) {
+ user = null;
+ }
if (wc != null) {
if (user == null && wc.getNewUsers().containsKey(dn))
user = wc.getNewUsers().get(dn);
if (wc.getDeletedUsers().containsKey(dn)) {
wc.getDeletedUsers().remove(dn);
wc.getModifiedUsers().put(dn, attrs);
+ return getRole(name);
} else {
wc.getModifiedUsers().put(dn, attrs);
DirectoryUser newRole = newRole(dn, type, attrs);
wc.getNewUsers().put(dn, newRole);
+ return newRole;
}
- return getRole(name);
}
protected DirectoryUser newRole(LdapName dn, int type, Attributes attrs) {
objClass.add(person.name());
}
objClass.add(top.name());
+ objClass.add(extensibleObject.name());
attrs.put(objClass);
newRole = new LdifUser(this, dn, attrs);
} else if (type == Role.GROUP) {
private static boolean readOnlyDefault(URI uri) {
if (uri == null)
return true;
+ if (uri.getScheme() == null)
+ return false;// assume relative file to be writable
if (uri.getScheme().equals("file")) {
File file = new File(uri);
if (file.exists())