Many time we need to perform certain operations in alfresco which needs system user access.
Using following code snippet we can use system user and restore back it to normal user authentication.
Note : alfresco 4 Enterprise version considered as of now
try { final Authentication authentication = AuthenticationUtil.getFullAuthentication(); AuthenticationUtil.setRunAsUserSystem(); // do your operation here } finally { AuthenticationUtil.clearCurrentSecurityContext(); AuthenticationUtil.setFullAuthentication(authentication); }
it is necessary to use a finally block to be sure that the authentication is set back to the initial value
ReplyDelete