<?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: Can not setAuthenticatedUserId in rest API if there is customization authentication in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185926#M139056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In your overrided &lt;/SPAN&gt;&lt;EM&gt;authenticate&lt;/EM&gt;&lt;SPAN&gt; method you need to return the user id that should be used.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your application uses custom authentication, you need to extract the current authenticated user id from the request. One way of doing that is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[java]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;public String authenticate(Request request, Response response) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; // use org.restlet.ext.servlet.ServletUtils to get HttpServletRequest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; String userId = // Add whatever logic to retrieve user id to be used&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return userId;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/java]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to use another user id (other than the current authenticated user id) for the initiator then you need to use a custom implementation of &lt;/SPAN&gt;&lt;EM&gt;ProcessInstanceCollectionResource&lt;/EM&gt;&lt;SPAN&gt; class and call &lt;/SPAN&gt;&lt;EM&gt;identityService.setAuthenticatedUserId&lt;/EM&gt;&lt;SPAN&gt; before starting the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Note that Restlet was replaced by Spring MVC since Activiti 5.16.4&lt;/EM&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 19 Jul 2015 04:00:08 GMT</pubDate>
    <dc:creator>balsarori</dc:creator>
    <dc:date>2015-07-19T04:00:08Z</dc:date>
    <item>
      <title>Can not setAuthenticatedUserId in rest API if there is customization authentication</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185925#M139055</link>
      <description>Hello everyone,As we know, we can set the initiator like below code :&amp;lt;startEvent id="request" activiti:initiator="initiator" /&amp;gt;The authenticated user must be set with the method BEFORE the process instance is started,try {&amp;nbsp; identityService.setAuthenticatedUserId("bono");&amp;nbsp; runtimeService.startP</description>
      <pubDate>Wed, 15 Jul 2015 07:35:55 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185925#M139055</guid>
      <dc:creator>youtianhong</dc:creator>
      <dc:date>2015-07-15T07:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can not setAuthenticatedUserId in rest API if there is customization authentication</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185926#M139056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In your overrided &lt;/SPAN&gt;&lt;EM&gt;authenticate&lt;/EM&gt;&lt;SPAN&gt; method you need to return the user id that should be used.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If your application uses custom authentication, you need to extract the current authenticated user id from the request. One way of doing that is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[java]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;public String authenticate(Request request, Response response) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; // use org.restlet.ext.servlet.ServletUtils to get HttpServletRequest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; String userId = // Add whatever logic to retrieve user id to be used&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return userId;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/java]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to use another user id (other than the current authenticated user id) for the initiator then you need to use a custom implementation of &lt;/SPAN&gt;&lt;EM&gt;ProcessInstanceCollectionResource&lt;/EM&gt;&lt;SPAN&gt; class and call &lt;/SPAN&gt;&lt;EM&gt;identityService.setAuthenticatedUserId&lt;/EM&gt;&lt;SPAN&gt; before starting the process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;Note that Restlet was replaced by Spring MVC since Activiti 5.16.4&lt;/EM&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Jul 2015 04:00:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185926#M139056</guid>
      <dc:creator>balsarori</dc:creator>
      <dc:date>2015-07-19T04:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can not setAuthenticatedUserId in rest API if there is customization authentication</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185927#M139057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Much Thanks balsarori for your detailed response.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Actuallty, I also thought that override ProcessInstanceCollectionResource&amp;nbsp; class and call identityService.setAuthenticatedUserId to solve this issue. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But this still has a problem, though this customization class can write the userId correctlly when we start a process instance, however we do other actions subsequently like 'claim task', 'complete task' etc, it will be overridden by "System user" which was written in 'authenticate' method again, because we know that every rest method has a validataion process like "if (!authenticate()) return null;" before invoking real API.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So I think we still need to modify 'authenticate' method, and receive the real userId in the client side.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to encapsulate rest api client side code, it's&amp;nbsp; like ActivitiClient.jar that can be embed in other web application.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So i don't how to create a dummy HttpServletRequest,Since HttpServletRequest is an interface &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;that is implemented by other web container&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tested it like you mention as below code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;code&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; // use org.restlet.ext.servlet.ServletUtils to get HttpServletRequest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpServletRequest servletRequest = ServletUtils.getRequest(restletRequest);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//client side java code&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; org.restlet.resource.ClientResource clientResource = new ClientResource(uri);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; clientResource.setReference(uri);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; ClientInfo clientInfo = new ClientInfo();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; org.restlet.security.User user = new User();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; user.setIdentifier("Frank");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; clientInfo.setUser(user);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; clientResource.setClientInfo(clientInfo);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; //the other way&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; org.restlet.Request request = clientResource.createRequest();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Map map = new HashMap();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; map.put("user", "ygq");&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; request.setAttributes(map);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;/code&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For my debug in service side, I did not find the attribute in restletRequest or HttpServletRequest,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you know how to set this parameter in restlet client or how to&amp;nbsp; create a dummy HttpServletRequest ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks a lot again!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Frank&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jul 2015 03:57:34 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/can-not-setauthenticateduserid-in-rest-api-if-there-is/m-p/185927#M139057</guid>
      <dc:creator>youtianhong</dc:creator>
      <dc:date>2015-07-21T03:57:34Z</dc:date>
    </item>
  </channel>
</rss>

