From b209f4c0730fc3a09896781e758bc29dfb1afed8 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Sat, 2 Dec 2006 00:54:41 +0000 Subject: [PATCH] Exported AuthenticationService via RMI. Insecure for now but we can switch over to using SSL when needed. Restructured exports of AVM specific apis to authenticate remotely and pass the ticket with each remote service call. These required some changes to jndi-client and even to the web-client which uses the AVM remote interface within the Alfresco server. Oh, the point of this is that since I'm writing some CLTs, I might as well do them correctly; we'll need the option of security sooner rather than later. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4489 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/avm-clt-context.xml | 20 +- config/alfresco/avm-services-context.xml | 31 +- config/alfresco/public-services-context.xml | 6 +- config/alfresco/remote-avm-test-context.xml | 53 ++- .../java/org/alfresco/repo/avm/AVMRemote.java | 40 +- .../repo/avm/AVMRemoteInputStream.java | 12 +- .../org/alfresco/repo/avm/AVMRemoteLocal.java | 433 +++++++++++++++++ .../repo/avm/AVMRemoteOutputStream.java | 12 +- .../alfresco/repo/avm/AVMRemoteTransport.java | 411 ++++++++++++++++ ...pl.java => AVMRemoteTransportService.java} | 192 +++++--- .../alfresco/repo/avm/AVMSyncServiceImpl.java | 2 +- .../repo/avm/AVMSyncServiceTransportImpl.java | 85 ++++ .../org/alfresco/repo/avm/AVMTestRemote.java | 39 +- .../org/alfresco/repo/avm/clt/AVMCltBase.java | 3 + .../org/alfresco/repo/avm/clt/AVMCopyIn.java | 13 +- .../alfresco/repo/avm/clt/AVMRemoteImpl.java | 439 ++++++++++++++++++ .../repo/avm/clt/AVMSyncServiceClient.java | 73 +++ .../repo/avm/clt/ClientTicketHolder.java | 32 ++ .../cmr/avmsync/AVMSyncServiceTransport.java | 65 +++ 19 files changed, 1790 insertions(+), 171 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/AVMRemoteLocal.java create mode 100644 source/java/org/alfresco/repo/avm/AVMRemoteTransport.java rename source/java/org/alfresco/repo/avm/{AVMRemoteImpl.java => AVMRemoteTransportService.java} (76%) create mode 100644 source/java/org/alfresco/repo/avm/AVMSyncServiceTransportImpl.java create mode 100644 source/java/org/alfresco/repo/avm/clt/AVMRemoteImpl.java create mode 100644 source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java create mode 100644 source/java/org/alfresco/repo/avm/clt/ClientTicketHolder.java create mode 100644 source/java/org/alfresco/service/cmr/avmsync/AVMSyncServiceTransport.java diff --git a/config/alfresco/avm-clt-context.xml b/config/alfresco/avm-clt-context.xml index 5cc4a177c7..22e0b6cea6 100644 --- a/config/alfresco/avm-clt-context.xml +++ b/config/alfresco/avm-clt-context.xml @@ -3,24 +3,36 @@ - + + + + + + + rmi://localhost:1313/avm - org.alfresco.repo.avm.AVMRemote + org.alfresco.repo.avm.AVMRemoteTransport true - + + + + + + + rmi://localhost:1313/avmsync - org.alfresco.service.cmr.avmsync.AVMSyncService + org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport true diff --git a/config/alfresco/avm-services-context.xml b/config/alfresco/avm-services-context.xml index f95862fbc3..750e0b9413 100644 --- a/config/alfresco/avm-services-context.xml +++ b/config/alfresco/avm-services-context.xml @@ -177,9 +177,16 @@ + + + + + + + - ${avm.remote.idlestream.timeout} @@ -187,16 +194,19 @@ + + + - + - org.alfresco.repo.avm.AVMRemote + org.alfresco.repo.avm.AVMRemoteTransport avm @@ -206,12 +216,21 @@ - - + + + + + + + + + + + - org.alfresco.service.cmr.avmsync.AVMSyncService + org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport avmsync diff --git a/config/alfresco/public-services-context.xml b/config/alfresco/public-services-context.xml index 7b47bfab78..25b2581599 100644 --- a/config/alfresco/public-services-context.xml +++ b/config/alfresco/public-services-context.xml @@ -1099,14 +1099,14 @@ - + org.alfresco.service.cmr.avmsync.AVMSyncService - + - + diff --git a/config/alfresco/remote-avm-test-context.xml b/config/alfresco/remote-avm-test-context.xml index a7268b5e4a..6dcf6d6411 100644 --- a/config/alfresco/remote-avm-test-context.xml +++ b/config/alfresco/remote-avm-test-context.xml @@ -3,33 +3,54 @@ "http://www.springframework.org/dtd/spring-beans.dtd"> + + + + rmi://localhost:1313/authentication + + + org.alfresco.service.cmr.security.AuthenticationService + + + true + + - - - + + + + + + + + + rmi://localhost:1313/avm - org.alfresco.repo.avm.AVMRemote + org.alfresco.repo.avm.AVMRemoteTransport true - - - - - rmi://localhost:1313/avmsync - - - org.alfresco.service.cmr.avmsync.AVMSyncService - - - true + + + - + + + + rmi://localhost:1313/avmsync + + + org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport + + + true + + diff --git a/source/java/org/alfresco/repo/avm/AVMRemote.java b/source/java/org/alfresco/repo/avm/AVMRemote.java index bf833c7bfe..5a400616e7 100644 --- a/source/java/org/alfresco/repo/avm/AVMRemote.java +++ b/source/java/org/alfresco/repo/avm/AVMRemote.java @@ -17,6 +17,8 @@ package org.alfresco.repo.avm; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Date; import java.util.List; import java.util.Map; @@ -42,46 +44,14 @@ public interface AVMRemote * @param path The path to the file. * @return A handle. */ - public String getInputHandle(int version, String path); - - /** - * Read a chunk of data from a handle. - * @param handle The opaque input stream handle. - * @param count The number of bytes to try to read. - * @return An array of bytes. 0 length at eof. - */ - public byte[] readInput(String handle, int count); - - /** - * Close an input stream. Server side input streams are - * timer limited, ie, they will be automatically closed - * after a given idle time. However, be nice, and close - * handles when you're done. - * @param handle The opaque handle to the server side stream. - */ - public void closeInputHandle(String handle); + public InputStream getFileInputStream(int version, String path); /** * Get an opaque handle to a server side output stream. * @param path The path to the existing file. * @return An opaque handle. */ - public String getOutputHandle(String path); - - /** - * Write count bytes from buffer buff - * starting at offset offset in buff - * @param handle The opaque handle to the server side output stream. - * @param buff The data buffer. - * @param count The number of bytes to write. - */ - public void writeOutput(String handle, byte [] buff, int count); - - /** - * Close the server side output stream designated by the handle. - * @param handle The handle to the server side output stream. - */ - public void closeOutputHandle(String handle); + public OutputStream getFileOutputStream(String path); /** * Get a listing of a directories direct contents. @@ -123,7 +93,7 @@ public interface AVMRemote * @param name The name of the file to create. * @return An opaque handle to a server side output stream. */ - public String createFile(String path, String name); + public OutputStream createFile(String path, String name); /** * Create a directory. diff --git a/source/java/org/alfresco/repo/avm/AVMRemoteInputStream.java b/source/java/org/alfresco/repo/avm/AVMRemoteInputStream.java index 991d36ab84..c050e950de 100644 --- a/source/java/org/alfresco/repo/avm/AVMRemoteInputStream.java +++ b/source/java/org/alfresco/repo/avm/AVMRemoteInputStream.java @@ -20,6 +20,8 @@ package org.alfresco.repo.avm; import java.io.IOException; import java.io.InputStream; +import org.alfresco.repo.avm.clt.ClientTicketHolder; + /** * Wrapper around AVMRemote stream reading. * @author britt @@ -29,7 +31,7 @@ public class AVMRemoteInputStream extends InputStream /** * The AVMRemote reference. */ - private AVMRemote fAVMRemote; + private AVMRemoteTransport fAVMRemote; /** * The handle to the input stream. @@ -41,7 +43,7 @@ public class AVMRemoteInputStream extends InputStream * @param handle The handle returned by getInputStream(); * @param remote The AVMRemote instance. */ - public AVMRemoteInputStream(String handle, AVMRemote remote) + public AVMRemoteInputStream(String handle, AVMRemoteTransport remote) { fHandle = handle; fAVMRemote = remote; @@ -56,7 +58,7 @@ public class AVMRemoteInputStream extends InputStream { try { - byte [] buff = fAVMRemote.readInput(fHandle, 1); + byte [] buff = fAVMRemote.readInput(ClientTicketHolder.GetTicket(), fHandle, 1); if (buff.length == 0) { return -1; @@ -81,7 +83,7 @@ public class AVMRemoteInputStream extends InputStream { try { - byte [] buff = fAVMRemote.readInput(fHandle, len); + byte [] buff = fAVMRemote.readInput(ClientTicketHolder.GetTicket(), fHandle, len); if (buff.length == 0) { return -1; @@ -103,7 +105,7 @@ public class AVMRemoteInputStream extends InputStream { try { - fAVMRemote.closeInputHandle(fHandle); + fAVMRemote.closeInputHandle(ClientTicketHolder.GetTicket(), fHandle); } catch (Exception e) { diff --git a/source/java/org/alfresco/repo/avm/AVMRemoteLocal.java b/source/java/org/alfresco/repo/avm/AVMRemoteLocal.java new file mode 100644 index 0000000000..63f82f6e8d --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMRemoteLocal.java @@ -0,0 +1,433 @@ +/** + * + */ +package org.alfresco.repo.avm; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; + +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avm.AVMStoreDescriptor; +import org.alfresco.service.cmr.avm.LayeringDescriptor; +import org.alfresco.service.cmr.avm.VersionDescriptor; +import org.alfresco.service.namespace.QName; + +/** + * A loopback implementation of the AVMRemote interface? + * @author britt + */ +public class AVMRemoteLocal implements AVMRemote +{ + /** + * The AVMService instance. + */ + private AVMService fService; + + /** + * Default constructor. + */ + public AVMRemoteLocal() + { + } + + /** + * Setter for the AVMService instance. + */ + public void setAvmService(AVMService service) + { + fService = service; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createAVMStore(java.lang.String) + */ + public void createAVMStore(String name) + { + fService.createAVMStore(name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createBranch(int, java.lang.String, java.lang.String, java.lang.String) + */ + public void createBranch(int version, String srcPath, String dstPath, + String name) + { + fService.createBranch(version, srcPath, dstPath, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createDirectory(java.lang.String, java.lang.String) + */ + public void createDirectory(String path, String name) + { + fService.createDirectory(path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createFile(java.lang.String, java.lang.String) + */ + public OutputStream createFile(String path, String name) + { + return fService.createFile(path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createLayeredDirectory(java.lang.String, java.lang.String, java.lang.String) + */ + public void createLayeredDirectory(String targetPath, String parent, + String name) + { + fService.createLayeredDirectory(targetPath, parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createLayeredFile(java.lang.String, java.lang.String, java.lang.String) + */ + public void createLayeredFile(String targetPath, String parent, String name) + { + fService.createLayeredFile(targetPath, parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String) + */ + public int createSnapshot(String store) + { + return fService.createSnapshot(store, null, null); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteNodeProperties(java.lang.String) + */ + public void deleteNodeProperties(String path) + { + fService.deleteNodeProperties(path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteNodeProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public void deleteNodeProperty(String path, QName name) + { + fService.deleteNodeProperty(path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteStoreProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public void deleteStoreProperty(String store, QName name) + { + fService.deleteStoreProperty(store, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStore(java.lang.String) + */ + public AVMStoreDescriptor getAVMStore(String name) + { + return fService.getAVMStore(name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreRoot(int, java.lang.String) + */ + public AVMNodeDescriptor getAVMStoreRoot(int version, String name) + { + return fService.getAVMStoreRoot(version, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreVersions(java.lang.String) + */ + public List getAVMStoreVersions(String name) + { + return fService.getAVMStoreVersions(name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreVersions(java.lang.String, java.util.Date, java.util.Date) + */ + public List getAVMStoreVersions(String name, Date from, + Date to) + { + return fService.getAVMStoreVersions(name, from, to); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStores() + */ + public List getAVMStores() + { + return fService.getAVMStores(); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getCommonAncestor(org.alfresco.service.cmr.avm.AVMNodeDescriptor, org.alfresco.service.cmr.avm.AVMNodeDescriptor) + */ + public AVMNodeDescriptor getCommonAncestor(AVMNodeDescriptor left, + AVMNodeDescriptor right) + { + return fService.getCommonAncestor(left, right); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDeleted(int, java.lang.String) + */ + public List getDeleted(int version, String path) + { + return fService.getDeleted(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListing(int, java.lang.String) + */ + public SortedMap getDirectoryListing( + int version, String path) + { + return fService.getDirectoryListing(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListing(org.alfresco.service.cmr.avm.AVMNodeDescriptor) + */ + public SortedMap getDirectoryListing( + AVMNodeDescriptor dir) + { + return fService.getDirectoryListing(dir); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListingDirect(int, java.lang.String) + */ + public SortedMap getDirectoryListingDirect( + int version, String path) + { + return fService.getDirectoryListingDirect(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getFileInputStream(int, java.lang.String) + */ + public InputStream getFileInputStream(int version, String path) + { + return fService.getFileInputStream(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String) + */ + public OutputStream getFileOutputStream(String path) + { + return fService.getFileOutputStream(path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getHistory(org.alfresco.service.cmr.avm.AVMNodeDescriptor, int) + */ + public List getHistory(AVMNodeDescriptor desc, int count) + { + return fService.getHistory(desc, count); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getIndirectionPath(int, java.lang.String) + */ + public String getIndirectionPath(int version, String path) + { + return fService.getIndirectionPath(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLatestSnapshotID(java.lang.String) + */ + public int getLatestSnapshotID(String storeName) + { + return 0; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLatestVersionID(java.lang.String) + */ + public int getLatestVersionID(String storeName) + { + return fService.getNextVersionID(storeName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLayeringInfo(int, java.lang.String) + */ + public LayeringDescriptor getLayeringInfo(int version, String path) + { + return fService.getLayeringInfo(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getNodeProperties(int, java.lang.String) + */ + public Map getNodeProperties(int version, String path) + { + return fService.getNodeProperties(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getNodeProperty(int, java.lang.String, org.alfresco.service.namespace.QName) + */ + public PropertyValue getNodeProperty(int version, String path, QName name) + { + return fService.getNodeProperty(version, path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getStoreProperties(java.lang.String) + */ + public Map getStoreProperties(String store) + { + return fService.getStoreProperties(store); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getStoreProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public PropertyValue getStoreProperty(String store, QName name) + { + return fService.getStoreProperty(store, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#lookup(int, java.lang.String) + */ + public AVMNodeDescriptor lookup(int version, String path) + { + return fService.lookup(version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#lookup(org.alfresco.service.cmr.avm.AVMNodeDescriptor, java.lang.String) + */ + public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name) + { + return fService.lookup(dir, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#makePrimary(java.lang.String) + */ + public void makePrimary(String path) + { + fService.makePrimary(path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#purgeAVMStore(java.lang.String) + */ + public void purgeAVMStore(String name) + { + fService.purgeAVMStore(name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#purgeVersion(int, java.lang.String) + */ + public void purgeVersion(int version, String name) + { + fService.purgeVersion(version, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#queryStorePropertyKey(java.lang.String, org.alfresco.service.namespace.QName) + */ + public Map queryStorePropertyKey(String store, + QName keyPattern) + { + return fService.queryStorePropertyKey(store, keyPattern); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#queryStoresPropertyKey(org.alfresco.service.namespace.QName) + */ + public Map> queryStoresPropertyKey( + QName keyPattern) + { + return fService.queryStoresPropertyKeys(keyPattern); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#removeNode(java.lang.String, java.lang.String) + */ + public void removeNode(String parent, String name) + { + fService.removeNode(parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#rename(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + public void rename(String srcParent, String srcName, String dstParent, + String dstName) + { + fService.rename(srcParent, srcName, dstParent, dstName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#retargetLayeredDirectory(java.lang.String, java.lang.String) + */ + public void retargetLayeredDirectory(String path, String target) + { + fService.retargetLayeredDirectory(path, target); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setNodeProperties(java.lang.String, java.util.Map) + */ + public void setNodeProperties(String path, + Map properties) + { + fService.setNodeProperties(path, properties); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setNodeProperty(java.lang.String, org.alfresco.service.namespace.QName, org.alfresco.repo.domain.PropertyValue) + */ + public void setNodeProperty(String path, QName name, PropertyValue value) + { + fService.setNodeProperty(path, name, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setOpacity(java.lang.String, boolean) + */ + public void setOpacity(String path, boolean opacity) + { + fService.setOpacity(path, opacity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setStoreProperties(java.lang.String, java.util.Map) + */ + public void setStoreProperties(String store, Map props) + { + fService.setStoreProperties(store, props); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setStoreProperty(java.lang.String, org.alfresco.service.namespace.QName, org.alfresco.repo.domain.PropertyValue) + */ + public void setStoreProperty(String store, QName name, PropertyValue value) + { + fService.setStoreProperty(store, name, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#uncover(java.lang.String, java.lang.String) + */ + public void uncover(String dirPath, String name) + { + fService.uncover(dirPath, name); + } +} diff --git a/source/java/org/alfresco/repo/avm/AVMRemoteOutputStream.java b/source/java/org/alfresco/repo/avm/AVMRemoteOutputStream.java index 4744fd8b1a..b6e625579b 100644 --- a/source/java/org/alfresco/repo/avm/AVMRemoteOutputStream.java +++ b/source/java/org/alfresco/repo/avm/AVMRemoteOutputStream.java @@ -19,9 +19,11 @@ package org.alfresco.repo.avm; import java.io.IOException; import java.io.OutputStream; +import org.alfresco.repo.avm.clt.ClientTicketHolder; + public class AVMRemoteOutputStream extends OutputStream { - private AVMRemote fAVMRemote; + private AVMRemoteTransport fAVMRemote; private String fHandle; @@ -30,7 +32,7 @@ public class AVMRemoteOutputStream extends OutputStream * @param handle The handle returned from an AVMRemote call. * @param remote The AVMRemote instance. */ - public AVMRemoteOutputStream(String handle, AVMRemote remote) + public AVMRemoteOutputStream(String handle, AVMRemoteTransport remote) { fAVMRemote = remote; fHandle = handle; @@ -58,7 +60,7 @@ public class AVMRemoteOutputStream extends OutputStream { try { - fAVMRemote.closeOutputHandle(fHandle); + fAVMRemote.closeOutputHandle(ClientTicketHolder.GetTicket(), fHandle); } catch (Exception e) { @@ -80,13 +82,13 @@ public class AVMRemoteOutputStream extends OutputStream { if (off == 0) { - fAVMRemote.writeOutput(fHandle, b, len); + fAVMRemote.writeOutput(ClientTicketHolder.GetTicket(), fHandle, b, len); } else { byte [] buff = new byte[len]; System.arraycopy(b, off, buff, 0, len); - fAVMRemote.writeOutput(fHandle, buff, len); + fAVMRemote.writeOutput(ClientTicketHolder.GetTicket(), fHandle, buff, len); } } catch (Exception e) diff --git a/source/java/org/alfresco/repo/avm/AVMRemoteTransport.java b/source/java/org/alfresco/repo/avm/AVMRemoteTransport.java new file mode 100644 index 0000000000..cc9e54ed0d --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMRemoteTransport.java @@ -0,0 +1,411 @@ +/** + * + */ +package org.alfresco.repo.avm; + +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; + +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMStoreDescriptor; +import org.alfresco.service.cmr.avm.LayeringDescriptor; +import org.alfresco.service.cmr.avm.VersionDescriptor; +import org.alfresco.service.namespace.QName; + +/** + * This is the actual remote interface that is wrapped by + * RMI. + * @author britt + */ +public interface AVMRemoteTransport +{ + /** + * Get an input handle. A handle is an opaque reference + * to a server side input stream. + * @param version The version to look under. + * @param path The path to the file. + * @return A handle. + */ + public String getInputHandle(String ticket, int version, String path); + + /** + * Read a chunk of data from a handle. + * @param handle The opaque input stream handle. + * @param count The number of bytes to try to read. + * @return An array of bytes. 0 length at eof. + */ + public byte[] readInput(String Ticket, String handle, int count); + + /** + * Close an input stream. Server side input streams are + * timer limited, ie, they will be automatically closed + * after a given idle time. However, be nice, and close + * handles when you're done. + * @param handle The opaque handle to the server side stream. + */ + public void closeInputHandle(String ticket, String handle); + + /** + * Get an opaque handle to a server side output stream. + * @param path The path to the existing file. + * @return An opaque handle. + */ + public String getOutputHandle(String ticket, String path); + + /** + * Write count bytes from buffer buff + * starting at offset offset in buff + * @param handle The opaque handle to the server side output stream. + * @param buff The data buffer. + * @param count The number of bytes to write. + */ + public void writeOutput(String ticket, String handle, byte [] buff, int count); + + /** + * Close the server side output stream designated by the handle. + * @param handle The handle to the server side output stream. + */ + public void closeOutputHandle(String ticket, String handle); + + /** + * Get a listing of a directories direct contents. + * @param version The version to look under. + * @param path The path to the directory. + * @return A sorted listing. + */ + public SortedMap + getDirectoryListingDirect(String ticket, int version, String path); + + /** + * Get a listing of a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A sorted listing. + */ + public SortedMap + getDirectoryListing(String ticket, int version, String path); + + /** + * Get a directory listing from a node descriptor. + * @param dir The directory node descriptor. + * @return A sorted listing. + */ + public SortedMap + getDirectoryListing(String ticket, AVMNodeDescriptor dir); + + /** + * Get the names of nodes that have been deleted in a directory. + * @param version The version to look under. + * @param path The path to the directory. + * @return A list of deleted names. + */ + public List getDeleted(String ticket, int version, String path); + + /** + * Create a file and return a handle to an output stream. + * @param path The path to the file. + * @param name The name of the file to create. + * @return An opaque handle to a server side output stream. + */ + public String createFile(String ticket, String path, String name); + + /** + * Create a directory. + * @param path The path to the containing directory. + * @param name The name for the new directory. + */ + public void createDirectory(String ticket, String path, String name); + + /** + * Create a new layered file. + * @param targetPath The path that is targeted. + * @param parent The path to the parent directory. + * @param name The name for the new file. + */ + public void createLayeredFile(String ticket, String targetPath, String parent, String name); + + /** + * Create a layered directory. + * @param targetPath The path that is targeted. + * @param parent The parent directory. + * @param name The name of the new directory. + */ + public void createLayeredDirectory(String ticket, String targetPath, String parent, String name); + + /** + * Set a layered directory node to point at a different target. + * @param path The path to the layered directory node. + * @param target The new target. + */ + public void retargetLayeredDirectory(String ticket, String path, String target); + + /** + * Create a new AVMStore. + * @param name The name to give the new store. + */ + public void createAVMStore(String ticket, String name); + + /** + * Create a new branch. + * @param version The version to look under for the source node. + * @param srcPath The path to the source node. + * @param dstPath The path to the destination directory. + * @param name The name of the new branch. + */ + public void createBranch(String ticket, int version, String srcPath, String dstPath, String name); + + /** + * Remove a node. + * @param parent The path to the parent directory. + * @param name The name of the node to remove. + */ + public void removeNode(String ticket, String parent, String name); + + /** + * Rename a node. + * @param srcParent The source directory path. + * @param srcName The source node name. + * @param dstParent The destination directory path. + * @param dstName The destination name for the node. + */ + public void rename(String ticket, String srcParent, String srcName, String dstParent, String dstName); + + /** + * Uncover a name in a layered directory. + * @param dirPath The path to the directory. + * @param name The name to uncover. + */ + public void uncover(String ticket, String dirPath, String name); + + /** + * Get the latest version id of the given AVMStore. + * @param storeName The name of the AVMStore. + * @return The latest version id. + */ + public int getLatestVersionID(String ticket, String storeName); + + /** + * Get the id of the latest extant snpashot. + * @param storeName The name of the store. + * @return The id. + */ + public int getLatestSnapshotID(String ticket, String storeName); + + /** + * Snapshot an AVMStore. + * @param store The name of the AVMStore to snapshot. + * @return The version id of the new snapshot. + */ + public int createSnapshot(String ticket, String store); + + /** + * Get a List of all versions in a given store. + * @param name The name of the store. + * @return A List of VersionDescriptors. + */ + public List getAVMStoreVersions(String ticket, String name); + + /** + * Get AVMStore versions between given dates. + * @param name The name of the store. + * @param from The date from which (inclusive). + * @param to The date to which (inclusive). + * @return A List of VersionDescriptors. + */ + public List getAVMStoreVersions(String ticket, String name, Date from, Date to); + + /** + * Get a list of all AVM stores. + * @return A List of AVMStoreDescriptors. + */ + public List getAVMStores(String ticket); + + /** + * Get the descriptor for a given AVMStore. + * @param name The name of the store. + * @return An AVMStoreDescriptor. + */ + public AVMStoreDescriptor getAVMStore(String ticket, String name); + + /** + * Get the specified root of the specified store. + * @param version The version number to fetch. + * @param name The name of the store. + * @return The AVMNodeDescriptor for the root. + */ + public AVMNodeDescriptor getAVMStoreRoot(String ticket, int version, String name); + + /** + * Get a descriptor for the specified node. + * @param version The version to look under. + * @param path The path to the node. + * @return An AVMNodeDescriptor. + */ + public AVMNodeDescriptor lookup(String ticket, int version, String path); + + /** + * Get a descriptor for the specified node. + * @param dir The descriptor for the directory node. + * @param name The name of the node to lookup. + * @return An AVMNodeDescriptor. + */ + public AVMNodeDescriptor lookup(String ticket, AVMNodeDescriptor dir, String name); + + /** + * Get the indirection path for a node. + * @param version The version to look under. + * @param path The path to the node. + * @return The indirection path/target. + */ + public String getIndirectionPath(String ticket, int version, String path); + + /** + * Purge an AVMStore. + * @param name The name of the store to purge. + */ + public void purgeAVMStore(String ticket, String name); + + /** + * Purge a given version from a given store. + * @param version The version id. + * @param name The name of the store. + */ + public void purgeVersion(String ticket, int version, String name); + + /** + * Turn a directory into a primary indirection node. + * @param path The path to the directory. + */ + public void makePrimary(String ticket, String path); + + /** + * Get a list of ancestors of a node. + * @param desc The descriptor of the node whose history is to be fetched. + * @param count The maximum number of ancestors that will be returned. + * @return A List of descriptors for ancestors starting most recent first. + */ + public List getHistory(String ticket, AVMNodeDescriptor desc, int count); + + /** + * Turn on or off a directory's opacity. + * @param path The path to the directory. + * @param opacity Whether the directory should be opaque or not. + */ + public void setOpacity(String ticket, String path, boolean opacity); + + /** + * Get the most recent common ancestor of two nodes. + * @param left One node. + * @param right The other node. + * @return The common ancestor. + */ + public AVMNodeDescriptor getCommonAncestor(String ticket, AVMNodeDescriptor left, AVMNodeDescriptor right); + + /** + * Get layering information about a path. + * @param version The version to look under. + * @param path The path to the node. + * @return A LayeringDescriptor. + */ + public LayeringDescriptor getLayeringInfo(String ticket, int version, String path); + + /** + * Set a property on a node. + * @param path The path to the node. + * @param name The name of the property. + * @param value The value to give the property. + */ + public void setNodeProperty(String ticket, String path, QName name, PropertyValue value); + + /** + * Set a group of properties on a node. + * @param path The path to the node. + * @param properties A Map of QNames to PropertyValues to set. + */ + public void setNodeProperties(String ticket, String path, Map properties); + + /** + * Get the value of a node property. + * @param version The version to look under. + * @param path The path to the node. + * @param name The name of the property. + * @return A PropertyValue. + */ + public PropertyValue getNodeProperty(String ticket, int version, String path, QName name); + + /** + * Get all properties of a node. + * @param version The version. + * @param path The path to the node. + * @return A Map of QNames to PropertyValues. + */ + public Map getNodeProperties(String ticket, int version, String path); + + /** + * Delete a property from a node. + * @param path The path to the node. + * @param name The name of the property. + */ + public void deleteNodeProperty(String ticket, String path, QName name); + + /** + * Delete all properties from a node. + * @param path The path to the node. + */ + public void deleteNodeProperties(String ticket, String path); + + /** + * Set a property on a store. + * @param store The name of the store. + * @param name The name of the property to set. + * @param value The value of the property to set. + */ + public void setStoreProperty(String ticket, String store, QName name, PropertyValue value); + + /** + * Set a group of properties on a store. + * @param store The name of the store. + * @param props A Map of QNames to PropertyValues to set. + */ + public void setStoreProperties(String ticket, String store, Map props); + + /** + * Get a property from a store. + * @param store The name of the store. + * @param name The name of the property. + * @return A PropertyValue. + */ + public PropertyValue getStoreProperty(String ticket, String store, QName name); + + /** + * Query a store for keys that match a pattern. + * @param store The store name. + * @param keyPattern The sql 'like' pattern. + * @return A Map of keys to values. + */ + public Map queryStorePropertyKey(String ticket, String store, QName keyPattern); + + /** + * Query all stores for keys that match a pattern. + * @param keyPattern The sql 'like' pattern. + * @return A Map of store names to Maps of matching keys to values. + */ + public Map> queryStoresPropertyKey(String ticket, QName keyPattern); + + /** + * Get all the properties on a store. + * @param store The name of the store. + * @return A Map of QNames to PropertyValues. + */ + public Map getStoreProperties(String ticket, String store); + + /** + * Delete a property from a store. + * @param store The name of the store. + * @param name The name of the property. + */ + public void deleteStoreProperty(String ticket, String store, QName name); +} diff --git a/source/java/org/alfresco/repo/avm/AVMRemoteImpl.java b/source/java/org/alfresco/repo/avm/AVMRemoteTransportService.java similarity index 76% rename from source/java/org/alfresco/repo/avm/AVMRemoteImpl.java rename to source/java/org/alfresco/repo/avm/AVMRemoteTransportService.java index 492b1813a2..53761dce16 100644 --- a/source/java/org/alfresco/repo/avm/AVMRemoteImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMRemoteTransportService.java @@ -1,20 +1,6 @@ -/* - * Copyright (C) 2006 Alfresco, Inc. - * - * Licensed under the Mozilla Public License version 1.1 - * with a permitted attribution clause. You may obtain a - * copy of the License at - * - * http://www.alfresco.org/legal/license.txt - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific - * language governing permissions and limitations under the - * License. +/** + * */ - package org.alfresco.repo.avm; import java.io.IOException; @@ -34,14 +20,17 @@ import org.alfresco.service.cmr.avm.AVMService; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avm.LayeringDescriptor; import org.alfresco.service.cmr.avm.VersionDescriptor; +import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.namespace.QName; import org.alfresco.util.GUID; /** - * This is the server side implementation for the remote AVM interface. + * Implementation of AVMRemoteTransport for the server side. It's + * job is to validate the authentication ticket passed with each + * method call, and to manage remote InputStreams and OutputStreams. * @author britt */ -public class AVMRemoteImpl implements AVMRemote, Runnable +public class AVMRemoteTransportService implements AVMRemoteTransport, Runnable { /** * The map of handles to open input streams. @@ -83,6 +72,11 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Reference to AVMService. */ private AVMService fAVMService; + + /** + * Reference to the AuthenticationService. + */ + private AuthenticationService fAuthService; /** * The thread for this Runnable. @@ -97,7 +91,7 @@ public class AVMRemoteImpl implements AVMRemote, Runnable /** * Default constructor. */ - public AVMRemoteImpl() + public AVMRemoteTransportService() { fIdleTimeout = 30000; fInputStreams = new HashMap(); @@ -128,6 +122,11 @@ public class AVMRemoteImpl implements AVMRemote, Runnable fAVMService = service; } + public void setAuthenticationService(AuthenticationService service) + { + fAuthService = service; + } + /** * The init method. This fires up a thread to check * for closable streams. @@ -237,8 +236,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the file. * @return A handle. */ - public String getInputHandle(int version, String path) + public String getInputHandle(String ticket, int version, String path) { + fAuthService.validate(ticket); InputStream in = fAVMService.getFileInputStream(version, path); String handle = GUID.generate(); synchronized (this) @@ -256,8 +256,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param count The number of bytes to try to read. * @return An array of bytes. 0 length at eof. */ - public byte [] readInput(String handle, int count) + public byte [] readInput(String ticket, String handle, int count) { + fAuthService.validate(ticket); InputStream in = null; synchronized (this) { @@ -308,8 +309,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * handles when you're done. * @param handle The opaque handle to the server side stream. */ - public synchronized void closeInputHandle(String handle) + public synchronized void closeInputHandle(String ticket, String handle) { + fAuthService.validate(ticket); InputStream in = fInputStreams.get(handle); if (in != null) { @@ -332,8 +334,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the existing file. * @return An opaque handle. */ - public String getOutputHandle(String path) + public String getOutputHandle(String ticket, String path) { + fAuthService.validate(ticket); OutputStream out = fAVMService.getFileOutputStream(path); String handle = GUID.generate(); synchronized (this) @@ -353,8 +356,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param offset The offset within the buffer. * @param count The number of bytes to write. */ - public void writeOutput(String handle, byte [] buff, int count) + public void writeOutput(String ticket, String handle, byte [] buff, int count) { + fAuthService.validate(ticket); OutputStream out = null; synchronized (this) { @@ -387,8 +391,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Close the server side output stream designated by the handle. * @param handle The handle to the server side output stream. */ - public synchronized void closeOutputHandle(String handle) + public synchronized void closeOutputHandle(String ticket, String handle) { + fAuthService.validate(ticket); OutputStream out = fOutputStreams.get(handle); if (out != null) { @@ -413,8 +418,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @return A sorted listing. */ public SortedMap - getDirectoryListingDirect(int version, String path) + getDirectoryListingDirect(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getDirectoryListingDirect(version, path); } @@ -425,8 +431,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @return A sorted listing. */ public SortedMap - getDirectoryListing(int version, String path) + getDirectoryListing(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getDirectoryListing(version, path); } @@ -436,8 +443,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @return A sorted listing. */ public SortedMap - getDirectoryListing(AVMNodeDescriptor dir) + getDirectoryListing(String ticket, AVMNodeDescriptor dir) { + fAuthService.validate(ticket); return fAVMService.getDirectoryListing(dir); } @@ -447,8 +455,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the directory. * @return A list of deleted names. */ - public List getDeleted(int version, String path) + public List getDeleted(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getDeleted(version, path); } @@ -458,8 +467,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the file to create. * @return An opaque handle to a server side output stream. */ - public String createFile(String path, String name) + public String createFile(String ticket, String path, String name) { + fAuthService.validate(ticket); OutputStream out = fAVMService.createFile(path, name); String handle = GUID.generate(); synchronized (this) @@ -476,8 +486,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the containing directory. * @param name The name for the new directory. */ - public void createDirectory(String path, String name) + public void createDirectory(String ticket, String path, String name) { + fAuthService.validate(ticket); fAVMService.createDirectory(path, name); } @@ -487,8 +498,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param parent The path to the parent directory. * @param name The name for the new file. */ - public void createLayeredFile(String targetPath, String parent, String name) + public void createLayeredFile(String ticket, String targetPath, String parent, String name) { + fAuthService.validate(ticket); fAVMService.createLayeredFile(targetPath, parent, name); } @@ -498,8 +510,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param parent The parent directory. * @param name The name of the new directory. */ - public void createLayeredDirectory(String targetPath, String parent, String name) + public void createLayeredDirectory(String ticket, String targetPath, String parent, String name) { + fAuthService.validate(ticket); fAVMService.createLayeredDirectory(targetPath, parent, name); } @@ -508,8 +521,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the layered directory node. * @param target The new target. */ - public void retargetLayeredDirectory(String path, String target) + public void retargetLayeredDirectory(String ticket, String path, String target) { + fAuthService.validate(ticket); fAVMService.retargetLayeredDirectory(path, target); } @@ -517,8 +531,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Create a new AVMStore. * @param name The name to give the new store. */ - public void createAVMStore(String name) + public void createAVMStore(String ticket, String name) { + fAuthService.validate(ticket); fAVMService.createAVMStore(name); } @@ -529,8 +544,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param dstPath The path to the destination directory. * @param name The name of the new branch. */ - public void createBranch(int version, String srcPath, String dstPath, String name) + public void createBranch(String ticket, int version, String srcPath, String dstPath, String name) { + fAuthService.validate(ticket); fAVMService.createBranch(version, srcPath, dstPath, name); } @@ -539,8 +555,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param parent The path to the parent directory. * @param name The name of the node to remove. */ - public void removeNode(String parent, String name) + public void removeNode(String ticket, String parent, String name) { + fAuthService.validate(ticket); fAVMService.removeNode(parent, name); } @@ -551,8 +568,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param dstParent The destination directory path. * @param dstName The destination name for the node. */ - public void rename(String srcParent, String srcName, String dstParent, String dstName) - { + public void rename(String ticket, String srcParent, String srcName, String dstParent, String dstName) + { + fAuthService.validate(ticket); fAVMService.rename(srcParent, srcName, dstParent, dstName); } @@ -561,8 +579,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param dirPath The path to the directory. * @param name The name to uncover. */ - public void uncover(String dirPath, String name) + public void uncover(String ticket, String dirPath, String name) { + fAuthService.validate(ticket); fAVMService.uncover(dirPath, name); } @@ -571,8 +590,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param storeName The name of the AVMStore. * @return The latest version id. */ - public int getLatestVersionID(String storeName) + public int getLatestVersionID(String ticket, String storeName) { + fAuthService.validate(ticket); return fAVMService.getNextVersionID(storeName); } @@ -581,19 +601,19 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param storeName The store name. * @return The id. */ - public int getLatestSnapshotID(String storeName) + public int getLatestSnapshotID(String ticket, String storeName) { return fAVMService.getLatestSnapshotID(storeName); } - // TODO update this if it's ever needed. /** * Snapshot an AVMStore. * @param store The name of the AVMStore to snapshot. * @return The version id of the new snapshot. */ - public int createSnapshot(String store) + public int createSnapshot(String ticket, String store) { + fAuthService.validate(ticket); return fAVMService.createSnapshot(store, null, null); } @@ -602,8 +622,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the store. * @return A List of VersionDescriptors. */ - public List getAVMStoreVersions(String name) + public List getAVMStoreVersions(String ticket, String name) { + fAuthService.validate(ticket); return fAVMService.getAVMStoreVersions(name); } @@ -614,8 +635,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param to The date to which (inclusive). * @return A List of VersionDescriptors. */ - public List getAVMStoreVersions(String name, Date from, Date to) + public List getAVMStoreVersions(String ticket, String name, Date from, Date to) { + fAuthService.validate(ticket); return fAVMService.getAVMStoreVersions(name, from, to); } @@ -623,8 +645,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Get a list of all AVM stores. * @return A List of AVMStoreDescriptors. */ - public List getAVMStores() + public List getAVMStores(String ticket) { + fAuthService.validate(ticket); return fAVMService.getAVMStores(); } @@ -633,8 +656,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the store. * @return An AVMStoreDescriptor. */ - public AVMStoreDescriptor getAVMStore(String name) + public AVMStoreDescriptor getAVMStore(String ticket, String name) { + fAuthService.validate(ticket); return fAVMService.getAVMStore(name); } @@ -644,8 +668,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the store. * @return The AVMNodeDescriptor for the root. */ - public AVMNodeDescriptor getAVMStoreRoot(int version, String name) + public AVMNodeDescriptor getAVMStoreRoot(String ticket, int version, String name) { + fAuthService.validate(ticket); return fAVMService.getAVMStoreRoot(version, name); } @@ -655,8 +680,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @return An AVMNodeDescriptor. */ - public AVMNodeDescriptor lookup(int version, String path) + public AVMNodeDescriptor lookup(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.lookup(version, path); } @@ -666,8 +692,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the node to lookup. * @return An AVMNodeDescriptor. */ - public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name) + public AVMNodeDescriptor lookup(String ticket, AVMNodeDescriptor dir, String name) { + fAuthService.validate(ticket); return fAVMService.lookup(dir, name); } @@ -677,8 +704,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @return The indirection path/target. */ - public String getIndirectionPath(int version, String path) + public String getIndirectionPath(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getIndirectionPath(version, path); } @@ -686,8 +714,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Purge an AVMStore. * @param name The name of the store to purge. */ - public void purgeAVMStore(String name) + public void purgeAVMStore(String ticket, String name) { + fAuthService.validate(ticket); fAVMService.purgeAVMStore(name); } @@ -696,8 +725,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param version The version id. * @param name The name of the store. */ - public void purgeVersion(int version, String name) + public void purgeVersion(String ticket, int version, String name) { + fAuthService.validate(ticket); fAVMService.purgeVersion(version, name); } @@ -705,8 +735,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Turn a directory into a primary indirection node. * @param path The path to the directory. */ - public void makePrimary(String path) + public void makePrimary(String ticket, String path) { + fAuthService.validate(ticket); fAVMService.makePrimary(path); } @@ -716,8 +747,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param count The maximum number of ancestors that will be returned. * @return A List of descriptors for ancestors starting most recent first. */ - public List getHistory(AVMNodeDescriptor desc, int count) + public List getHistory(String ticket, AVMNodeDescriptor desc, int count) { + fAuthService.validate(ticket); return fAVMService.getHistory(desc, count); } @@ -726,8 +758,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the directory. * @param opacity Whether the directory should be opaque or not. */ - public void setOpacity(String path, boolean opacity) + public void setOpacity(String ticket, String path, boolean opacity) { + fAuthService.validate(ticket); fAVMService.setOpacity(path, opacity); } @@ -737,8 +770,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param right The other node. * @return The common ancestor. */ - public AVMNodeDescriptor getCommonAncestor(AVMNodeDescriptor left, AVMNodeDescriptor right) + public AVMNodeDescriptor getCommonAncestor(String ticket, AVMNodeDescriptor left, AVMNodeDescriptor right) { + fAuthService.validate(ticket); return fAVMService.getCommonAncestor(left, right); } @@ -748,8 +782,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @return A LayeringDescriptor. */ - public LayeringDescriptor getLayeringInfo(int version, String path) + public LayeringDescriptor getLayeringInfo(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getLayeringInfo(version, path); } @@ -759,8 +794,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the property. * @param value The value to give the property. */ - public void setNodeProperty(String path, QName name, PropertyValue value) + public void setNodeProperty(String ticket, String path, QName name, PropertyValue value) { + fAuthService.validate(ticket); fAVMService.setNodeProperty(path, name, value); } @@ -769,8 +805,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @param properties A Map of QNames to PropertyValues to set. */ - public void setNodeProperties(String path, Map properties) + public void setNodeProperties(String ticket, String path, Map properties) { + fAuthService.validate(ticket); fAVMService.setNodeProperties(path, properties); } @@ -781,8 +818,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the property. * @return A PropertyValue. */ - public PropertyValue getNodeProperty(int version, String path, QName name) + public PropertyValue getNodeProperty(String ticket, int version, String path, QName name) { + fAuthService.validate(ticket); return fAVMService.getNodeProperty(version, path, name); } @@ -792,8 +830,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @return A Map of QNames to PropertyValues. */ - public Map getNodeProperties(int version, String path) + public Map getNodeProperties(String ticket, int version, String path) { + fAuthService.validate(ticket); return fAVMService.getNodeProperties(version, path); } @@ -802,8 +841,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param path The path to the node. * @param name The name of the property. */ - public void deleteNodeProperty(String path, QName name) + public void deleteNodeProperty(String ticket, String path, QName name) { + fAuthService.validate(ticket); fAVMService.deleteNodeProperty(path, name); } @@ -811,8 +851,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * Delete all properties from a node. * @param path The path to the node. */ - public void deleteNodeProperties(String path) + public void deleteNodeProperties(String ticket, String path) { + fAuthService.validate(ticket); fAVMService.deleteNodeProperties(path); } @@ -822,8 +863,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the property to set. * @param value The value of the property to set. */ - public void setStoreProperty(String store, QName name, PropertyValue value) + public void setStoreProperty(String ticket, String store, QName name, PropertyValue value) { + fAuthService.validate(ticket); fAVMService.setStoreProperty(store, name, value); } @@ -832,8 +874,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param store The name of the store. * @param props A Map of QNames to PropertyValues to set. */ - public void setStoreProperties(String store, Map props) + public void setStoreProperties(String ticket, String store, Map props) { + fAuthService.validate(ticket); fAVMService.setStoreProperties(store, props); } @@ -843,8 +886,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param name The name of the property. * @return A PropertyValue. */ - public PropertyValue getStoreProperty(String store, QName name) + public PropertyValue getStoreProperty(String ticket, String store, QName name) { + fAuthService.validate(ticket); return fAVMService.getStoreProperty(store, name); } @@ -854,8 +898,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param keyPattern The sql 'like' pattern. * @return A Map of keys to values. */ - public Map queryStorePropertyKey(String store, QName keyPattern) + public Map queryStorePropertyKey(String ticket, String store, QName keyPattern) { + fAuthService.validate(ticket); return fAVMService.queryStorePropertyKey(store, keyPattern); } @@ -864,8 +909,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param keyPattern The sql 'like' pattern. * @return A Map of store names to Maps of matching keys to values. */ - public Map> queryStoresPropertyKey(QName keyPattern) + public Map> queryStoresPropertyKey(String ticket, QName keyPattern) { + fAuthService.validate(ticket); return fAVMService.queryStoresPropertyKeys(keyPattern); } @@ -874,8 +920,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param store The name of the store. * @return A Map of QNames to PropertyValues. */ - public Map getStoreProperties(String store) + public Map getStoreProperties(String ticket, String store) { + fAuthService.validate(ticket); return fAVMService.getStoreProperties(store); } @@ -884,8 +931,9 @@ public class AVMRemoteImpl implements AVMRemote, Runnable * @param store The name of the store. * @param name The name of the property. */ - public void deleteStoreProperty(String store, QName name) + public void deleteStoreProperty(String ticket, String store, QName name) { + fAuthService.validate(ticket); fAVMService.deleteStoreProperty(store, name); } } diff --git a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java index a5a07f8048..fa4bf4f155 100644 --- a/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java +++ b/source/java/org/alfresco/repo/avm/AVMSyncServiceImpl.java @@ -358,7 +358,7 @@ public class AVMSyncServiceImpl implements AVMSyncService // You can force it. if (overrideOlder) { - linkIn(dstParts[0], dstParts[1], srcDesc, true); + linkIn(dstParts[0], dstParts[1], srcDesc, !dstDesc.isDeleted()); continue; } // You can ignore it. diff --git a/source/java/org/alfresco/repo/avm/AVMSyncServiceTransportImpl.java b/source/java/org/alfresco/repo/avm/AVMSyncServiceTransportImpl.java new file mode 100644 index 0000000000..70bf50bfb2 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AVMSyncServiceTransportImpl.java @@ -0,0 +1,85 @@ +/** + * + */ +package org.alfresco.repo.avm; + +import java.util.List; + +import org.alfresco.service.cmr.avmsync.AVMDifference; +import org.alfresco.service.cmr.avmsync.AVMSyncService; +import org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport; +import org.alfresco.service.cmr.security.AuthenticationService; + +/** + * Server side implementation of the remote wrapper of AVMSyncService. + * @author britt + */ +public class AVMSyncServiceTransportImpl implements AVMSyncServiceTransport +{ + /** + * Reference to the AVMSyncService instance. + */ + private AVMSyncService fSyncService; + + /** + * Reference to the AuthenticationService instance. + */ + private AuthenticationService fAuthenticationService; + + /** + * Default constructor. + */ + public AVMSyncServiceTransportImpl() + { + } + + public void setAvmSyncService(AVMSyncService service) + { + fSyncService = service; + } + + public void setAuthenticationService(AuthenticationService service) + { + fAuthenticationService = service; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#compare(java.lang.String, int, java.lang.String, int, java.lang.String) + */ + public List compare(String ticket, int srcVersion, + String srcPath, int dstVersion, String dstPath) + { + fAuthenticationService.validate(ticket); + return fSyncService.compare(srcVersion, srcPath, dstVersion, dstPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#flatten(java.lang.String, java.lang.String, java.lang.String) + */ + public void flatten(String ticket, String layerPath, String underlyingPath) + { + fAuthenticationService.validate(ticket); + fSyncService.flatten(layerPath, underlyingPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#resetLayer(java.lang.String, java.lang.String) + */ + public void resetLayer(String ticket, String layerPath) + { + fAuthenticationService.validate(ticket); + fSyncService.resetLayer(layerPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport#update(java.lang.String, java.util.List, boolean, boolean, boolean, boolean, java.lang.String, java.lang.String) + */ + public void update(String ticket, List diffList, + boolean ignoreConflicts, boolean ignoreOlder, + boolean overrideConflicts, boolean overrideOlder, String tag, + String description) + { + fAuthenticationService.validate(ticket); + fSyncService.update(diffList, ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder, tag, description); + } +} diff --git a/source/java/org/alfresco/repo/avm/AVMTestRemote.java b/source/java/org/alfresco/repo/avm/AVMTestRemote.java index d10efa4967..0afc730973 100644 --- a/source/java/org/alfresco/repo/avm/AVMTestRemote.java +++ b/source/java/org/alfresco/repo/avm/AVMTestRemote.java @@ -17,11 +17,15 @@ package org.alfresco.repo.avm; +import java.io.InputStream; +import java.io.OutputStream; import java.util.List; +import org.alfresco.repo.avm.clt.ClientTicketHolder; import org.alfresco.service.cmr.avm.AVMStoreDescriptor; import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMSyncService; +import org.alfresco.service.cmr.security.AuthenticationService; import org.springframework.context.support.FileSystemXmlApplicationContext; import junit.framework.TestCase; @@ -42,6 +46,11 @@ public class AVMTestRemote extends TestCase */ private AVMSyncService fAVMSync; + /** + * The Authentication Service. + */ + private AuthenticationService fAuthService; + /** * The application context. */ @@ -52,7 +61,11 @@ public class AVMTestRemote extends TestCase { fContext = new FileSystemXmlApplicationContext("config/alfresco/remote-avm-test-context.xml"); fAVMRemote = (AVMRemote)fContext.getBean("avmRemote"); - fAVMSync = (AVMSyncService)fContext.getBean("avmSync"); + fAVMSync = (AVMSyncService)fContext.getBean("avmSyncService"); + fAuthService = (AuthenticationService)fContext.getBean("authenticationService"); + fAuthService.authenticate("admin", "admin".toCharArray()); + String ticket = fAuthService.getCurrentTicket(); + ClientTicketHolder.SetTicket(ticket); } @Override @@ -98,18 +111,16 @@ public class AVMTestRemote extends TestCase // Create a directory. fAVMRemote.createDirectory("test2933:/", "a"); // Write out a file. - AVMRemoteOutputStream out = - new AVMRemoteOutputStream(fAVMRemote.createFile("test2933:/a", "foo.txt"), - fAVMRemote); + OutputStream out = + fAVMRemote.createFile("test2933:/a", "foo.txt"); byte [] buff = "This is a plain old text file.\n".getBytes(); out.write(buff); buff = "It contains text.\n".getBytes(); out.write(buff); out.close(); // Read back that file. - AVMRemoteInputStream in = - new AVMRemoteInputStream(fAVMRemote.getInputHandle(-1, "test2933:/a/foo.txt"), - fAVMRemote); + InputStream in = + fAVMRemote.getFileInputStream(-1, "test2933:/a/foo.txt"); buff = new byte[1024]; assertEquals(49, in.read(buff)); System.out.print(new String(buff)); @@ -136,15 +147,13 @@ public class AVMTestRemote extends TestCase { buff[i] = (byte)i; } - AVMRemoteOutputStream out = - new AVMRemoteOutputStream(fAVMRemote.createFile("froo:/", "foo.dat"), - fAVMRemote); + OutputStream out = + fAVMRemote.createFile("froo:/", "foo.dat"); out.write(buff, 32, 32); out.close(); // Read it back in. - AVMRemoteInputStream in = - new AVMRemoteInputStream(fAVMRemote.getInputHandle(-1, "froo:/foo.dat"), - fAVMRemote); + InputStream in = + fAVMRemote.getFileInputStream(-1, "froo:/foo.dat"); buff = new byte[1024]; assertEquals(32, in.read(buff)); in.close(); @@ -184,14 +193,14 @@ public class AVMTestRemote extends TestCase // Create a directory. fAVMRemote.createDirectory("froo:/", "a"); // Create a file. - fAVMRemote.closeOutputHandle(fAVMRemote.createFile("froo:/a", "foo")); + fAVMRemote.createFile("froo:/a", "foo").close(); // Create another store. fAVMRemote.createAVMStore("broo"); // Create a branch. fAVMRemote.createBranch(-1, "froo:/a", "broo:/", "a"); List diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a"); assertEquals(0, diffs.size()); - fAVMRemote.closeOutputHandle(fAVMRemote.createFile("froo:/a", "bar")); + fAVMRemote.createFile("froo:/a", "bar").close(); diffs = fAVMSync.compare(-1, "froo:/a", -1, "broo:/a"); assertEquals(1, diffs.size()); // Update. diff --git a/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java b/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java index 3a0577af48..c8f70b0daf 100644 --- a/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java +++ b/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java @@ -52,6 +52,9 @@ public abstract class AVMCltBase fAVMRemote = (AVMRemote)fContext.getBean("avmRemote"); fAVMSyncService = (AVMSyncService)fContext.getBean("avmSyncService"); fAuthenticationService = (AuthenticationService)fContext.getBean("authenticationService"); + fAuthenticationService.authenticate("admin", "admin".toCharArray()); + String ticket = fAuthenticationService.getCurrentTicket(); + ClientTicketHolder.SetTicket(ticket); } /** diff --git a/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java b/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java index 1ea266005d..53e7f1fd5e 100644 --- a/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java +++ b/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java @@ -11,7 +11,6 @@ import java.io.OutputStream; import java.util.List; import java.util.Map; -import org.alfresco.repo.avm.AVMRemoteOutputStream; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; /** @@ -70,9 +69,8 @@ public class AVMCopyIn extends AVMCltBase } InputStream in = new FileInputStream(file); - OutputStream out = - new AVMRemoteOutputStream(fAVMRemote.createFile(pathBase[0], pathBase[1]), - fAVMRemote); + OutputStream out = fAVMRemote.createFile(pathBase[0], pathBase[1]); + copyStream(in, out); } catch (IOException e) @@ -99,8 +97,7 @@ public class AVMCopyIn extends AVMCltBase InputStream in = new FileInputStream(file); OutputStream out = - new AVMRemoteOutputStream(fAVMRemote.createFile(args.get(1), - file.getName()), fAVMRemote); + fAVMRemote.createFile(args.get(1), file.getName()); copyStream(in, out); } catch (IOException e) @@ -157,9 +154,7 @@ public class AVMCopyIn extends AVMCltBase { InputStream in = new FileInputStream(file); - OutputStream out = - new AVMRemoteOutputStream(fAVMRemote.createFile(dest, file.getName()), - fAVMRemote); + OutputStream out = fAVMRemote.createFile(dest, file.getName()); copyStream(in, out); } catch (IOException e) diff --git a/source/java/org/alfresco/repo/avm/clt/AVMRemoteImpl.java b/source/java/org/alfresco/repo/avm/clt/AVMRemoteImpl.java new file mode 100644 index 0000000000..47a2c6a581 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/clt/AVMRemoteImpl.java @@ -0,0 +1,439 @@ +/** + * + */ +package org.alfresco.repo.avm.clt; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; + +import org.alfresco.repo.avm.AVMRemote; +import org.alfresco.repo.avm.AVMRemoteInputStream; +import org.alfresco.repo.avm.AVMRemoteOutputStream; +import org.alfresco.repo.avm.AVMRemoteTransport; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.avm.AVMStoreDescriptor; +import org.alfresco.service.cmr.avm.LayeringDescriptor; +import org.alfresco.service.cmr.avm.VersionDescriptor; +import org.alfresco.service.namespace.QName; + +/** + * Client side wrapper for AVMRemoteTransport. + * @author britt + */ +public class AVMRemoteImpl implements AVMRemote +{ + /** + * The reference to the AVMRemoteTransport instance. + */ + private AVMRemoteTransport fTransport; + + /** + * Default constructor. + */ + public AVMRemoteImpl() + { + } + + /** + * Set the remote transport. + */ + public void setAvmRemoteTransport(AVMRemoteTransport transport) + { + fTransport = transport; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createAVMStore(java.lang.String) + */ + public void createAVMStore(String name) + { + fTransport.createAVMStore(ClientTicketHolder.GetTicket(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createBranch(int, java.lang.String, java.lang.String, java.lang.String) + */ + public void createBranch(int version, String srcPath, String dstPath, + String name) + { + fTransport.createBranch(ClientTicketHolder.GetTicket(), version, + srcPath, dstPath, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createDirectory(java.lang.String, java.lang.String) + */ + public void createDirectory(String path, String name) + { + fTransport.createDirectory(ClientTicketHolder.GetTicket(), path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createFile(java.lang.String, java.lang.String) + */ + public OutputStream createFile(String path, String name) + { + return new AVMRemoteOutputStream(fTransport.createFile(ClientTicketHolder.GetTicket(), path, name), fTransport); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createLayeredDirectory(java.lang.String, java.lang.String, java.lang.String) + */ + public void createLayeredDirectory(String targetPath, String parent, + String name) + { + fTransport.createLayeredDirectory(ClientTicketHolder.GetTicket(), targetPath, parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createLayeredFile(java.lang.String, java.lang.String, java.lang.String) + */ + public void createLayeredFile(String targetPath, String parent, String name) + { + fTransport.createLayeredFile(ClientTicketHolder.GetTicket(), targetPath, parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#createSnapshot(java.lang.String) + */ + public int createSnapshot(String store) + { + return fTransport.createSnapshot(ClientTicketHolder.GetTicket(), store); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteNodeProperties(java.lang.String) + */ + public void deleteNodeProperties(String path) + { + fTransport.deleteNodeProperties(ClientTicketHolder.GetTicket(), path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteNodeProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public void deleteNodeProperty(String path, QName name) + { + fTransport.deleteNodeProperty(ClientTicketHolder.GetTicket(), path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#deleteStoreProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public void deleteStoreProperty(String store, QName name) + { + fTransport.deleteStoreProperty(ClientTicketHolder.GetTicket(), store, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStore(java.lang.String) + */ + public AVMStoreDescriptor getAVMStore(String name) + { + return fTransport.getAVMStore(ClientTicketHolder.GetTicket(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreRoot(int, java.lang.String) + */ + public AVMNodeDescriptor getAVMStoreRoot(int version, String name) + { + return fTransport.getAVMStoreRoot(ClientTicketHolder.GetTicket(), version, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreVersions(java.lang.String) + */ + public List getAVMStoreVersions(String name) + { + return fTransport.getAVMStoreVersions(ClientTicketHolder.GetTicket(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStoreVersions(java.lang.String, java.util.Date, java.util.Date) + */ + public List getAVMStoreVersions(String name, Date from, + Date to) + { + return fTransport.getAVMStoreVersions(ClientTicketHolder.GetTicket(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getAVMStores() + */ + public List getAVMStores() + { + return fTransport.getAVMStores(ClientTicketHolder.GetTicket()); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getCommonAncestor(org.alfresco.service.cmr.avm.AVMNodeDescriptor, org.alfresco.service.cmr.avm.AVMNodeDescriptor) + */ + public AVMNodeDescriptor getCommonAncestor(AVMNodeDescriptor left, + AVMNodeDescriptor right) + { + return fTransport.getCommonAncestor(ClientTicketHolder.GetTicket(), left, right); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDeleted(int, java.lang.String) + */ + public List getDeleted(int version, String path) + { + return fTransport.getDeleted(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListing(int, java.lang.String) + */ + public SortedMap getDirectoryListing( + int version, String path) + { + return fTransport.getDirectoryListing(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListing(org.alfresco.service.cmr.avm.AVMNodeDescriptor) + */ + public SortedMap getDirectoryListing( + AVMNodeDescriptor dir) + { + return fTransport.getDirectoryListing(ClientTicketHolder.GetTicket(), dir); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getDirectoryListingDirect(int, java.lang.String) + */ + public SortedMap getDirectoryListingDirect( + int version, String path) + { + return fTransport.getDirectoryListing(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getFileInputStream(int, java.lang.String) + */ + public InputStream getFileInputStream(int version, String path) + { + return new AVMRemoteInputStream(fTransport.getInputHandle(ClientTicketHolder.GetTicket(), version, path), + fTransport); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getFileOutputStream(java.lang.String) + */ + public OutputStream getFileOutputStream(String path) + { + return new AVMRemoteOutputStream(fTransport.getOutputHandle(ClientTicketHolder.GetTicket(), path), + fTransport); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getHistory(org.alfresco.service.cmr.avm.AVMNodeDescriptor, int) + */ + public List getHistory(AVMNodeDescriptor desc, int count) + { + return fTransport.getHistory(ClientTicketHolder.GetTicket(), desc, count); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getIndirectionPath(int, java.lang.String) + */ + public String getIndirectionPath(int version, String path) + { + return fTransport.getIndirectionPath(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLatestSnapshotID(java.lang.String) + */ + public int getLatestSnapshotID(String storeName) + { + return fTransport.getLatestSnapshotID(ClientTicketHolder.GetTicket(), storeName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLatestVersionID(java.lang.String) + */ + public int getLatestVersionID(String storeName) + { + return fTransport.getLatestVersionID(ClientTicketHolder.GetTicket(), storeName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getLayeringInfo(int, java.lang.String) + */ + public LayeringDescriptor getLayeringInfo(int version, String path) + { + return fTransport.getLayeringInfo(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getNodeProperties(int, java.lang.String) + */ + public Map getNodeProperties(int version, String path) + { + return fTransport.getNodeProperties(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getNodeProperty(int, java.lang.String, org.alfresco.service.namespace.QName) + */ + public PropertyValue getNodeProperty(int version, String path, QName name) + { + return fTransport.getNodeProperty(ClientTicketHolder.GetTicket(), version, path, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getStoreProperties(java.lang.String) + */ + public Map getStoreProperties(String store) + { + return fTransport.getStoreProperties(ClientTicketHolder.GetTicket(), store); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#getStoreProperty(java.lang.String, org.alfresco.service.namespace.QName) + */ + public PropertyValue getStoreProperty(String store, QName name) + { + return fTransport.getStoreProperty(ClientTicketHolder.GetTicket(), store, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#lookup(int, java.lang.String) + */ + public AVMNodeDescriptor lookup(int version, String path) + { + return fTransport.lookup(ClientTicketHolder.GetTicket(), version, path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#lookup(org.alfresco.service.cmr.avm.AVMNodeDescriptor, java.lang.String) + */ + public AVMNodeDescriptor lookup(AVMNodeDescriptor dir, String name) + { + return fTransport.lookup(ClientTicketHolder.GetTicket(), dir, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#makePrimary(java.lang.String) + */ + public void makePrimary(String path) + { + fTransport.makePrimary(ClientTicketHolder.GetTicket(), path); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#purgeAVMStore(java.lang.String) + */ + public void purgeAVMStore(String name) + { + fTransport.purgeAVMStore(ClientTicketHolder.GetTicket(), name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#purgeVersion(int, java.lang.String) + */ + public void purgeVersion(int version, String name) + { + fTransport.purgeVersion(ClientTicketHolder.GetTicket(), version, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#queryStorePropertyKey(java.lang.String, org.alfresco.service.namespace.QName) + */ + public Map queryStorePropertyKey(String store, + QName keyPattern) + { + return fTransport.queryStorePropertyKey(ClientTicketHolder.GetTicket(), store, keyPattern); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#queryStoresPropertyKey(org.alfresco.service.namespace.QName) + */ + public Map> queryStoresPropertyKey( + QName keyPattern) + { + return fTransport.queryStoresPropertyKey(ClientTicketHolder.GetTicket(), keyPattern); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#removeNode(java.lang.String, java.lang.String) + */ + public void removeNode(String parent, String name) + { + fTransport.removeNode(ClientTicketHolder.GetTicket(), parent, name); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#rename(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ + public void rename(String srcParent, String srcName, String dstParent, + String dstName) + { + fTransport.rename(ClientTicketHolder.GetTicket(), srcParent, srcName, dstParent, dstName); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#retargetLayeredDirectory(java.lang.String, java.lang.String) + */ + public void retargetLayeredDirectory(String path, String target) + { + fTransport.retargetLayeredDirectory(ClientTicketHolder.GetTicket(), path, target); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setNodeProperties(java.lang.String, java.util.Map) + */ + public void setNodeProperties(String path, + Map properties) + { + fTransport.setNodeProperties(ClientTicketHolder.GetTicket(), path, properties); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setNodeProperty(java.lang.String, org.alfresco.service.namespace.QName, org.alfresco.repo.domain.PropertyValue) + */ + public void setNodeProperty(String path, QName name, PropertyValue value) + { + fTransport.setNodeProperty(ClientTicketHolder.GetTicket(), path, name, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setOpacity(java.lang.String, boolean) + */ + public void setOpacity(String path, boolean opacity) + { + fTransport.setOpacity(ClientTicketHolder.GetTicket(), path, opacity); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setStoreProperties(java.lang.String, java.util.Map) + */ + public void setStoreProperties(String store, Map props) + { + fTransport.setStoreProperties(ClientTicketHolder.GetTicket(), store, props); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#setStoreProperty(java.lang.String, org.alfresco.service.namespace.QName, org.alfresco.repo.domain.PropertyValue) + */ + public void setStoreProperty(String store, QName name, PropertyValue value) + { + fTransport.setStoreProperty(ClientTicketHolder.GetTicket(), store, name, value); + } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMRemote#uncover(java.lang.String, java.lang.String) + */ + public void uncover(String dirPath, String name) + { + fTransport.uncover(ClientTicketHolder.GetTicket(), dirPath, name); + } +} diff --git a/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java b/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java new file mode 100644 index 0000000000..2842ad0166 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java @@ -0,0 +1,73 @@ +/** + * + */ +package org.alfresco.repo.avm.clt; + +import java.util.List; + +import org.alfresco.service.cmr.avmsync.AVMDifference; +import org.alfresco.service.cmr.avmsync.AVMSyncService; +import org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport; +import org.alfresco.service.cmr.security.AuthenticationService; + +/** + * Client side wrapper around the RMI based AVMSyncServiceTransport. + * @author britt + */ +public class AVMSyncServiceClient implements AVMSyncService +{ + /** + * The instance of AVMSyncServiceTransport. + */ + private AVMSyncServiceTransport fTransport; + + /** + * Default constructor. + */ + public AVMSyncServiceClient() + { + } + + /** + * Set the transport for the service. + */ + public void setAvmSyncServiceTransport(AVMSyncServiceTransport transport) + { + fTransport = transport; + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncService#compare(int, java.lang.String, int, java.lang.String) + */ + public List compare(int srcVersion, String srcPath, + int dstVersion, String dstPath) + { + return fTransport.compare(ClientTicketHolder.GetTicket(), srcVersion, srcPath, dstVersion, dstPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncService#flatten(java.lang.String, java.lang.String) + */ + public void flatten(String layerPath, String underlyingPath) + { + fTransport.flatten(ClientTicketHolder.GetTicket(), layerPath, underlyingPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncService#resetLayer(java.lang.String) + */ + public void resetLayer(String layerPath) + { + fTransport.resetLayer(ClientTicketHolder.GetTicket(), layerPath); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.avmsync.AVMSyncService#update(java.util.List, boolean, boolean, boolean, boolean, java.lang.String, java.lang.String) + */ + public void update(List diffList, boolean ignoreConflicts, + boolean ignoreOlder, boolean overrideConflicts, + boolean overrideOlder, String tag, String description) + { + fTransport.update(ClientTicketHolder.GetTicket(), diffList, ignoreConflicts, ignoreOlder, overrideConflicts, overrideOlder, tag, description); + } +} diff --git a/source/java/org/alfresco/repo/avm/clt/ClientTicketHolder.java b/source/java/org/alfresco/repo/avm/clt/ClientTicketHolder.java new file mode 100644 index 0000000000..bd1d4762ff --- /dev/null +++ b/source/java/org/alfresco/repo/avm/clt/ClientTicketHolder.java @@ -0,0 +1,32 @@ +/** + * + */ +package org.alfresco.repo.avm.clt; + +/** + * Remote client utility to hold an authentication ticket. + * @author britt + */ +public class ClientTicketHolder +{ + /** + * Thread local tickets. + */ + private static String fTicket; + + /** + * Set the ticket. + */ + public static void SetTicket(String ticket) + { + fTicket = ticket; + } + + /** + * Get the ticket. + */ + public static String GetTicket() + { + return fTicket; + } +} diff --git a/source/java/org/alfresco/service/cmr/avmsync/AVMSyncServiceTransport.java b/source/java/org/alfresco/service/cmr/avmsync/AVMSyncServiceTransport.java new file mode 100644 index 0000000000..9ef205c6a1 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/avmsync/AVMSyncServiceTransport.java @@ -0,0 +1,65 @@ +/** + * + */ +package org.alfresco.service.cmr.avmsync; + +import java.util.List; + +/** + * A wrapper around AVMSyncService for remote access. + * @author britt + */ +public interface AVMSyncServiceTransport +{ + /** + * Get a difference list between two corresponding node trees. + * @param srcVersion The version id for the source tree. + * @param srcPath The avm path to the source tree. + * @param dstVersion The version id for the destination tree. + * @param dstPath The avm path to the destination tree. + * @return A List of AVMDifference structs which can be used for + * the update operation. + */ + public List compare(String ticket, + int srcVersion, String srcPath, + int dstVersion, String dstPath); + + /** + * Updates the destination nodes in the AVMDifferences + * with the source nodes. Normally any conflicts or cases in + * which the source of an AVMDifference is older than the destination + * will cause the transaction to roll back. + * @param diffList A List of AVMDifference structs. + * @param ignoreConflicts If this is true the update will skip those + * AVMDifferences which are in conflict with + * the destination. + * @param ignoreOlder If this is true the update will skip those + * AVMDifferences which have the source older than the destination. + * @param overrideConflicts If this is true the update will override conflicting + * AVMDifferences and replace the destination with the conflicting source. + * @param overrideOlder If this is true the update will override AVMDifferences + * in which the source is older than the destination and overwrite the destination. + * @param tag Short comment. + * @param description Full update blurb. + */ + public void update(String ticket, List diffList, boolean ignoreConflicts, boolean ignoreOlder, + boolean overrideConflicts, boolean overrideOlder, String tag, String description); + + /** + * Flattens a layer so that all all nodes under and including + * layerPath become translucent to any nodes in the + * corresponding location under and including underlyingPath + * that are the same version. + * @param layerPath The overlying layer path. + * @param underlyingPath The underlying path. + */ + public void flatten(String ticket, String layerPath, String underlyingPath); + + /** + * Takes a layer, deletes it and recreates it pointing at the same underlying + * node. Any changes in the layer are lost (except to history if the layer has been + * snapshotted.) + * @param layerPath + */ + public void resetLayer(String ticket, String layerPath); +}