<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to lock document by admin Java in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139061#M37220</link>
    <description>&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 13:04:24 GMT</pubDate>
    <dc:creator>afaust</dc:creator>
    <dc:date>2021-01-29T13:04:24Z</dc:date>
    <item>
      <title>How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139060#M37219</link>
      <description>&lt;P&gt;I have part of code, which runs as system&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;AuthenticationUtil.&lt;SPAN&gt;runAsSystem&lt;/SPAN&gt;(() -&amp;gt; {...}&lt;/PRE&gt;&lt;P&gt;and in it i lock document&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;lockService&lt;/SPAN&gt;.lock(&lt;SPAN&gt;nodeRef&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;LockType.&lt;SPAN&gt;WRITE_LOCK&lt;/SPAN&gt;)&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I also tried this code&lt;/P&gt;&lt;PRE&gt;AuthenticationUtil.&lt;SPAN&gt;runAs&lt;/SPAN&gt;(() -&amp;gt; {...}, "admin");&lt;/PRE&gt;&lt;P&gt;but document locks by current user (user, which authorized&amp;nbsp;in now). I wan't do it by "admin" username. How can i do it?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 08:10:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139060#M37219</guid>
      <dc:creator>Skyor</dc:creator>
      <dc:date>2021-01-29T08:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139061#M37220</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 13:04:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139061#M37220</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-01-29T13:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139062#M37221</link>
      <description>&lt;P&gt;Thank you! Perfect solution for me.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 08:18:53 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139062#M37221</guid>
      <dc:creator>Skyor</dc:creator>
      <dc:date>2021-02-01T08:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139063#M37222</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/82721"&gt;@Skyor&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Great this helped &amp;amp; thanks for accepting the solution - really helpful to other users.&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 10:34:19 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139063#M37222</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2021-02-01T10:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139064#M37223</link>
      <description>&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt;&amp;nbsp;that solution works but not for the "System" username. After executing those lines below,&amp;nbsp; `&lt;FONT face="courier new,courier"&gt;AuthenticationService.getCurrentUserName()&lt;/FONT&gt;` still returns "admin" instead of "system".&lt;/P&gt;&lt;PRE&gt;AuthenticationUtil.pushAuthentication();&lt;BR /&gt;AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());&lt;/PRE&gt;&lt;P&gt;I tried to set manually&amp;nbsp;&amp;nbsp;&lt;EM&gt;PROP_LOCK_OWNER&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;PROP_MODIFIER &lt;/EM&gt;but I faced many issues.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 10:54:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139064#M37223</guid>
      <dc:creator>upforsin</dc:creator>
      <dc:date>2021-07-05T10:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139065#M37224</link>
      <description>&lt;P&gt;The functionality via AuthenticationUtil makes no distinction between users - it either works for all or for none Of course other components / code - custom or part of core - could potentially not properly respect the state of AuthenticationUtil, or override it after you set it. Without knowing any of your code / other customisation (e.g. use of an authentication component which may not properly respect AuthenticationUtil), it's hard to know what is the issue in your case.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 12:35:02 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139065#M37224</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-07-05T12:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139066#M37225</link>
      <description>&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt;thank you for the quick response, it's probably just like you said - &lt;EM&gt;authenticationService&lt;/EM&gt; does not respect &lt;EM&gt;AuthenticationUtils&lt;/EM&gt; state. But how to make it respect?&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is my code which should lock the given nodeRef as the System user.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;try {&lt;BR /&gt;    AuthenticationUtil.pushAuthentication();&lt;BR /&gt;    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());&lt;BR /&gt;&lt;BR /&gt;    NodeRef childRef = child.getChildRef();&lt;BR /&gt;    ownableSerice.setOwner(childRef, AuthenticationUtil.SYSTEM_USER_NAME);&lt;BR /&gt;    lockService.lock(childRef, LockType.READ_ONLY_LOCK); // inside it uses authenticationService.getCurrentUserName()&lt;BR /&gt;    }&lt;BR /&gt;} finally {&lt;BR /&gt;    AuthenticationUtil.popAuthentication();&lt;BR /&gt;}&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;After executing this code both&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;cm:lockOwner&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;cm:modifier&lt;/FONT&gt; are set to "admin" instead of "system"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 12:51:29 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139066#M37225</guid>
      <dc:creator>upforsin</dc:creator>
      <dc:date>2021-07-05T12:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139067#M37226</link>
      <description>&lt;P&gt;The cm:modifier is likely set to admin because that property can potentially be set after popAuthentication as part of the transaction commit handling, due to delayed policies / transaction listeners.&lt;/P&gt;
&lt;P&gt;"But how to make it respect?" - Well, first by finding out how it actually does not respect it and then potentially having that fixed (if it comes from a third-party addon or is some other custom code), or switching over to a more default implementation. There will generally be no way to "make it respect" in your client code alone.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 09:23:56 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139067#M37226</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-07-06T09:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to lock document by admin Java</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139068#M37227</link>
      <description>&lt;P&gt;Thank you for this solution. I also have the same case.&amp;nbsp;The software development with&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://mlsdev.com/" target="_blank" rel="noopener nofollow noreferrer"&gt;mlsdev.com&lt;/A&gt;&lt;/SPAN&gt; process refers to a series of activities aimed at the execution and delivery of software application designed by using the software's designing tools. This software development service is carried out by software engineers who have a broad range of skills and experience in software design, software implementation and software testing. They develop software according to clients' specifications and integrate it into a business environment. A software developer who works as a team to deliver an application is also called a Software Development Service Provider.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jul 2021 11:51:39 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/how-to-lock-document-by-admin-java/m-p/139068#M37227</guid>
      <dc:creator>martalinols</dc:creator>
      <dc:date>2021-07-07T11:51:39Z</dc:date>
    </item>
  </channel>
</rss>

