private boolean hasPermissionOnExternalPath( PathSupplier pathSupplier, String... actions ) throws RepositoryException { Connectors connectors = this.repository().runningState().connectors(); if (!connectors.hasConnectors() || !connectors.hasReadonlyConnectors()) { // federation is not enabled or there are no readonly connectors return true; } Path path = pathSupplier.getAbsolutePath(); if (path == null) return false; if (connectors.isReadonlyPath(path, this)) { // this is a readonly external path, so we need to see what the actual actions are if (actions.length > ModeShapePermissions.READONLY_EXTERNAL_PATH_PERMISSIONS.size()) { return false; } List<String> actionsList = new ArrayList<String>(Arrays.asList(actions)); for (Iterator<String> actionsIterator = actionsList.iterator(); actionsIterator.hasNext();) { String action = actionsIterator.next(); if (!ModeShapePermissions.READONLY_EXTERNAL_PATH_PERMISSIONS.contains(action)) { return false; } actionsIterator.remove(); } return actionsList.isEmpty(); } return true; }
private boolean hasPermissionOnExternalPath( PathSupplier pathSupplier, String... actions ) throws RepositoryException { Connectors connectors = this.repository().runningState().connectors(); if (!connectors.hasConnectors() || !connectors.hasReadonlyConnectors()) { // federation is not enabled or there are no readonly connectors return true; } Path path = pathSupplier.getAbsolutePath(); if (path == null) return false; if (connectors.isReadonlyPath(path, this)) { // this is a readonly external path, so we need to see what the actual actions are if (actions.length > ModeShapePermissions.READONLY_EXTERNAL_PATH_PERMISSIONS.size()) { return false; } List<String> actionsList = new ArrayList<String>(Arrays.asList(actions)); for (Iterator<String> actionsIterator = actionsList.iterator(); actionsIterator.hasNext();) { String action = actionsIterator.next(); if (!ModeShapePermissions.READONLY_EXTERNAL_PATH_PERMISSIONS.contains(action)) { return false; } actionsIterator.remove(); } return actionsList.isEmpty(); } return true; }
@Before @Override public void beforeEach() throws Exception { // And make sure that the 'generated-surefire' directory exists (it often doesn't when running in Eclipse) // and create an empty 'tmp' directory underneath it ... new File("target/generated-surefire/tmp").mkdirs(); // Now start the repository ... startRepositoryWithConfigurationFrom("config/repo-config-filesystem-federation-with-persistence.json"); printMessage("Started repository..."); connectors = repository().runningState().connectors(); }
sourceSession.cache(), repository().systemWorkspaceKey(), repository().runningState().connectors());
sourceSession.cache(), repository().systemWorkspaceKey(), repository().runningState().connectors());
Connectors connectors = repository().runningState().connectors(); if (sourceContainsExternalNodes && !targetIsExternal) { String sourceName = connectors.getSourceNameAtKey(externalSourceKey);
Connectors connectors = repository().runningState().connectors(); if (sourceContainsExternalNodes && !targetIsExternal) { String sourceName = connectors.getSourceNameAtKey(externalSourceKey);
protected void deepClone( JcrSession sourceSession, NodeKey sourceNodeKey, JcrSession cloneSession, NodeKey cloneNodeKey ) throws RepositoryException { assert !cloneSession.cache().isReadOnly(); SessionCache sourceCache = sourceSession.cache(); CachedNode sourceNode = sourceCache.getNode(sourceNodeKey); SessionCache cloneCache = cloneSession.cache(); MutableCachedNode mutableCloneNode = cloneSession.node(cloneNodeKey, null).mutable(); /** * Perform the clone at the cache level - clone all properties & children */ mutableCloneNode.deepClone(cloneCache, sourceNode, sourceCache, repository().systemWorkspaceKey(), repository().runningState().connectors()); /** * Make sure the version history is preserved */ cloneSession.initBaseVersionKeys(); Set<NodeKey> sourceKeys = sourceCache.getNodeKeysAtAndBelow(sourceNodeKey); for (NodeKey sourceKey : sourceKeys) { AbstractJcrNode srcNode = sourceSession.node(sourceKey, null); if (srcNode.isNodeType(JcrMixLexicon.VERSIONABLE)) { // Preserve the base version of the versionable nodes (this will in turn preserve the version history) cloneSession.setDesiredBaseVersionKey(sourceKey, srcNode.getBaseVersion().key()); } } cloneSession.save(); }
protected void deepClone( JcrSession sourceSession, NodeKey sourceNodeKey, JcrSession cloneSession, NodeKey cloneNodeKey ) throws RepositoryException { assert !cloneSession.cache().isReadOnly(); SessionCache sourceCache = sourceSession.cache(); CachedNode sourceNode = sourceCache.getNode(sourceNodeKey); SessionCache cloneCache = cloneSession.cache(); MutableCachedNode mutableCloneNode = cloneSession.node(cloneNodeKey, null).mutable(); /** * Perform the clone at the cache level - clone all properties & children */ mutableCloneNode.deepClone(cloneCache, sourceNode, sourceCache, repository().systemWorkspaceKey(), repository().runningState().connectors()); /** * Make sure the version history is preserved */ cloneSession.initBaseVersionKeys(); Set<NodeKey> sourceKeys = sourceCache.getNodeKeysAtAndBelow(sourceNodeKey); for (NodeKey sourceKey : sourceKeys) { AbstractJcrNode srcNode = sourceSession.node(sourceKey, null); if (srcNode.isNodeType(JcrMixLexicon.VERSIONABLE)) { // Preserve the base version of the versionable nodes (this will in turn preserve the version history) cloneSession.setDesiredBaseVersionKey(sourceKey, srcNode.getBaseVersion().key()); } } cloneSession.save(); }
private void validateCopyForExternalNode( AbstractJcrNode sourceNode, AbstractJcrNode destParentNode ) throws RepositoryException { String rootSourceKey = session.getRootNode().key().getSourceKey(); NodeKey parentKey = destParentNode.key(); if (parentKey.getSourceKey().equalsIgnoreCase(rootSourceKey)) { return; } String destExternalKey = parentKey.getSourceKey(); Connectors connectors = repository().runningState().connectors(); String destSourceName = connectors.getSourceNameAtKey(destExternalKey); Set<NodeKey> sourceKeys = session.cache().getNodeKeysAtAndBelow(sourceNode.key()); boolean sourceContainsExternalNodes = false; for (NodeKey sourceKey : sourceKeys) { String sourceNodeSourceKey = sourceKey.getSourceKey(); if (!rootSourceKey.equalsIgnoreCase(sourceNodeSourceKey)) { sourceContainsExternalNodes = true; if (!sourceNodeSourceKey.equalsIgnoreCase(destExternalKey)) { String sourceExternalSourceName = connectors.getSourceNameAtKey(sourceNodeSourceKey); throw new RepositoryException(JcrI18n.unableToCopySourceTargetMismatch.text(sourceExternalSourceName, destSourceName)); } } } String sourceNodeSourceKey = sourceNode.key().getSourceKey(); if (sourceContainsExternalNodes && !sourceNodeSourceKey.equalsIgnoreCase(destExternalKey)) { // the source graph contains external nodes, but the source itself is not an external node throw new RepositoryException(JcrI18n.unableToCopySourceNotExternal.text(sourceNode.path())); } }
private void validateCopyForExternalNode( AbstractJcrNode sourceNode, AbstractJcrNode destParentNode ) throws RepositoryException { String rootSourceKey = session.getRootNode().key().getSourceKey(); NodeKey parentKey = destParentNode.key(); if (parentKey.getSourceKey().equalsIgnoreCase(rootSourceKey)) { return; } String destExternalKey = parentKey.getSourceKey(); Connectors connectors = repository().runningState().connectors(); String destSourceName = connectors.getSourceNameAtKey(destExternalKey); Set<NodeKey> sourceKeys = session.cache().getNodeKeysAtAndBelow(sourceNode.key()); boolean sourceContainsExternalNodes = false; for (NodeKey sourceKey : sourceKeys) { String sourceNodeSourceKey = sourceKey.getSourceKey(); if (!rootSourceKey.equalsIgnoreCase(sourceNodeSourceKey)) { sourceContainsExternalNodes = true; if (!sourceNodeSourceKey.equalsIgnoreCase(destExternalKey)) { String sourceExternalSourceName = connectors.getSourceNameAtKey(sourceNodeSourceKey); throw new RepositoryException(JcrI18n.unableToCopySourceTargetMismatch.text(sourceExternalSourceName, destSourceName)); } } } String sourceNodeSourceKey = sourceNode.key().getSourceKey(); if (sourceContainsExternalNodes && !sourceNodeSourceKey.equalsIgnoreCase(destExternalKey)) { // the source graph contains external nodes, but the source itself is not an external node throw new RepositoryException(JcrI18n.unableToCopySourceNotExternal.text(sourceNode.path())); } }
private void validateCloneForExternalNodes( boolean sameWorkspace, JcrSession sourceSession, AbstractJcrNode sourceNode, AbstractJcrNode parentNode ) throws RepositoryException { String rootSourceKey = sourceSession.getRootNode().key().getSourceKey(); Connectors connectors = repository().runningState().connectors(); Set<NodeKey> sourceKeys = sourceSession.cache().getNodeKeysAtAndBelow(sourceNode.key()); for (NodeKey sourceKey : sourceKeys) { String sourceNodeSourceKey = sourceKey.getSourceKey(); if (!sourceNodeSourceKey.equalsIgnoreCase(rootSourceKey)) { String sourceNameAtKey = connectors.getSourceNameAtKey(sourceNodeSourceKey); if (sameWorkspace) { throw new RepositoryException(JcrI18n.unableToCloneSameWsContainsExternalNode.text(sourceNameAtKey)); } else if (!sourceNode.isRoot() || !parentNode.isRoot()) { throw new RepositoryException(JcrI18n.unableToCloneExternalNodesRequireRoot.text(sourceNameAtKey)); } } } }
private void validateCloneForExternalNodes( boolean sameWorkspace, JcrSession sourceSession, AbstractJcrNode sourceNode, AbstractJcrNode parentNode ) throws RepositoryException { String rootSourceKey = sourceSession.getRootNode().key().getSourceKey(); Connectors connectors = repository().runningState().connectors(); Set<NodeKey> sourceKeys = sourceSession.cache().getNodeKeysAtAndBelow(sourceNode.key()); for (NodeKey sourceKey : sourceKeys) { String sourceNodeSourceKey = sourceKey.getSourceKey(); if (!sourceNodeSourceKey.equalsIgnoreCase(rootSourceKey)) { String sourceNameAtKey = connectors.getSourceNameAtKey(sourceNodeSourceKey); if (sameWorkspace) { throw new RepositoryException(JcrI18n.unableToCloneSameWsContainsExternalNode.text(sourceNameAtKey)); } else if (!sourceNode.isRoot() || !parentNode.isRoot()) { throw new RepositoryException(JcrI18n.unableToCloneExternalNodesRequireRoot.text(sourceNameAtKey)); } } } }