cancel
Showing results for 
Search instead for 
Did you mean: 

Using aspects/behaviors to alter content

bradw
Champ in-the-making
Champ in-the-making
Hi,

I'm not sure if this question is best suited for this forum or not, but I'll give it a shot.

I have added an aspect to my model, let's call it "encrypted", whose value will depend on certain business rules (i.e. encryption enabled for *some* users, but not others).

My question is, can I attach a behavior in such a way that when this content is accessed (the actual content, not just the node, or other properties of the node), that I can intercept the data and apply encryption/decryption algorithms?

I don't want to store the content encrypted because it doesn't apply to everybody – I want to do it on-the-fly based on the presence of the aspect and the value of that aspect's property.

From what I can tell, the NodeServicesPolicies doesn't have any hook into reading properties, only updating them, so I'm kind of at a dead end.  Maybe this isn't even the right way to go – is there some other event model to hook into?

Any thoughts? Thanks!
Brad
5 REPLIES 5

bradw
Champ in-the-making
Champ in-the-making
I seem to have answered my own question through additional trial/error and browsing the source code.

First off, policies/behaviors weren't the answer.  As I stated in my original post, I have setup and aspect called "encryptable", which contains a property "encryptionLevel".  As each document gets added to the repository, I have a rule setup which will automatically apply the aspect based on mime type.

Now here's where the fun begins.  I started browsing through the source code in order to see what really happens when you attempt to view a node's content.  That led me to the DownloadContentServlet, which has the following code:


   …
   ContentReader reader = contentService.getReader(nodeRef, propertyQName);
   …
   reader.getContent( res.getOutputStream() );

It is the ContentReader which provides the InputStream for the actual content data.

So what I did was to (using the magic of DI), inject my own content service.  This class simply extended the existing RoutingContentService and overrode the getReader() method.

My custom ContentService.getReader() method will now delegate to the superclass to obtain the original ContentReader, and then it will inspect the NodeRef to see if the desired aspect is present. If so, it will check the aspect's property value to see if encryption should be applied.  If not, the original ContentReader is returned, and everying works as normal…

However, if encryption is to be applied, I created a decorated ContentReader (called EncryptedContentReader) which gets returned instead of the original one.  My custom ContentReader will intercept the getContent() and getContentInputStream() methods, and apply the necessary encryption.

The end result is that programatic encryption has been applied based on aspect existance and property values.

Good job Alfresco team!

bradw
Champ in-the-making
Champ in-the-making
Oh, just to avoid confusion – I understand that the aspect's property values will be the same for all users. This is simply a proof of concept test for me, so I chose using an aspect. In real-life this would probably manefest itself as some sort of permission/ACL type of attribute that can be set independantly for each user.

steve
Champ in-the-making
Champ in-the-making
That's nice work Brad!

Steve

pnnerveza
Champ in-the-making
Champ in-the-making
Hi,

i'm looking for a way to incorporate encryption in my space and happened to read your post that might address this. my problem is on how to automatically encrypt (using gpg) all incoming content into a space. gpg from what i know is a command line apps which can be called by other applics like java script. i'm not just sure how to do it in alfresco.

please help

rivarola
Champ on-the-rise
Champ on-the-rise
Hello,

I found your post because I also want to alter content on the fly, but I wonder if wrapping the ContentReader this ways is enough. Can't we run into problems because the getSize method of the FileContentReader will return a value different from the output stream bit count ? Shouldn't the getReader of the custom ContentReader be overriden too, to return an instance of the custom reader ?
Are there other possible traps ?