String nodeRolesUri = getFrameworkProp(NodeConstants.ROLES_URI);
String baseNodeRoleDn = NodeConstants.ROLES_BASEDN;
if (nodeRolesUri == null) {
- File nodeRolesFile = new File(nodeBaseDir, baseNodeRoleDn + ".ldif");
+ nodeRolesUri = baseNodeRoleDn + ".ldif";
+ File nodeRolesFile = new File(nodeBaseDir, nodeRolesUri);
if (!nodeRolesFile.exists())
try {
FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(baseNodeRoleDn + ".ldif"),
} catch (IOException e) {
throw new CmsException("Cannot copy demo resource", e);
}
- nodeRolesUri = nodeRolesFile.toURI().toString();
+ // nodeRolesUri = nodeRolesFile.toURI().toString();
}
uris.add(nodeRolesUri);
String userAdminUris = getFrameworkProp(NodeConstants.USERADMIN_URIS);
if (userAdminUris == null) {
String demoBaseDn = "dc=example,dc=com";
- File businessRolesFile = new File(nodeBaseDir, demoBaseDn + ".ldif");
+ userAdminUris = demoBaseDn + ".ldif";
+ File businessRolesFile = new File(nodeBaseDir, userAdminUris);
if (!businessRolesFile.exists())
try {
FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(demoBaseDn + ".ldif"),
} catch (IOException e) {
throw new CmsException("Cannot copy demo resource", e);
}
- userAdminUris = businessRolesFile.toURI().toString();
+ // userAdminUris = businessRolesFile.toURI().toString();
log.warn("## DEV Using dummy base DN " + demoBaseDn);
// TODO downgrade security level
}
if (uri.startsWith("/") || uri.startsWith("./") || uri.startsWith("../"))
u = new File(uri).getCanonicalFile().toURI();
else if (!uri.contains("/")) {
- u = KernelUtils.getOsgiInstanceUri(KernelConstants.DIR_NODE + '/' + uri);
- // u = new URI(nodeBaseDir.toURI() + uri);
+ // u = KernelUtils.getOsgiInstanceUri(KernelConstants.DIR_NODE + '/' + uri);
+ u = new URI(uri);
} else
throw new CmsException("Cannot interpret " + uri + " as an uri");
} else if (u.getScheme().equals("file")) {
String uri = (String) properties.get(UserAdminConf.uri.name());
URI u;
try {
- u = new URI(uri);
+ if (uri == null) {
+ String baseDn = (String) properties.get(UserAdminConf.baseDn.name());
+ u = KernelUtils.getOsgiInstanceUri(KernelConstants.DIR_NODE + '/' + baseDn + ".ldif");
+ } else
+ u = new URI(uri);
} catch (URISyntaxException e) {
throw new CmsException("Badly formatted URI " + uri, e);
}
// Create
AbstractUserDirectory userDirectory = u.getScheme().equals("ldap") ? new LdapUserAdmin(properties)
- : new LdifUserAdmin(properties);
+ : new LdifUserAdmin(u, properties);
Object realm = userDirectory.getProperties().get(UserAdminConf.realm.name());
addUserDirectory(userDirectory);
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);
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())
private InitialLdapContext initialLdapContext = null;
public LdapUserAdmin(Dictionary<String, ?> properties) {
- super(properties);
+ super(null, properties);
try {
Hashtable<String, Object> connEnv = new Hashtable<String, Object>();
connEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashSet;
}
public LdifUserAdmin(Dictionary<String, ?> properties) {
- super(properties);
+ super(null, properties);
}
+ public LdifUserAdmin(URI uri, Dictionary<String, ?> properties) {
+ super(uri, properties);
+ }
+
+ @Deprecated
public LdifUserAdmin(InputStream in) {
- super(new Hashtable<String, Object>());
+ super(null, new Hashtable<String, Object>());
load(in);
}
scheme = u.getScheme();
}
String path = u.getPath();
+ // base DN
String bDn = path.substring(path.lastIndexOf('/') + 1, path.length());
if (bDn.endsWith(".ldif"))
bDn = bDn.substring(0, bDn.length() - ".ldif".length());
res.put(Context.SECURITY_PRINCIPAL, principal);
if (credentials != null)
res.put(Context.SECURITY_CREDENTIALS, credentials);
- if (scheme != null) {
+ if (scheme != null) {// relative URIs are dealt with externally
URI bareUri = new URI(scheme, null, u.getHost(), u.getPort(),
scheme.equals("file") ? u.getPath() : null, null, null);
res.put(uri.name(), bareUri.toString());