<div dir="ltr"><div>Hello Reed,</div><div><br></div><div>as you already wrote, you can write a federation provider that queries your</div><div>backend service via REST for user data.</div><div>Within the federation provider you can then import the user data </div><div>returned from the REST call. </div><div><br></div><div>This would work as follows - within the method:</div><div> org.keycloak.models.UserFederationProvider.getUserByUsername(RealmModel, String)</div><div>you call your backend REST service.</div><div><br></div><div>As a next step you create a new user with the given username</div><div> UserModel keycloakUser = session.userStorage().addUser(realm, username);</div><div><br></div><div>Then you copy all the user data from your backend into Keycloak's UserModel.</div><div><br></div><div>After that your backend user has a corresponding representation in Keycloak</div><div>with a reference to this federation provider (id) via the "userModel.federationLink" property.</div><div><br></div><div>The federation link will also be shown in the user page in the keycloak admin console.</div><div>As long as the federation link is in place keycloak will ask the federation provider </div><div>for the latest user data. Once you decide to cut the link to the federation provider you can </div><div>simply do userModel.setFederationLink(null). You could basically cut (or rather omit) the federation</div><div> link right after you added the user to Keycloak.</div><div><br></div><div>Keycloak has no link information after that anymore and it will only use the user data stored</div><div>in the Keycloak database for that particular user.</div><div><br></div><div>You also have the option to do that for all your users via:</div><div> org.keycloak.models.UserFederationProviderFactory.syncAllUsers(KeycloakSessionFactory, String, UserFederationProviderModel)<br></div><div>or just use on demand per User when he / she want's to login for the first time.</div><div><br></div><div>Cheers,</div><div>Thomas</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-01-15 16:16 GMT+01:00 Reed Lewis <span dir="ltr"><<a href="mailto:RLewis@carbonite.com" target="_blank">RLewis@carbonite.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Calibri,sans-serif">
<div>Hi,</div>
<div> We are examining KeyCloak (It looks like it can do what we want), but we have the need to have an external lookup of accounts who are not in KeyCloak in an external database which is accessible via a REST call. I know about federation, but would prefer
to only check the external datasource if the user is not in KeyCloak, but from then on have all the data “live” in KeyCloak and never refer to the external datasource again once the account is “migrated” into KeyCloak.</div>
<div><br>
</div>
<div><br>
</div>
<div>Can this be done with some modification of federation? </div>
<div><br>
</div>
<div>We do not want to add the user accounts directly into KeyCloak as there are many more there than will ever be in KeyCloak.</div>
<div><br>
</div>
<div>Thank you,</div>
<div><br>
</div>
<div>Reed Lewis</div>
<div><br>
</div>
<div> </div>
<div>
<div></div>
</div>
</div>
<br>_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br></blockquote></div><br></div>