How to lock document by admin Java

cancel
Showing results for 
Search instead for 
Did you mean: 
Skyor
Active Member

How to lock document by admin Java

Jump to solution

I have part of code, which runs as system 

AuthenticationUtil.runAsSystem(() -> {...}

and in it i lock document

lockService.lock(nodeRef, LockType.WRITE_LOCK);

 I also tried this code

AuthenticationUtil.runAs(() -> {...}, "admin");

but document locks by current user (user, which authorized in now). I wan't do it by "admin" username. How can i do it?

1 Solution

Accepted Solutions
afaust
Master

Re: How to lock document by admin Java

Jump to solution

You can use AuthenticationUtil.pushAuthentication() + AuthenticationUtil.setFullyAuthenticatedUser() + custom code + AuthenticationUtil.popAuthentication() to temporarily switch the entire authenticated user, which should deal with your case. Just make sure you do the push/pop of the authentication context in a try-finally block.

View solution in original post

3 Replies
afaust
Master

Re: How to lock document by admin Java

Jump to solution

You can use AuthenticationUtil.pushAuthentication() + AuthenticationUtil.setFullyAuthenticatedUser() + custom code + AuthenticationUtil.popAuthentication() to temporarily switch the entire authenticated user, which should deal with your case. Just make sure you do the push/pop of the authentication context in a try-finally block.

View solution in original post

Skyor
Active Member

Re: How to lock document by admin Java

Jump to solution

Thank you! Perfect solution for me.

EddieMay
Community Manager
Community Manager

Re: How to lock document by admin Java

Jump to solution

Hi @Skyor 

Great this helped & thanks for accepting the solution - really helpful to other users.

Cheers,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!