<div dir="ltr">Allow me some rubber-ducking here..<div><br></div><div>1) Add user attributes (old salt, etc.) when migrating a user<br>2) Implement authenticator that:<br> 2.1) Get user by username/email, if not present, fail<br> 2.2) Retrieve user attributes<br> 2.3) If user attributes include old salt, hence user has been migrated, hash input password (cleartext) and pass it to context.getSession().users().validCredentials(...)</div><div> 2.4) If user attributes don't include old salt, hence user was created in KC, pass input password(cleartext) to context.getSession().users().validCredentials(...)</div><div><br></div><div>If this is proven to work - and there's no better way to do it - one may verify validCredentials(...) return-value, and if it is validated successfully, and the user is migrated, can we replace current user model password with a new one?</div><div><br></div><div>Pires </div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jul 22, 2016 at 10:41 AM Paulo Pires <pires@littlebits.cc> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Updated PR!<div><br></div><div>But now I'm hitting another wall: password migration.</div><div><br></div><div>The app I'm replacing generated a random salt per user, stored it and then used SHA-512(password, iterations, pepper, salt) to hash the password - iterations and pepper are static. Now, I want to import this to Keycloak and use bcrypt to hash the old hash. Obviously, I'll still need to be able to generate the old hash when validating on KC log-in, right?</div><div><br></div><div>I also want that new users to just have bcrypt and not the old hashing thing.</div><div><br></div><div>Now, I know that I can implement a PasswordHashProvider, but I'm not sure exactly where to store and how to read information like the old salt, or how to split between users that were migrated and need to use old hash + brcrypt hash AND users that were created directly in KC and just need bcrypt hash.</div><div><br></div><div>Any help is highly appreciated,</div><div>Pires</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 21, 2016 at 1:46 PM Paulo Pires <pires@littlebits.cc> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Oh, awesome! Going to add tests, open JIRA ticket and update PR.<div><br></div><div>Thanks Stian,</div><div>Pires</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 21, 2016 at 1:13 PM Stian Thorgersen <<a href="mailto:sthorger@redhat.com" target="_blank">sthorger@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>We like cowboy style :)</div><div><br></div><div>Could you add a JIRA please?</div><div><br></div>Also you could add tests to <a href="https://github.com/keycloak/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmTest.java" target="_blank">https://github.com/keycloak/keycloak/blob/master/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/realm/RealmTest.java</a></div><div class="gmail_extra"><br><div class="gmail_quote">On 21 July 2016 at 13:13, Paulo Pires <span dir="ltr"><<a href="mailto:pires@littlebits.cc" target="_blank">pires@littlebits.cc</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I went ahead, cowboy style and opened a PR for it <a href="https://github.com/keycloak/keycloak/pull/3056" target="_blank">https://github.com/keycloak/keycloak/pull/3056</a><div><br></div><div>Couldn't find tests so didn't add any.</div><span><font color="#888888"><div><br></div><div>Pires</div></font></span></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 21, 2016 at 12:06 PM Paulo Pires <pires@littlebits.cc> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Something like this should work though:<div><br><div><div>@GET</div><div>@Produces({"application/json"})</div><div>@Path("default-roles")</div><div>List<RoleRepresentation> getDefaultRoles();</div><div><br></div><div>@PUT</div><div>@Path("default-roles/{roleId}")</div><div>void addDefaultRole(@PathParam("roleId") String roleId);</div><div><br></div><div>@DELETE</div><div>@Path("default-roles/{roleId}")</div><div>void removeDefaultRole(@PathParam("roleId") String roleId);</div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 21, 2016 at 12:03 PM Paulo Pires <pires@littlebits.cc> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It's working like a charm :)</div><div><br></div><div>Some things I learned:</div><div>* Need to import resteasy deps for keycloak-admin-cli explicitly</div><div>* Methods won't return errors but will throw InvocationTargetException (must be checked)</div><div><br></div>Question: is there a way to set default roles? I can't seem to find it in the Java code but it is available through REST.<div><br></div><div>Thanks,</div><div>Pires</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 21, 2016 at 8:47 AM Paulo Pires <pires@littlebits.cc> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you Bruno, I haven't been able to verify your code but I assume you're sharing it because it works.<div><br></div><div>It seems pretty trivial, awesome!</div><div><br></div><div>Cheers,</div><div>Pires</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 20, 2016 at 9:30 PM Bruno Oliveira <<a href="mailto:bruno@abstractj.org" target="_blank">bruno@abstractj.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Note sure if it helps, but an example about how to do it<br>
programatically is here[1].<br>
<br>
I just adapted from the admin-client[2].<br>
<br>
<br>
[1] - <a href="https://gist.github.com/abstractj/78b127e8c9273cdcea6eb82a1cfc153c" rel="noreferrer" target="_blank">https://gist.github.com/abstractj/78b127e8c9273cdcea6eb82a1cfc153c</a><br>
[2] - <a href="https://github.com/keycloak/keycloak/tree/master/examples/admin-client" rel="noreferrer" target="_blank">https://github.com/keycloak/keycloak/tree/master/examples/admin-client</a><br>
<br>
On 2016-07-20, Paulo Pires wrote:<br>
> I did check the admin-cli JAR but it's not clear how to add roles and<br>
> users, or if it's even implemented (I did check the REST API and there's<br>
> endpoints for that).<br>
><br>
> Thank you very much for clarifying,<br>
> Pires<br>
><br>
> On Wed, Jul 20, 2016 at 2:52 PM Stian Thorgersen <<a href="mailto:sthorger@redhat.com" target="_blank">sthorger@redhat.com</a>><br>
> wrote:<br>
><br>
> > Yep, take a look at<br>
> > <a href="https://keycloak.gitbooks.io/server-developer-guide/content/topics/admin-rest-api.html" rel="noreferrer" target="_blank">https://keycloak.gitbooks.io/server-developer-guide/content/topics/admin-rest-api.html</a><br>
> ><br>
> > On 20 July 2016 at 15:33, Paulo Pires <pires@littlebits.cc> wrote:<br>
> ><br>
> >> More than 150k. Is there a Java library for the REST api?<br>
> >><br>
> >> On Jul 20, 2016 13:56, "Stian Thorgersen" <<a href="mailto:sthorger@redhat.com" target="_blank">sthorger@redhat.com</a>> wrote:<br>
> >><br>
> >>> Depending on the amount of users I'd use either partial import through<br>
> >>> the admin console (if you don't have more than a thousand or so users) or<br>
> >>> use the admin REST endpoints if you have quite a lot of users.<br>
> >>><br>
> >>> On 20 July 2016 at 11:52, Paulo Pires <pires@littlebits.cc> wrote:<br>
> >>><br>
> >>>> Hi all,<br>
> >>>><br>
> >>>> I'm in the process of migrating from an in-house user-role storage to<br>
> >>>> Keycloak and I'm looking for programmatic (Java) ways to migrate all<br>
> >>>> current users to the new storage. And I need your help to figure out the<br>
> >>>> best approach.<br>
> >>>><br>
> >>>> At first, when reading KC documentation, I believed I could easily<br>
> >>>> achieve this by implementing a User Federation provider but after diving a<br>
> >>>> little more into it, and looking for examples, I can't see a way to migrate<br>
> >>>> all users on-demand but simply one user at a time, possible during log-in.<br>
> >>>><br>
> >>>> Next, I tried and look into ways, such as admin-cli, REST, etc but<br>
> >>>> nothing strikes me as the solution to use.<br>
> >>>><br>
> >>>> Here's what I was hoping to deliver:<br>
> >>>> * Get all roles and users from my soon-to-be deprecated storage, e.g.<br>
> >>>> MySQL tables<br>
> >>>> * Add roles to KC<br>
> >>>> * Iterate users and add user to KC + map roles + update password hashes<br>
> >>>> (here I know I need to implement a HashProvider)<br>
> >>>><br>
> >>>> Any hints will be appreciated!<br>
> >>>><br>
> >>>> Pires<br>
> >>>><br>
> >>>> _______________________________________________<br>
> >>>> keycloak-user mailing list<br>
> >>>> <a href="mailto:keycloak-user@lists.jboss.org" target="_blank">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>
> >>>><br>
> >>><br>
> >>><br>
> ><br>
<br>
> _______________________________________________<br>
> keycloak-user mailing list<br>
> <a href="mailto:keycloak-user@lists.jboss.org" target="_blank">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>
<br>
<br>
--<br>
<br>
abstractj<br>
PGP: 0x84DC9914<br>
</blockquote></div></blockquote></div></blockquote></div></blockquote></div>
</div></div></blockquote></div><br></div>
</blockquote></div></blockquote></div></blockquote></div>