FileSystem fileSystem = nodeFileSystemProvider.getFileSystem(uri);
if (fileSystem == null)
fileSystem = nodeFileSystemProvider.newFileSystem(uri, null);
- Path nodePath = fileSystem.getPath("~");
+ Path nodePath = fileSystem.getPath("/");
Path localPath = Paths.get(System.getProperty("user.home"));
import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
import org.argeo.eclipse.ui.jcr.utils.NodeViewerComparer;
import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeConstants;
import org.argeo.node.security.CryptoKeyring;
import org.argeo.node.security.Keyring;
import org.eclipse.e4.core.contexts.IEclipseContext;
top.setLayout(CmsUtils.noSpaceGridLayout());
try {
- this.userSession = this.nodeRepository.login();
+ this.userSession = this.nodeRepository.login(NodeConstants.HOME);
} catch (RepositoryException e) {
throw new CmsException("Cannot open user session", e);
}
private DataModels dataModels;
private DeployConfig deployConfig;
- private HomeRepository homeRepository;
private Long availableSince;
// Publish home with the highest service ranking
Hashtable<String, Object> regProps = new Hashtable<>();
- regProps.put(NodeConstants.CN, NodeConstants.HOME);
+ regProps.put(NodeConstants.CN, NodeConstants.EGO);
regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
- homeRepository = new HomeRepository(deployedRepository, false);
- bc.registerService(Repository.class, homeRepository, regProps);
+ Repository egoRepository = new EgoRepository(deployedRepository, false);
+ bc.registerService(Repository.class, egoRepository, regProps);
// Keyring only if Argeo extensions are available
if (argeoDataModelExtensionsAvailable) {
@Override
public CallbackHandler addingService(ServiceReference<CallbackHandler> reference) {
- NodeKeyRing nodeKeyring = new NodeKeyRing(homeRepository);
+ NodeKeyRing nodeKeyring = new NodeKeyRing(egoRepository);
CallbackHandler callbackHandler = bc.getService(reference);
nodeKeyring.setDefaultCallbackHandler(callbackHandler);
bc.registerService(LangUtils.names(Keyring.class, CryptoKeyring.class, ManagedService.class),
import java.util.Map;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.RepositoryFactory;
import org.argeo.jcr.fs.JcrFileSystemProvider;
import org.argeo.jcr.fs.JcrFsException;
import org.argeo.node.NodeConstants;
-import org.argeo.node.NodeTypes;
import org.argeo.node.NodeUtils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
URI repoUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), "/jcr/node", null, null);
RepositoryFactory repositoryFactory = bc.getService(bc.getServiceReference(RepositoryFactory.class));
Repository repository = NodeUtils.getRepositoryByUri(repositoryFactory, repoUri.toString());
- Session session = repository.login("main");
- CmsFileSystem fileSystem = new CmsFileSystem(this, session);
+// Session session = repository.login("main");
+ CmsFileSystem fileSystem = new CmsFileSystem(this, repository);
fileSystems.put(username, fileSystem);
return fileSystem;
} else {
Repository repository = bc.getService(
- bc.getServiceReferences(Repository.class, "(cn=" + NodeConstants.HOME + ")").iterator().next());
- Session session = repository.login();
- CmsFileSystem fileSystem = new CmsFileSystem(this, session);
+ bc.getServiceReferences(Repository.class, "(cn=" + NodeConstants.EGO + ")").iterator().next());
+// Session session = repository.login();
+ CmsFileSystem fileSystem = new CmsFileSystem(this, repository);
fileSystems.put(username, fileSystem);
return fileSystem;
}
return fileSystems.get(username);
}
- public Node getUserHome(Session session) {
- return NodeUtils.getUserHome(session);
+ public Node getUserHome(Repository repository) {
+ try {
+ Session session = repository.login(NodeConstants.HOME);
+ return NodeUtils.getUserHome(session);
+ } catch (RepositoryException e) {
+ throw new IllegalStateException("Cannot get user home", e);
+ }
}
static class CmsFileSystem extends JcrFileSystem {
- public CmsFileSystem(JcrFileSystemProvider provider, Session session) throws IOException {
- super(provider, session);
+ public CmsFileSystem(JcrFileSystemProvider provider, Repository repository) throws IOException {
+ super(provider, repository);
}
public boolean skipNode(Node node) throws RepositoryException {
// || node.isNodeType(NodeTypes.NODE_GROUP_HOME))
if (node.isNodeType(NodeType.NT_HIERARCHY_NODE))
return false;
+ // FIXME Better identifies home
+ if (node.hasProperty(Property.JCR_ID))
+ return false;
return true;
}
private final Log log = LogFactory.getLog(getClass());
private final BundleContext bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
- private HomeRepository homeRepository;
+ private EgoRepository egoRepository;
public CmsInstance() {
initTrackers();
@Override
public Repository addingService(ServiceReference<Repository> reference) {
Object cn = reference.getProperty(NodeConstants.CN);
- if (cn != null && cn.equals(NodeConstants.HOME)) {
- homeRepository = (HomeRepository) bc.getService(reference);
+ if (cn != null && cn.equals(NodeConstants.EGO)) {
+ egoRepository = (EgoRepository) bc.getService(reference);
if (log.isTraceEnabled())
log.trace("Home repository is available");
}
@Override
public void removedService(ServiceReference<Repository> reference, Repository service) {
super.removedService(reference, service);
- homeRepository = null;
+ egoRepository = null;
}
}.open();
@Override
public void createWorkgroup(LdapName dn) {
- if (homeRepository == null)
- throw new CmsException("Home repository is not available");
+ if (egoRepository == null)
+ throw new CmsException("Ego repository is not available");
// TODO add check that the group exists
- homeRepository.createWorkgroup(dn);
+ egoRepository.createWorkgroup(dn);
}
}
--- /dev/null
+package org.argeo.cms.internal.kernel;
+
+import java.security.PrivilegedAction;
+import java.text.SimpleDateFormat;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.security.Privilege;
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+
+import org.argeo.cms.CmsException;
+import org.argeo.jcr.JcrRepositoryWrapper;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeConstants;
+import org.argeo.node.NodeUtils;
+
+/**
+ * Make sure each user has a home directory available.
+ */
+class EgoRepository extends JcrRepositoryWrapper implements KernelConstants {
+
+ /** The home base path. */
+// private String homeBasePath = KernelConstants.DEFAULT_HOME_BASE_PATH;
+// private String usersBasePath = KernelConstants.DEFAULT_USERS_BASE_PATH;
+// private String groupsBasePath = KernelConstants.DEFAULT_GROUPS_BASE_PATH;
+
+ private Set<String> checkedUsers = new HashSet<String>();
+
+ private SimpleDateFormat usersDatePath = new SimpleDateFormat("YYYY/MM");
+
+ private String defaultHomeWorkspace = NodeConstants.HOME;
+ private String defaultGroupsWorkspace = NodeConstants.SRV;
+// private String defaultGuestsWorkspace = NodeConstants.GUESTS;
+ private final boolean remote;
+
+ public EgoRepository(Repository repository, boolean remote) {
+ super(repository);
+ this.remote = remote;
+ putDescriptor(NodeConstants.CN, NodeConstants.EGO);
+ if (!remote) {
+ LoginContext lc;
+ try {
+ lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_DATA_ADMIN);
+ lc.login();
+ } catch (javax.security.auth.login.LoginException e1) {
+ throw new CmsException("Cannot login as systrem", e1);
+ }
+ Subject.doAs(lc.getSubject(), new PrivilegedAction<Void>() {
+
+ @Override
+ public Void run() {
+ loginOrCreateWorkspace(defaultHomeWorkspace);
+ loginOrCreateWorkspace(defaultGroupsWorkspace);
+ return null;
+ }
+
+ });
+ }
+ }
+
+ private void loginOrCreateWorkspace(String workspace) {
+ Session adminSession = null;
+ try {
+ adminSession = JcrUtils.loginOrCreateWorkspace(getRepository(workspace), workspace);
+// JcrUtils.addPrivilege(adminSession, "/", NodeConstants.ROLE_USER, Privilege.JCR_READ);
+
+// initJcr(adminSession);
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot init JCR home", e);
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+ }
+
+// @Override
+// public Session login(Credentials credentials, String workspaceName)
+// throws LoginException, NoSuchWorkspaceException, RepositoryException {
+// if (workspaceName == null) {
+// return super.login(credentials, getUserHomeWorkspace());
+// } else {
+// return super.login(credentials, workspaceName);
+// }
+// }
+
+ protected String getUserHomeWorkspace() {
+ // TODO base on JAAS Subject metadata
+ return defaultHomeWorkspace;
+ }
+
+ protected String getGroupsWorkspace() {
+ // TODO base on JAAS Subject metadata
+ return defaultGroupsWorkspace;
+ }
+
+// protected String getGuestsWorkspace() {
+// // TODO base on JAAS Subject metadata
+// return defaultGuestsWorkspace;
+// }
+
+ @Override
+ protected void processNewSession(Session session, String workspaceName) {
+ String username = session.getUserID();
+ if (username == null || username.toString().equals(""))
+ return;
+ if (session.getUserID().equals(NodeConstants.ROLE_ANONYMOUS))
+ return;
+
+ String userHomeWorkspace = getUserHomeWorkspace();
+ if (workspaceName == null || !workspaceName.equals(userHomeWorkspace))
+ return;
+
+ if (checkedUsers.contains(username))
+ return;
+ Session adminSession = KernelUtils.openAdminSession(getRepository(workspaceName), workspaceName);
+ try {
+ syncJcr(adminSession, username);
+ checkedUsers.add(username);
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+ }
+
+ /*
+ * JCR
+ */
+ /** Session is logged out. */
+ private void initJcr(Session adminSession) {
+ try {
+// JcrUtils.mkdirs(adminSession, homeBasePath);
+// JcrUtils.mkdirs(adminSession, groupsBasePath);
+ adminSession.save();
+
+// JcrUtils.addPrivilege(adminSession, homeBasePath, NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_READ);
+// JcrUtils.addPrivilege(adminSession, groupsBasePath, NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_READ);
+ adminSession.save();
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot initialize home repository", e);
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+ }
+
+ protected synchronized void syncJcr(Session adminSession, String username) {
+ // only in the default workspace
+// if (workspaceName != null)
+// return;
+ // skip system users
+ if (username.endsWith(NodeConstants.ROLES_BASEDN))
+ return;
+
+ try {
+ Node userHome = NodeUtils.getUserHome(adminSession, username);
+ if (userHome == null) {
+// String homePath = generateUserPath(username);
+ String userId = extractUserId(username);
+// if (adminSession.itemExists(homePath))// duplicate user id
+// userHome = adminSession.getNode(homePath).getParent().addNode(JcrUtils.lastPathElement(homePath));
+// else
+// userHome = JcrUtils.mkdirs(adminSession, homePath);
+ userHome = adminSession.getRootNode().addNode(userId);
+// userHome.addMixin(NodeTypes.NODE_USER_HOME);
+ userHome.addMixin(NodeType.MIX_CREATED);
+ userHome.addMixin(NodeType.MIX_TITLE);
+ userHome.setProperty(Property.JCR_ID, username);
+ // TODO use display name
+ userHome.setProperty(Property.JCR_TITLE, userId);
+// userHome.setProperty(NodeNames.LDAP_UID, username);
+ adminSession.save();
+
+ JcrUtils.clearAccessControList(adminSession, userHome.getPath(), username);
+ JcrUtils.addPrivilege(adminSession, userHome.getPath(), username, Privilege.JCR_ALL);
+// JackrabbitSecurityUtils.denyPrivilege(adminSession, userHome.getPath(), NodeConstants.ROLE_USER,
+// Privilege.JCR_READ);
+ }
+ if (adminSession.hasPendingChanges())
+ adminSession.save();
+ } catch (RepositoryException e) {
+ JcrUtils.discardQuietly(adminSession);
+ throw new CmsException("Cannot sync node security model for " + username, e);
+ }
+ }
+
+ /** Generate path for a new user home */
+ private String generateUserPath(String username) {
+ LdapName dn;
+ try {
+ dn = new LdapName(username);
+ } catch (InvalidNameException e) {
+ throw new CmsException("Invalid name " + username, e);
+ }
+ String userId = dn.getRdn(dn.size() - 1).getValue().toString();
+ return '/' + userId;
+// int atIndex = userId.indexOf('@');
+// if (atIndex < 0) {
+// return homeBasePath+'/' + userId;
+// } else {
+// return usersBasePath + '/' + usersDatePath.format(new Date()) + '/' + userId;
+// }
+ }
+
+ private String extractUserId(String username) {
+ LdapName dn;
+ try {
+ dn = new LdapName(username);
+ } catch (InvalidNameException e) {
+ throw new CmsException("Invalid name " + username, e);
+ }
+ String userId = dn.getRdn(dn.size() - 1).getValue().toString();
+ return userId;
+// int atIndex = userId.indexOf('@');
+// if (atIndex < 0) {
+// return homeBasePath+'/' + userId;
+// } else {
+// return usersBasePath + '/' + usersDatePath.format(new Date()) + '/' + userId;
+// }
+ }
+
+ public void createWorkgroup(LdapName dn) {
+ String groupsWorkspace = getGroupsWorkspace();
+ Session adminSession = KernelUtils.openAdminSession(getRepository(groupsWorkspace), groupsWorkspace);
+ String cn = dn.getRdn(dn.size() - 1).getValue().toString();
+ Node newWorkgroup = NodeUtils.getGroupHome(adminSession, cn);
+ if (newWorkgroup != null) {
+ JcrUtils.logoutQuietly(adminSession);
+ throw new CmsException("Workgroup " + newWorkgroup + " already exists for " + dn);
+ }
+ try {
+ // TODO enhance transformation of cn to a valid node name
+ // String relPath = cn.replaceAll("[^a-zA-Z0-9]", "_");
+ String relPath = JcrUtils.replaceInvalidChars(cn);
+ newWorkgroup = adminSession.getRootNode().addNode(relPath, NodeType.NT_UNSTRUCTURED);
+// newWorkgroup = JcrUtils.mkdirs(adminSession.getNode(groupsBasePath), relPath, NodeType.NT_UNSTRUCTURED);
+// newWorkgroup.addMixin(NodeTypes.NODE_GROUP_HOME);
+ newWorkgroup.addMixin(NodeType.MIX_CREATED);
+ newWorkgroup.addMixin(NodeType.MIX_TITLE);
+ newWorkgroup.setProperty(Property.JCR_ID, dn.toString());
+ newWorkgroup.setProperty(Property.JCR_TITLE, cn);
+// newWorkgroup.setProperty(NodeNames.LDAP_CN, cn);
+ adminSession.save();
+ JcrUtils.addPrivilege(adminSession, newWorkgroup.getPath(), dn.toString(), Privilege.JCR_ALL);
+ adminSession.save();
+ } catch (RepositoryException e) {
+ throw new CmsException("Cannot create workgroup", e);
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+
+ }
+
+ public boolean isRemote() {
+ return remote;
+ }
+
+}
+++ /dev/null
-package org.argeo.cms.internal.kernel;
-
-import java.security.PrivilegedAction;
-import java.text.SimpleDateFormat;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.jcr.Credentials;
-import javax.jcr.LoginException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.security.Privilege;
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import javax.security.auth.Subject;
-import javax.security.auth.login.LoginContext;
-
-import org.argeo.cms.CmsException;
-import org.argeo.jcr.JcrRepositoryWrapper;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.node.NodeConstants;
-import org.argeo.node.NodeUtils;
-
-/**
- * Make sure each user has a home directory available in the default workspace.
- */
-class HomeRepository extends JcrRepositoryWrapper implements KernelConstants {
-
- /** The home base path. */
-// private String homeBasePath = KernelConstants.DEFAULT_HOME_BASE_PATH;
-// private String usersBasePath = KernelConstants.DEFAULT_USERS_BASE_PATH;
-// private String groupsBasePath = KernelConstants.DEFAULT_GROUPS_BASE_PATH;
-
- private Set<String> checkedUsers = new HashSet<String>();
-
- private SimpleDateFormat usersDatePath = new SimpleDateFormat("YYYY/MM");
-
- private String defaultHomeWorkspace = NodeConstants.HOME;
- private String defaultGroupsWorkspace = NodeConstants.SRV;
-// private String defaultGuestsWorkspace = NodeConstants.GUESTS;
- private final boolean remote;
-
- public HomeRepository(Repository repository, boolean remote) {
- super(repository);
- this.remote = remote;
- putDescriptor(NodeConstants.CN, NodeConstants.HOME);
- if (!remote) {
- LoginContext lc;
- try {
- lc = new LoginContext(NodeConstants.LOGIN_CONTEXT_DATA_ADMIN);
- lc.login();
- } catch (javax.security.auth.login.LoginException e1) {
- throw new CmsException("Cannot login as systrem", e1);
- }
- Subject.doAs(lc.getSubject(), new PrivilegedAction<Void>() {
-
- @Override
- public Void run() {
- loginOrCreateWorkspace(defaultHomeWorkspace);
- loginOrCreateWorkspace(defaultGroupsWorkspace);
- return null;
- }
-
- });
- }
- }
-
- private void loginOrCreateWorkspace(String workspace) {
- Session adminSession = null;
- try {
- adminSession = JcrUtils.loginOrCreateWorkspace(getRepository(workspace), workspace);
-// JcrUtils.addPrivilege(adminSession, "/", NodeConstants.ROLE_USER, Privilege.JCR_READ);
-
-// initJcr(adminSession);
- } catch (RepositoryException e) {
- throw new CmsException("Cannot init JCR home", e);
- } finally {
- JcrUtils.logoutQuietly(adminSession);
- }
- }
-
-// @Override
-// public Session login(Credentials credentials, String workspaceName)
-// throws LoginException, NoSuchWorkspaceException, RepositoryException {
-// if (workspaceName == null) {
-// return super.login(credentials, getUserHomeWorkspace());
-// } else {
-// return super.login(credentials, workspaceName);
-// }
-// }
-
- protected String getUserHomeWorkspace() {
- // TODO base on JAAS Subject metadata
- return defaultHomeWorkspace;
- }
-
- protected String getGroupsWorkspace() {
- // TODO base on JAAS Subject metadata
- return defaultGroupsWorkspace;
- }
-
-// protected String getGuestsWorkspace() {
-// // TODO base on JAAS Subject metadata
-// return defaultGuestsWorkspace;
-// }
-
- @Override
- protected void processNewSession(Session session, String workspaceName) {
- String username = session.getUserID();
- if (username == null || username.toString().equals(""))
- return;
- if (session.getUserID().equals(NodeConstants.ROLE_ANONYMOUS))
- return;
-
- String userHomeWorkspace = getUserHomeWorkspace();
- if (workspaceName == null || !workspaceName.equals(userHomeWorkspace))
- return;
-
- if (checkedUsers.contains(username))
- return;
- Session adminSession = KernelUtils.openAdminSession(getRepository(workspaceName), workspaceName);
- try {
- syncJcr(adminSession, username);
- checkedUsers.add(username);
- } finally {
- JcrUtils.logoutQuietly(adminSession);
- }
- }
-
- /*
- * JCR
- */
- /** Session is logged out. */
- private void initJcr(Session adminSession) {
- try {
-// JcrUtils.mkdirs(adminSession, homeBasePath);
-// JcrUtils.mkdirs(adminSession, groupsBasePath);
- adminSession.save();
-
-// JcrUtils.addPrivilege(adminSession, homeBasePath, NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_READ);
-// JcrUtils.addPrivilege(adminSession, groupsBasePath, NodeConstants.ROLE_USER_ADMIN, Privilege.JCR_READ);
- adminSession.save();
- } catch (RepositoryException e) {
- throw new CmsException("Cannot initialize home repository", e);
- } finally {
- JcrUtils.logoutQuietly(adminSession);
- }
- }
-
- protected synchronized void syncJcr(Session adminSession, String username) {
- // only in the default workspace
-// if (workspaceName != null)
-// return;
- // skip system users
- if (username.endsWith(NodeConstants.ROLES_BASEDN))
- return;
-
- try {
- Node userHome = NodeUtils.getUserHome(adminSession, username);
- if (userHome == null) {
-// String homePath = generateUserPath(username);
- String userId = extractUserId(username);
-// if (adminSession.itemExists(homePath))// duplicate user id
-// userHome = adminSession.getNode(homePath).getParent().addNode(JcrUtils.lastPathElement(homePath));
-// else
-// userHome = JcrUtils.mkdirs(adminSession, homePath);
- userHome = adminSession.getRootNode().addNode(userId);
-// userHome.addMixin(NodeTypes.NODE_USER_HOME);
- userHome.addMixin(NodeType.MIX_CREATED);
- userHome.addMixin(NodeType.MIX_TITLE);
- userHome.setProperty(Property.JCR_ID, username);
- // TODO use display name
- userHome.setProperty(Property.JCR_TITLE, userId);
-// userHome.setProperty(NodeNames.LDAP_UID, username);
- adminSession.save();
-
- JcrUtils.clearAccessControList(adminSession, userHome.getPath(), username);
- JcrUtils.addPrivilege(adminSession, userHome.getPath(), username, Privilege.JCR_ALL);
-// JackrabbitSecurityUtils.denyPrivilege(adminSession, userHome.getPath(), NodeConstants.ROLE_USER,
-// Privilege.JCR_READ);
- }
- if (adminSession.hasPendingChanges())
- adminSession.save();
- } catch (RepositoryException e) {
- JcrUtils.discardQuietly(adminSession);
- throw new CmsException("Cannot sync node security model for " + username, e);
- }
- }
-
- /** Generate path for a new user home */
- private String generateUserPath(String username) {
- LdapName dn;
- try {
- dn = new LdapName(username);
- } catch (InvalidNameException e) {
- throw new CmsException("Invalid name " + username, e);
- }
- String userId = dn.getRdn(dn.size() - 1).getValue().toString();
- return '/' + userId;
-// int atIndex = userId.indexOf('@');
-// if (atIndex < 0) {
-// return homeBasePath+'/' + userId;
-// } else {
-// return usersBasePath + '/' + usersDatePath.format(new Date()) + '/' + userId;
-// }
- }
-
- private String extractUserId(String username) {
- LdapName dn;
- try {
- dn = new LdapName(username);
- } catch (InvalidNameException e) {
- throw new CmsException("Invalid name " + username, e);
- }
- String userId = dn.getRdn(dn.size() - 1).getValue().toString();
- return userId;
-// int atIndex = userId.indexOf('@');
-// if (atIndex < 0) {
-// return homeBasePath+'/' + userId;
-// } else {
-// return usersBasePath + '/' + usersDatePath.format(new Date()) + '/' + userId;
-// }
- }
-
- public void createWorkgroup(LdapName dn) {
- String groupsWorkspace = getGroupsWorkspace();
- Session adminSession = KernelUtils.openAdminSession(getRepository(groupsWorkspace), groupsWorkspace);
- String cn = dn.getRdn(dn.size() - 1).getValue().toString();
- Node newWorkgroup = NodeUtils.getGroupHome(adminSession, cn);
- if (newWorkgroup != null) {
- JcrUtils.logoutQuietly(adminSession);
- throw new CmsException("Workgroup " + newWorkgroup + " already exists for " + dn);
- }
- try {
- // TODO enhance transformation of cn to a valid node name
- // String relPath = cn.replaceAll("[^a-zA-Z0-9]", "_");
- String relPath = JcrUtils.replaceInvalidChars(cn);
- newWorkgroup = adminSession.getRootNode().addNode(relPath, NodeType.NT_UNSTRUCTURED);
-// newWorkgroup = JcrUtils.mkdirs(adminSession.getNode(groupsBasePath), relPath, NodeType.NT_UNSTRUCTURED);
-// newWorkgroup.addMixin(NodeTypes.NODE_GROUP_HOME);
- newWorkgroup.addMixin(NodeType.MIX_CREATED);
- newWorkgroup.addMixin(NodeType.MIX_TITLE);
- newWorkgroup.setProperty(Property.JCR_ID, dn.toString());
- newWorkgroup.setProperty(Property.JCR_TITLE, cn);
-// newWorkgroup.setProperty(NodeNames.LDAP_CN, cn);
- adminSession.save();
- JcrUtils.addPrivilege(adminSession, newWorkgroup.getPath(), dn.toString(), Privilege.JCR_ALL);
- adminSession.save();
- } catch (RepositoryException e) {
- throw new CmsException("Cannot create workgroup", e);
- } finally {
- JcrUtils.logoutQuietly(adminSession);
- }
-
- }
-
- public boolean isRemote() {
- return remote;
- }
-
-}
}
static Dictionary<String, Object> getRepositoryConfig(String dataModelName, Dictionary<String, Object> provided) {
- if (dataModelName.equals(NodeConstants.NODE) || dataModelName.equals(NodeConstants.HOME))
+ if (dataModelName.equals(NodeConstants.NODE) || dataModelName.equals(NodeConstants.EGO))
throw new IllegalArgumentException("Data model '" + dataModelName + "' is reserved.");
Dictionary<String, Object> props = provided != null ? provided : new Hashtable<String, Object>();
for (RepoConf repoConf : RepoConf.values()) {
try {
registerWebdavServlet(httpService, alias, repository);
registerRemotingServlet(httpService, alias, repository);
- if (NodeConstants.HOME.equals(alias))
+ if (NodeConstants.EGO.equals(alias))
registerFilesServlet(httpService, alias, repository);
if (log.isTraceEnabled())
log.trace("Registered servlets for repository '" + alias + "'");
try {
httpService.unregister(webdavPath(alias));
httpService.unregister(remotingPath(alias));
- if (NodeConstants.HOME.equals(alias))
+ if (NodeConstants.EGO.equals(alias))
httpService.unregister(filesPath(alias));
if (log.isTraceEnabled())
log.trace("Unregistered servlets for repository '" + alias + "'");
bc.registerService(Repository.class, repository, props);
// home
- // TODO make a sperate home configurable
if (cn.equals(NodeConstants.NODE)) {
- Dictionary<String, Object> homeProps = LangUtils.dico(NodeConstants.CN, NodeConstants.HOME);
- HomeRepository homeRepository = new HomeRepository(repository, true);
+ Dictionary<String, Object> homeProps = LangUtils.dico(NodeConstants.CN, NodeConstants.EGO);
+ EgoRepository homeRepository = new EgoRepository(repository, true);
bc.registerService(Repository.class, homeRepository, homeProps);
}
} catch (Exception e) {
Path rootPath = fsProvider.getPath(new URI("jcr+memory:/"));
log.debug("Got root " + rootPath);
+ Path testDir = rootPath.resolve("testDir");
+ Files.createDirectory(testDir);
Path testMount = fsProvider.getPath(new URI("jcr+memory:/test"));
log.debug("Test path");
log.debug("Created " + testPath + " (" + ft + ")");
Files.delete(testPath);
log.debug("Deleted " + testPath);
+
+ // Browse directories from root
+ DirectoryStream<Path> files = Files.newDirectoryStream(rootPath);
+ int directoryCount = 0;
+ for (Path file : files) {
+ if (Files.isDirectory(file)) {
+ directoryCount++;
+ }
+ }
+ assertEquals(2, directoryCount);
+
+ // Browse directories from mount
+ Path mountSubDir = testMount.resolve("mountSubDir");
+ Files.createDirectory(mountSubDir);
+ Path otherSubDir = testMount.resolve("otherSubDir");
+ Files.createDirectory(otherSubDir);
+ testPath = testMount.resolve("test.txt");
+ Files.createFile(testPath);
+ files = Files.newDirectoryStream(testMount);
+ int fileCount = 0;
+ for (Path file : files) {
+ fileCount++;
+ }
+ assertEquals(3, fileCount);
+
}
public void testSimple() throws Exception {
}
return tryGetRepo(repositoryFactory, nextUri, nextWorkspace);
} else {
- JcrFileSystem fileSystem = new JcrFileSystem(this, session);
+ JcrFileSystem fileSystem = new JcrFileSystem(this, repository);
fileSystems.put(repoUri.toString() + "/" + workspace, fileSystem);
return fileSystem;
}
+++ /dev/null
-package org.argeo.jcr.fs;
-
-import java.io.IOException;
-import java.nio.file.FileStore;
-import java.nio.file.attribute.FileAttributeView;
-import java.nio.file.attribute.FileStoreAttributeView;
-
-public class JcrFileStore extends FileStore {
-
- @Override
- public String name() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String type() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isReadOnly() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public long getTotalSpace() throws IOException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public long getUsableSpace() throws IOException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public long getUnallocatedSpace() throws IOException {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public boolean supportsFileAttributeView(
- Class<? extends FileAttributeView> type) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean supportsFileAttributeView(String name) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public <V extends FileStoreAttributeView> V getFileStoreAttributeView(
- Class<V> type) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Object getAttribute(String attribute) throws IOException {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
import java.nio.file.spi.FileSystemProvider;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
+import org.argeo.jcr.Jcr;
import org.argeo.jcr.JcrUtils;
public class JcrFileSystem extends FileSystem {
private final JcrFileSystemProvider provider;
- private final Session session;
+ private final Repository repository;
+ private Session session;
private WorkspaceFileStore baseFileStore;
private Map<String, WorkspaceFileStore> mounts = new TreeMap<>();
this.provider = provider;
baseFileStore = new WorkspaceFileStore(null, session.getWorkspace());
this.session = session;
- Node userHome = provider.getUserHome(session);
- if (userHome != null)
- try {
- userHomePath = userHome.getPath();
- } catch (RepositoryException e) {
- throw new IOException("Cannot retrieve user home path", e);
- }
+// Node userHome = provider.getUserHome(session);
+// if (userHome != null)
+// try {
+// userHomePath = userHome.getPath();
+// } catch (RepositoryException e) {
+// throw new IOException("Cannot retrieve user home path", e);
+// }
+ this.repository = null;
}
public JcrFileSystem(JcrFileSystemProvider provider, Repository repository) throws IOException {
throws IOException {
super();
this.provider = provider;
+ this.repository = repository;
try {
this.session = credentials == null ? repository.login() : repository.login(credentials);
baseFileStore = new WorkspaceFileStore(null, session.getWorkspace());
workspaces: for (String workspaceName : baseFileStore.getWorkspace().getAccessibleWorkspaceNames()) {
if (workspaceName.equals(baseFileStore.getWorkspace().getName()))
continue workspaces;// do not mount base
+ if (workspaceName.equals("security")) {
+ continue workspaces;// do not mount security workspace
+ // TODO make it configurable
+ }
Session mountSession = credentials == null ? repository.login(workspaceName)
: repository.login(credentials, workspaceName);
String mountPath = JcrPath.separator + workspaceName;
throw new IOException("Cannot initialise file system", e);
}
- Node userHome = provider.getUserHome(session);
+ Node userHome = provider.getUserHome(repository);
if (userHome != null)
try {
- userHomePath = userHome.getPath();
+ userHomePath = toFsPath(userHome);
} catch (RepositoryException e) {
throw new IOException("Cannot retrieve user home path", e);
+ } finally {
+ JcrUtils.logoutQuietly(Jcr.session(userHome));
}
}
+ public String toFsPath(Node node) throws RepositoryException {
+ return getFileStore(node).toFsPath(node);
+ }
+
/** Whether this node should be skipped in directory listings */
public boolean skipNode(Node node) throws RepositoryException {
if (node.isNodeType(NodeType.NT_HIERARCHY_NODE))
public WorkspaceFileStore getFileStore(String path) {
WorkspaceFileStore res = baseFileStore;
for (String mountPath : mounts.keySet()) {
- if (path.startsWith(mountPath)) {
+ if (path.equals(mountPath))
+ return mounts.get(mountPath);
+ if (path.startsWith(mountPath + JcrPath.separator)) {
res = mounts.get(mountPath);
// we keep the last one
}
throw new IllegalStateException("No workspace mount found for " + node + " in workspace " + workspaceName);
}
+ public Iterator<JcrPath> listDirectMounts(Path base) {
+ String baseStr = base.toString();
+ Set<JcrPath> res = new HashSet<>();
+ mounts: for (String mountPath : mounts.keySet()) {
+ if (mountPath.equals(baseStr))
+ continue mounts;
+ if (mountPath.startsWith(baseStr)) {
+ JcrPath path = new JcrPath(this, mountPath);
+ Path relPath = base.relativize(path);
+ if (relPath.getNameCount() == 1)
+ res.add(path);
+ }
+ }
+ return res.iterator();
+ }
+
public WorkspaceFileStore getBaseFileStore() {
return baseFileStore;
}
throw new UnsupportedOperationException();
}
- public Session getSession() {
- return session;
+// public Session getSession() {
+// return session;
+// }
+
+ public Repository getRepository() {
+ return repository;
}
}
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.PropertyType;
+import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
Node base = toNode(dir);
if (base == null)
throw new IOException(dir + " is not a JCR node");
- return new NodeDirectoryStream((JcrFileSystem) dir.getFileSystem(), base.getNodes(), filter);
+ JcrFileSystem fileSystem = (JcrFileSystem) dir.getFileSystem();
+ return new NodeDirectoryStream(fileSystem, base.getNodes(), fileSystem.listDirectMounts(dir), filter);
} catch (RepositoryException e) {
throw new IOException("Cannot list directory", e);
}
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
- try {
- Session session = ((JcrFileSystem) path.getFileSystem()).getSession();
- if (!session.itemExists(path.toString()))
- throw new NoSuchFileException(path + " does not exist");
- // TODO check access via JCR api
- } catch (RepositoryException e) {
- throw new IOException("Cannot delete " + path, e);
- }
+ Node node = toNode(path);
+ if (node == null)
+ throw new NoSuchFileException(path + " does not exist");
+ // TODO check access via JCR api
}
@Override
*
* @return null by default
*/
- public Node getUserHome(Session session) {
+ public Node getUserHome(Repository session) {
return null;
}
public class NodeDirectoryStream implements DirectoryStream<Path> {
private final JcrFileSystem fs;
private final NodeIterator nodeIterator;
+ private final Iterator<JcrPath> additionalPaths;
private final Filter<? super Path> filter;
- public NodeDirectoryStream(JcrFileSystem fs, NodeIterator nodeIterator, Filter<? super Path> filter) {
+ public NodeDirectoryStream(JcrFileSystem fs, NodeIterator nodeIterator, Iterator<JcrPath> additionalPaths,
+ Filter<? super Path> filter) {
this.fs = fs;
this.nodeIterator = nodeIterator;
+ this.additionalPaths = additionalPaths;
this.filter = filter;
}
throw new JcrFsException("Could not get next path", e);
}
}
+
+ if (next == null) {
+ if (additionalPaths.hasNext())
+ next = additionalPaths.next();
+ }
+
return next != null;
}
+++ /dev/null
-package org.argeo.jcr.fs;
-
-import java.io.IOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystemAlreadyExistsException;
-import java.nio.file.Path;
-import java.util.Map;
-
-import javax.jcr.Session;
-
-/** An FS provider based on a single JCR session (experimental). */
-public class SessionFsProvider extends JcrFileSystemProvider {
- private Session session;
- private JcrFileSystem fileSystem;
-
- public SessionFsProvider(Session session) {
- this.session = session;
- }
-
- @Override
- public String getScheme() {
- return "jcr+session";
- }
-
- @Override
- public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
- if (fileSystem != null && fileSystem.isOpen())
- throw new FileSystemAlreadyExistsException();
- fileSystem = new JcrFileSystem(this, session) {
- boolean open;
-
- @Override
- public void close() throws IOException {
- // prevent the session logout
- open = false;
- }
-
- @Override
- public boolean isOpen() {
- return open;
- }
-
- };
- return fileSystem;
- }
-
- @Override
- public FileSystem getFileSystem(URI uri) {
- return fileSystem;
- }
-
- @Override
- public Path getPath(URI uri) {
- return new JcrPath(fileSystem, uri.getPath());
- }
-
-}
* COMMON NAMES
*/
String NODE = "node";
+ String EGO = "ego";
String HOME = "home";
- String SRV = "groups";
+ String SRV = "srv";
String GUESTS = "guests";
String PUBLIC = "public";