<?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 Rest API authentication with Keycloak in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/rest-api-authentication-with-keycloak/m-p/121314#M33293</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm integrating the alfresco rest API with an external application. using the latest version of Alfresco configured with Keyclok as an identity server with the open-source module provided by &lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt; (&lt;STRONG&gt;&lt;A href="https://github.com/Acosix/alfresco-keycloak" target="_blank" rel="noopener nofollow noreferrer"&gt;alfresco-keycloak&lt;/A&gt;&lt;/STRONG&gt;).&lt;/P&gt;&lt;P&gt;Keycloak has been configured with 2 different realms each one with its user provider and roles and Alfresco has been configured with 2 Authentication subsystems and different Keycloak adapters:&lt;/P&gt;&lt;PRE&gt;        -Dauthentication.chain=keycloak1:keycloak,keycloak2:keycloak
        -Dsynchronization.import.cron=\"0 0 0/4 ? * * *\"
        -Dsynchronization.allowDeletions=true"&lt;/PRE&gt;&lt;P&gt;This configuration works well when logging in through Alfresco Share, chaining across each subsystem until the user logs in successfully.&lt;/P&gt;&lt;P&gt;But the same configuration won't work with the Alfresco public API. When my external application calls an endpoint with a valid Bearer token Alfresco uses just the first of two adapters configured so if my token has been released by the last keycloak realm it always fails and a 401 error is returned.&lt;/P&gt;&lt;P&gt;I can't find any solution to this problem or any documentation about that. I can't understand if the authorization mechanism used to authorize for rest-API doesn't use the same security chain as Alfresco Share.&lt;/P&gt;&lt;P&gt;Does anybody else have the same problem and found a solution to fix it?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Stefano&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2022 09:48:44 GMT</pubDate>
    <dc:creator>sveloccia</dc:creator>
    <dc:date>2022-11-07T09:48:44Z</dc:date>
    <item>
      <title>Rest API authentication with Keycloak</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/rest-api-authentication-with-keycloak/m-p/121314#M33293</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I'm integrating the alfresco rest API with an external application. using the latest version of Alfresco configured with Keyclok as an identity server with the open-source module provided by &lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt; (&lt;STRONG&gt;&lt;A href="https://github.com/Acosix/alfresco-keycloak" target="_blank" rel="noopener nofollow noreferrer"&gt;alfresco-keycloak&lt;/A&gt;&lt;/STRONG&gt;).&lt;/P&gt;&lt;P&gt;Keycloak has been configured with 2 different realms each one with its user provider and roles and Alfresco has been configured with 2 Authentication subsystems and different Keycloak adapters:&lt;/P&gt;&lt;PRE&gt;        -Dauthentication.chain=keycloak1:keycloak,keycloak2:keycloak
        -Dsynchronization.import.cron=\"0 0 0/4 ? * * *\"
        -Dsynchronization.allowDeletions=true"&lt;/PRE&gt;&lt;P&gt;This configuration works well when logging in through Alfresco Share, chaining across each subsystem until the user logs in successfully.&lt;/P&gt;&lt;P&gt;But the same configuration won't work with the Alfresco public API. When my external application calls an endpoint with a valid Bearer token Alfresco uses just the first of two adapters configured so if my token has been released by the last keycloak realm it always fails and a 401 error is returned.&lt;/P&gt;&lt;P&gt;I can't find any solution to this problem or any documentation about that. I can't understand if the authorization mechanism used to authorize for rest-API doesn't use the same security chain as Alfresco Share.&lt;/P&gt;&lt;P&gt;Does anybody else have the same problem and found a solution to fix it?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Stefano&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 09:48:44 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/rest-api-authentication-with-keycloak/m-p/121314#M33293</guid>
      <dc:creator>sveloccia</dc:creator>
      <dc:date>2022-11-07T09:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API authentication with Keycloak</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/rest-api-authentication-with-keycloak/m-p/121315#M33294</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;The way Alfresco's SSO handling works is a bit different then normal username + password authentication. The latter chains over all subsystems, whereas by design, the SSO handling only works for the first SSO-enabled subsystem. Similarily, the RemoteUserMapper which - dependending on subsystem - can extract user names from headers / handle bearer tokens, is also only called for the first subsystem which provides such a component. This is why the alfresco-keycloak module by default also only handles a Bearer token via the first instance. But I have actually run into this kind of problem in a customer project, albeit not with two Keycloak realms but with a custom-built "magic cookie" authentication subsystem. In my alfresco-utility project - which is a dependency for alfresco-keycloak - I provide a &lt;A href="https://github.com/Acosix/alfresco-utility/blob/master/core/repository/src/main/java/de/acosix/alfresco/utility/repo/subsystems/SubsystemChainingRemoteUserMapper.java" target="_self" rel="nofollow noopener noreferrer"&gt;chaining RemoteUserMapper implementation&lt;/A&gt;. Unfortunately, I have not included a prepared patch that can simply be enabled (which I really should have), and at this time, it would be necessary to manually apply that via a Spring override context XML file, i.e. in alfresco/extension/authentication-services-override-context.xml (the path I used in the customer's project). Such a context file would only need to contain the following bean:&lt;/P&gt;
&lt;PRE&gt;    &amp;lt;!-- default proxy has "first active wins" semantic, we want "first successful wins" --&amp;gt;
    &amp;lt;bean id="RemoteUserMapper" class="de.acosix.alfresco.utility.repo.subsystems.SubsystemChainingRemoteUserMapper"&amp;gt;
        &amp;lt;property name="applicationContextManager" ref="Authentication" /&amp;gt;
        &amp;lt;property name="sourceBeanName" value="remoteUserMapper" /&amp;gt;
    &amp;lt;/bean&amp;gt;&lt;/PRE&gt;
&lt;P&gt;I hope this helps in your case. If it does, please get back to me and ideally also raise a new issue in alfresco-keycloak, so that I have a reminder to include that in documentation as well as provide a pre-bundled patch in future versions.&lt;/P&gt;
&lt;P&gt;Note that this patch would onyl fix the "two realms" use case for the Repository-tier (ACS), not Share SSO. Share SSO has not been designed at all to support multiple SSO authentication instances, there are no preparations in alfresco-keycloak to support this, and it would take some significant refactoring effort to achieve this within the Share architecture. So for Share, only username + password authentication with multiple Keycloak realms is supported.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 12:17:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/rest-api-authentication-with-keycloak/m-p/121315#M33294</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2022-11-08T12:17:15Z</dc:date>
    </item>
  </channel>
</rss>

