<div dir="ltr">Hi Stian,<div><br></div><div>thanks for your reply. We&#39;ve actually come up with a totally different approach in the meantime. We now ask our back-end for a domain specific token every time an object that requires a custom role mapping is selected in the UI. We then replace the token in keycloak.js. The back-end uses keycloak-core in order to create tokens (inspired by <a href="https://github.com/liveoak-io/liveoak/blob/master/modules/keycloak/src/test/java/io/liveoak/keycloak/TokenUtil.java">https://github.com/liveoak-io/liveoak/blob/master/modules/keycloak/src/test/java/io/liveoak/keycloak/TokenUtil.java</a>).</div>
<div><br></div><div>Cheers,</div><div>Nils</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 26, 2014 at 9:32 AM, Stian Thorgersen <span dir="ltr">&lt;<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This sounds like a feature that our adapter should provide so I would say if you can come up with a decent way to add it, then we&#39;d probably be more than happy to pull it in.<br>

<br>
We could enable multi-tenancy support in keycloak.json by allowing multiple sets of configs with one or more url-patterns to match what config to use. For example:<br>
<br>
[<br>
  {<br>
    &quot;realm&quot; : &quot;example&quot;,<br>
    &quot;resource&quot; : &quot;app1&quot;,<br>
    ...<br>
    &quot;url-pattern&quot; : [ &quot;/app1/*&quot;, &quot;/myapp/*&quot; ]<br>
  },<br>
  {<br>
    &quot;realm&quot; : &quot;example2&quot;,<br>
    &quot;resource&quot; : &quot;app2&quot;,<br>
    ...<br>
    &quot;url-pattern&quot; : [ &quot;<a href="http://app2.org/*" target="_blank">http://app2.org/*</a>&quot; ]<br>
  }<br>
]<br>
<div class="HOEnZb"><div class="h5"><br>
----- Original Message -----<br>
&gt; From: &quot;Nils Preusker&quot; &lt;<a href="mailto:n.preusker@gmail.com">n.preusker@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; Sent: Tuesday, 12 August, 2014 7:01:33 PM<br>
&gt; Subject: Re: [keycloak-user] Multitenancy for WAR<br>
&gt;<br>
&gt; Hi Bill,<br>
&gt;<br>
&gt; it&#39;s been a while since we discussed this but I thought I&#39;d add my question<br>
&gt; to this thread since it is related. I&#39;m now looking into authorizing<br>
&gt; requests based on domain specific permissions.<br>
&gt;<br>
&gt; Here&#39;s the use case:<br>
&gt; We have one war that serves as a REST-back-end for a JavaScript application.<br>
&gt; We&#39;ve successfully secured the application (AngularJS with keycloak.js in<br>
&gt; the front-end, WAR on Wildfly 8 with JAX-RS/ RestEasy in the back-end) with<br>
&gt; keycloak (beta-2). Now, instead of using the role mapping in the OAuth<br>
&gt; token, we&#39;d like to be able to determine the users&#39; role mappings based on a<br>
&gt; path parameter in the HTTP request to the REST-back-end.<br>
&gt;<br>
&gt; For example, if the URL is &#39;/my-app/1/some-resource&#39;, we need to check<br>
&gt; whether the user has an account in &#39;my-app 1&#39; (which is an entry in the<br>
&gt; applications database) and add the respective roles (also from the<br>
&gt; applications database), if the URL is /my-app/2/... the same needs to happen<br>
&gt; for &#39;my-app 2&#39; etc.<br>
&gt;<br>
&gt; The idea would be to add some kind of security interceptor which extracts the<br>
&gt; keycloak user id, matches the id to the domain user (user from e.g. my-app<br>
&gt; 1), and adds the role mapping of the domain user. Since we&#39;d like to<br>
&gt; continue using the EJB annotations (RolesAllowed etc.), we&#39;d need to make<br>
&gt; sure those domain users&#39; roles are propagated to the security context.<br>
&gt;<br>
&gt; So the question is, would you recommend extending the keycloak login module?<br>
&gt; Or can you think of an easier way like e.g. a web filter?<br>
&gt;<br>
&gt; Cheers!<br>
&gt; Nils<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; My question is whether to extend the wildfly adapter (KeycloakLoginModule) or<br>
&gt; to<br>
&gt;<br>
&gt;<br>
&gt; On Sun, Jun 1, 2014 at 5:57 PM, Nils Preusker &lt; <a href="mailto:n.preusker@gmail.com">n.preusker@gmail.com</a> &gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; Hi Bill,<br>
&gt;<br>
&gt; The more I think about it the more it makes sense to me that the tenant or<br>
&gt; application instance is indeed part of the applications data model and not<br>
&gt; part of keycloak. Especially since we want to add tenants at runtime, it<br>
&gt; wouldn&#39;t be possible to have a check without hitting the db.<br>
&gt;<br>
&gt; About cross realm users, I totally agree! I also don&#39;t like the idea and I&#39;m<br>
&gt; hoping and guessing that we won&#39;t really need it in the end.<br>
&gt;<br>
&gt; Thanks for the discussion!<br>
&gt; Nils<br>
&gt;<br>
&gt; &gt; On 01 Jun 2014, at 13:28, Bill Burke &lt; <a href="mailto:bburke@redhat.com">bburke@redhat.com</a> &gt; wrote:<br>
&gt; &gt;<br>
&gt; &gt; We already support some form of multi-tenancy. One keycloak server can<br>
&gt; &gt; serve up multiple realms.<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; For multitenant-apps was thinking of a app or service that needs to<br>
&gt; &gt; support multiple isolated realms.<br>
&gt; &gt;<br>
&gt; &gt; For bearer-only services, there would just be a list of realms that are<br>
&gt; &gt; supported and the keycloak adapter would just look into the bearer token<br>
&gt; &gt; to know which realm to validate the token with. For browser apps, they<br>
&gt; &gt; need to be able to know which realm you are authenticating against, so I<br>
&gt; &gt; thought the desired realm would be extracted from the URL.<br>
&gt; &gt;<br>
&gt; &gt; I balk at your use-case because I don&#39;t like the idea of cross-realm users.<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;&gt; On 6/1/2014 4:02 AM, Nils Preusker wrote:<br>
&gt; &gt;&gt; The only issue is that we might need to be able to assign different<br>
&gt; &gt;&gt; roles to the same user in different application instances.<br>
&gt; &gt;<br>
&gt; &gt; What you could do, is not use the keycloak adapter and just hand code<br>
&gt; &gt; your interactions via our oauth client api. Then your application<br>
&gt; &gt; service could figure out which realm and application instance the user<br>
&gt; &gt; was logging however it wanted and and pass that information along when<br>
&gt; &gt; you start the oauth protocol flow. Following me?<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; Bill Burke<br>
&gt; &gt; JBoss, a division of Red Hat<br>
&gt; &gt; <a href="http://bill.burkecentral.com" target="_blank">http://bill.burkecentral.com</a><br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; keycloak-user mailing list<br>
&gt; &gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</div></div></blockquote></div><br></div>