- private void initUserAdmins(String userAdminUri, File nodeBaseDir) {
- if (userAdminUri == null) {
- String demoBaseDn = "dc=example,dc=com";
- File businessRolesFile = new File(nodeBaseDir, demoBaseDn + ".ldif");
- if (!businessRolesFile.exists())
- try {
- FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(demoBaseDn + ".ldif"),
- businessRolesFile);
- } catch (IOException e) {
- throw new CmsException("Cannot copy demo resource", e);
- }
- userAdminUri = businessRolesFile.toURI().toString();
- }
- String[] uris = userAdminUri.split(" ");
- for (String uri : uris) {
- 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("/") || uri.startsWith("./") || uri.startsWith("../"))
- u = new File(uri).getCanonicalFile().toURI();
- else if (!uri.contains("/")) {
- u = new URI(nodeBaseDir.toURI() + uri);
- // 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 (Exception e) {
- throw new CmsException("Cannot interpret " + uri + " as an uri", e);
- }
- Dictionary<String, ?> properties = UserAdminConf.uriAsProperties(u.toString());
- UserDirectory businessRoles;
- if (u.getScheme().startsWith("ldap")) {
- businessRoles = new LdapUserAdmin(properties);
- } else {
- businessRoles = new LdifUserAdmin(properties);
- }
- businessRoles.init();
- String baseDn = businessRoles.getBaseDn();
- if (userAdmins.containsKey(baseDn))
- throw new UserDirectoryException("There is already a user admin for " + baseDn);
- try {
- userAdmins.put(new LdapName(baseDn), (UserAdmin) businessRoles);
- } catch (InvalidNameException e) {
- throw new UserDirectoryException("Badly formatted base DN " + baseDn, e);
- }
- addUserAdmin(businessRoles.getBaseDn(), (UserAdmin) businessRoles);
- if (log.isDebugEnabled())
- log.debug("User directory " + businessRoles.getBaseDn() + " [" + u.getScheme() + "] enabled.");
- }
-
- }
-
- private void initNodeRoles(String nodeRolesUri, File nodeBaseDir) {
- String baseNodeRoleDn = AuthConstants.ROLES_BASEDN;
- if (nodeRolesUri == null) {
- File nodeRolesFile = new File(nodeBaseDir, baseNodeRoleDn + ".ldif");
- if (!nodeRolesFile.exists())
- try {
- FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(baseNodeRoleDn + ".ldif"),
- nodeRolesFile);
- } catch (IOException e) {
- throw new CmsException("Cannot copy demo resource", e);
- }
- nodeRolesUri = nodeRolesFile.toURI().toString();
- }
-
- Dictionary<String, ?> nodeRolesProperties = UserAdminConf.uriAsProperties(nodeRolesUri);
- if (!nodeRolesProperties.get(UserAdminConf.baseDn.name()).equals(baseNodeRoleDn)) {
- throw new CmsException("Invalid base dn for node roles");
- // TODO deal with "mounted" roles with a different baseDN
- }
- if (nodeRolesUri.startsWith("ldap")) {
- nodeRoles = new LdapUserAdmin(nodeRolesProperties);
- } else {
- nodeRoles = new LdifUserAdmin(nodeRolesProperties);
- }
- ((UserDirectory) nodeRoles).setExternalRoles(this);
- ((UserDirectory) nodeRoles).init();
- addUserAdmin(baseNodeRoleDn, (UserAdmin) nodeRoles);
- if (log.isTraceEnabled())
- log.trace("Node roles enabled.");
-
- }
+ // private void initUserAdmins(String userAdminUri, File nodeBaseDir) {
+ // // if (userAdminUri == null) {
+ // // String demoBaseDn = "dc=example,dc=com";
+ // // File businessRolesFile = new File(nodeBaseDir, demoBaseDn + ".ldif");
+ // // if (!businessRolesFile.exists())
+ // // try {
+ // //
+ // FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(demoBaseDn
+ // // + ".ldif"),
+ // // businessRolesFile);
+ // // } catch (IOException e) {
+ // // throw new CmsException("Cannot copy demo resource", e);
+ // // }
+ // // userAdminUri = businessRolesFile.toURI().toString();
+ // // }
+ // String[] uris = userAdminUri.split(" ");
+ // for (String uri : uris) {
+ // 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("/") || uri.startsWith("./") || uri.startsWith("../"))
+ // u = new File(uri).getCanonicalFile().toURI();
+ // else if (!uri.contains("/")) {
+ // u = new URI(nodeBaseDir.toURI() + uri);
+ // // 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 (Exception e) {
+ // throw new CmsException("Cannot interpret " + uri + " as an uri", e);
+ // }
+ // Dictionary<String, ?> properties =
+ // UserAdminConf.uriAsProperties(u.toString());
+ // UserDirectory businessRoles;
+ // if (u.getScheme().startsWith("ldap")) {
+ // businessRoles = new LdapUserAdmin(properties);
+ // } else {
+ // businessRoles = new LdifUserAdmin(properties);
+ // }
+ // businessRoles.init();
+ // String baseDn = businessRoles.getBaseDn();
+ // if (userAdmins.containsKey(baseDn))
+ // throw new UserDirectoryException("There is already a user admin for " +
+ // baseDn);
+ // try {
+ // userAdmins.put(new LdapName(baseDn), (UserAdmin) businessRoles);
+ // } catch (InvalidNameException e) {
+ // throw new UserDirectoryException("Badly formatted base DN " + baseDn, e);
+ // }
+ // addUserAdmin(businessRoles.getBaseDn(), (UserAdmin) businessRoles);
+ // if (log.isDebugEnabled())
+ // log.debug("User directory " + businessRoles.getBaseDn() + " [" +
+ // u.getScheme() + "] enabled.");
+ // }
+ //
+ // }
+ //
+ // private void initNodeRoles(String nodeRolesUri, File nodeBaseDir) {
+ // String baseNodeRoleDn = AuthConstants.ROLES_BASEDN;
+ // if (nodeRolesUri == null) {
+ // File nodeRolesFile = new File(nodeBaseDir, baseNodeRoleDn + ".ldif");
+ // if (!nodeRolesFile.exists())
+ // try {
+ // FileUtils.copyInputStreamToFile(getClass().getResourceAsStream(baseNodeRoleDn
+ // + ".ldif"),
+ // nodeRolesFile);
+ // } catch (IOException e) {
+ // throw new CmsException("Cannot copy demo resource", e);
+ // }
+ // nodeRolesUri = nodeRolesFile.toURI().toString();
+ // }
+ //
+ // Dictionary<String, ?> nodeRolesProperties =
+ // UserAdminConf.uriAsProperties(nodeRolesUri);
+ // if
+ // (!nodeRolesProperties.get(UserAdminConf.baseDn.name()).equals(baseNodeRoleDn))
+ // {
+ // throw new CmsException("Invalid base dn for node roles");
+ // // TODO deal with "mounted" roles with a different baseDN
+ // }
+ // if (nodeRolesUri.startsWith("ldap")) {
+ // nodeRoles = new LdapUserAdmin(nodeRolesProperties);
+ // } else {
+ // nodeRoles = new LdifUserAdmin(nodeRolesProperties);
+ // }
+ // ((UserDirectory) nodeRoles).setExternalRoles(this);
+ // ((UserDirectory) nodeRoles).init();
+ // addUserAdmin(baseNodeRoleDn, (UserAdmin) nodeRoles);
+ // if (log.isTraceEnabled())
+ // log.trace("Node roles enabled.");
+ //
+ // }