<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I’d recommend using a federation provider. Others may have another opinion but here’s the approach I like, using a federation provider:</div><div class=""><br class=""></div><div class="">Create the user when Keycloak calls one of these methods on the federation provider and the user exists in the legacy system:</div><div class=""><br class=""></div><div class="">UserFederationProvider.getUserByUsername()</div><div class="">UserFederationProvider.getUserByEmail()</div><div class=""><br class=""></div><div class="">This creates the federation link. However, do not set a password for the user yet (you wouldn’t know what to set it to yet anyway). Then, when Keycloak calls:</div><div class=""><br class=""></div><div class="">UserFederationProvider.validCredentials(RealmModel realm,&nbsp;UserModel user,&nbsp;List&lt;UserCredentialModel&gt; input)</div><div class=""><br class=""></div><div class="">query your legacy system to see if the given user and password combination is valid. If so:</div><div class=""><br class=""></div><div class="">1. Update the user (in Keycloak) to have password supplied in List&lt;UserCredentialModel&gt; input</div><div class="">2. Break the federation link (session.userStorage().getUserById(user.getId(),&nbsp;realm).setFederationLink(null);)</div><div class=""><br class=""></div><div class="">I’m going to publish a template for migrating users using this approach soon. For now, I hope this is enough to get you going in the right direction if you choose the federation provider approach.</div><div class=""><br class=""></div><div class="">~ Scott</div><br class=""><div apple-content-edited="true" class="">
<div class="">Scott Rossillo</div><div class="">Smartling | Senior Software Engineer</div><div class=""><a href="mailto:srossillo@smartling.com" class="">srossillo@smartling.com</a></div><div class=""><br class=""></div><div class=""><a href="https://app.sigstr.com/uc/55e5d41c6533390d03580000" id="campaignblock" target="_blank" style="box-sizing: border-box; color: rgb(0, 75, 118); outline-offset: -2px; font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255); outline: 0px !important;" class=""><img alt="Latest News + Events" border="0" src="https://app.sigstr.com/uc/55e5d41c6533390d03580000/img" style="box-sizing: border-box; border: 0px; vertical-align: top; max-width: 100%; height: auto; width: inherit; color: blue; font-family: Helvetica; font-size: 12px;" class=""></a><span style="color: rgb(169, 169, 169); font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255);" class=""></span><div id="watermark" style="box-sizing: border-box; color: rgb(169, 169, 169); font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255);" class=""><a href="http://www.sigstr.com/" style="box-sizing: border-box; color: rgb(0, 124, 194); text-decoration: none; background-color: transparent; outline: 0px !important;" class=""><img alt="Powered by Sigstr" border="0" src="https://app.sigstr.com/uc/55e5d41c6533390d03580000/watermark" style="box-sizing: border-box; border: 0px; vertical-align: top; max-width: 100%; height: auto; width: inherit; color: rgb(99, 99, 99); font-family: Helvetica; font-size: 11px;" class=""></a></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Oct 5, 2015, at 11:59 AM, Remi Cartier &lt;<a href="mailto:remi.cartier@imetrik.com" class="">remi.cartier@imetrik.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class="">

<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hey guys,
<div class=""><br class="">
</div>
<div class="">I will have to migrate from a custom in house user management system to keycloak.</div>
<div class="">We are using this algorithm to store salted/hashed password :</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">&nbsp; &nbsp; public static String hashPassword(String password, String salt) {</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; try {</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 2048, 160);</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] hash = secretKeyFactory.generateSecret(keySpec).getEncoded();</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new BigInteger(1, hash).toString(16);</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception x) {</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new IllegalStateException(x);</div>
<div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div>
<div class="">&nbsp; &nbsp; }</div>
<div class=""><br class="">
</div>
<div class="">I was wondering, in order to ease the migration, if I could configure keycloak to use the same hash algorithm ?</div>
<div class=""><br class="">
</div>
<div class="">Or if there was any other ways ? Like maybe a federation provider, but then comes the question when to push things into keycloak, at password change ?</div>
<div class=""><br class="">
</div>
<div class="">What do you think ?</div>
<div class=""><br class="">
</div>
<div class="">Sincerely.</div>
<div class=""><br class="Apple-interchange-newline">
<hr align="left" border-color:#40ae49;="" style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px; border: 0px; width: 320px; height: 1px; background-color: rgb(64, 174, 73);" class=""><p class="MsoNormal" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; orphans: 2; widows: 2; margin: 0cm 0cm 1pt;">
<br style="color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; orphans: auto; widows: auto;" class="">
<span style="color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; orphans: auto; widows: auto; text-transform: uppercase;" class="">REMI CARTIER</span><br style="color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; font-size: 12px; line-height: 14px; orphans: auto; widows: auto;" class="">
</p>
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="text-align: -webkit-auto; line-height: 14px;" class=""><font color="#666666" face="Helvetica, Arial, sans-serif" class="">B.O.S.S. (Business &amp; Operation Support Systems) P.O (Product Owner)</font></span></div>
<br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<strong style="font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(64, 174, 73); font-family: Helvetica, Arial, sans-serif; line-height: 14px; text-transform: uppercase;" class="">IMETRIK
 GLOBAL INC.</strong><span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">&nbsp;</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<strong style="font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">T
 :</strong><span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">&nbsp;+1
 514 448-6407 x2009</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<strong style="font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">T
 :</strong><span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">&nbsp;+1
 866 276-5382 (toll free)&nbsp;</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<strong style="font-size: 12px; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">F
 :</strong><span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">&nbsp;+1
 514 904-0611&nbsp;</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">740
 Notre Dame St. West, Suite 1575&nbsp;</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<span style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">Montreal,
 Quebec, Canada H3C 3X6&nbsp;</span><br style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(102, 102, 102); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">
<a href="http://www.imetrik.com/" target="_blank" style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(64, 174, 73); font-family: Helvetica, Arial, sans-serif; line-height: 14px;" class="">imetrik.com</a>
</div>
<br class="">
</div>
</div>

_______________________________________________<br class="">keycloak-user mailing list<br class=""><a href="mailto:keycloak-user@lists.jboss.org" class="">keycloak-user@lists.jboss.org</a><br class="">https://lists.jboss.org/mailman/listinfo/keycloak-user</div></blockquote></div><br class=""></body></html>