Home

Alfresco as you know is open source Content Management system and having strong Content management features. But as we know each client has their own set of requirements where they might want to customize existing functionality or create new feature in Alfresco or integrate it with other technology. For making all of this feasible Alfresco has provided set of Services on top of alfresco repository through which we can manipulate that repository.

Now alfresco has taken care that although we can do customization using those services all critical operations like creation of contents, deletion of content etc… has to be done explicitly through System user or user with proper privileges. For implementing this security feature they has created APIs within AuthenticationUtils class.

Details of Those apis are as follow.

public static String getSystemUserName()

Get the name of the system user

Returns: system user name

public static net.sf.acegisecurity.Authentication setRunAsUserSystem()

Set the system user as the currently running user for authentication purposes.

public static <R> R runAs(AuthenticationUtil.RunAsWork<R> runAsWork, String uid)

Execute a unit of work as a given user. The thread’s authenticated user will be returned to its normal state after the call.

Parameters:

runAsWork – the unit of work to do

uid – the user ID

Returns:

Returns the work’s return value

This is how it would look like when you implement it in your code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private void assoicate(final NodeRef sourceRef,final NodeRef destRef,
final QName assocTypeQName) {
RunAsWork<Void> processNodesWork = new RunAsWork<Void>() {
public Void doWork() throws Exception {
// Piece of block which needs to be run as system
return null;
}};
AuthenticationUtil.runAs(processNodesWork, AuthenticationUtil.getSystemUserName());
}

Keep in mind this has to be used with caution. If you try to retrieve user name within that blog it will return as system because for that particular execution user is system. One more point is that all external variables which are used in that block has to be defined as final that is the reason all parameters of that method are all final.

You can also return value from that piece of code incase require. For instance you are creating new node within that block you can always return that ndoeRef but you need to define that return type.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Publicités

Laisser un commentaire

Choisissez une méthode de connexion pour poster votre commentaire:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s