<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Olga Totskaya on Medium]]></title>
        <description><![CDATA[Stories by Olga Totskaya on Medium]]></description>
        <link>https://medium.com/@olgaatsmartling?source=rss-a0e471c44840------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*6fLFdS2OOzJ1qC9I.jpg</url>
            <title>Stories by Olga Totskaya on Medium</title>
            <link>https://medium.com/@olgaatsmartling?source=rss-a0e471c44840------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:01:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olgaatsmartling/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Migrate to Keycloak with Zero Downtime]]></title>
            <link>https://medium.com/@olgaatsmartling/migrate-to-keycloak-with-zero-downtime-7ae232c07a78?source=rss-a0e471c44840------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ae232c07a78</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[downtime]]></category>
            <dc:creator><![CDATA[Olga Totskaya]]></dc:creator>
            <pubDate>Sat, 20 Feb 2016 14:33:52 GMT</pubDate>
            <atom:updated>2016-02-20T16:30:29.451Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://tech.smartling.com/author/kbogdanovs/">Scott Rossillo</a> <a href="http://tech.smartling.com/migrate-to-keycloak-with-zero-downtime/">January 14, 2016</a> <a href="http://tech.smartling.com/category/programming/">Programming</a> <a href="http://tech.smartling.com/migrate-to-keycloak-with-zero-downtime/#respond">No Comments</a></p><p><a href="http://keycloak.jboss.org/">Keycloak</a> is an excellent Single Sign-On and identity management server, implementing both OpenID Connect 1.0 (OIDC) and SAML 2.0 specifications. It provides an Authorization Server and adapters for Java clients, including a Spring Security implementation. Since Keycloak implements the standard OIDC protocol, it works great with applications developed in other languages as well.</p><p>Migrating your users from one identity management system to another is something that requires careful upfront planning. You’re probably focused on the new features the new software will give you to build out your product. However, it’s important to plan and test your strategy for moving your users from your legacy system to your new identity management system, since a failed user migration process will cause headaches for your users and support team.</p><p>Some questions you should ask yourself when planning your new identity management implementation include:</p><p><strong>1.</strong> Can users be migrated to the new system without them having to reset their passwords?<br> <strong>2.</strong> Can the new login system be turned on without downtime?<br> <strong>3.</strong> If something totally unexpected goes wrong with your new system launch, can it be rolled back?</p><p>When implementing Keycloak, the answer to all three questions is yes. The solution lies in Keycloak’s User Federation SPI, an interface allowing users to be imported from a legacy system into Keycloak’s local storage the first time they log into your application using Keycloak. This is called an on demand migration.</p><p>To help Keycloak implementers with user migration, we’ve open sourced our <a href="https://github.com/Smartling/keycloak-user-migration-provider">user federation provider</a>. It can be used to perform an on demand migration to Keycloak. Below, we’ll take a dive into the code to understand how the user migration process works.</p><p>Our user federation provider will:</p><p><strong>1.</strong> Confirm on demand if a user exists in our legacy user system.<br> <strong>2.</strong> Validate on demand if the password being typed into Keycloak’s login page matches their password in our legacy user system.<br> <strong>3.</strong> Import the user into Keycloak’s local storage and make Keycloak the system of record for the imported user after their first successful login.</p><p>Since we’re implementing Keycloak to support a service oriented architecture, our federation provider will use a RESTful API to request information about our users from the legacy system. This approach is very flexible because it supports a legacy user service written in any language and it provides a clear separation of concerns between Keycloak and the legacy system during the migration process.</p><p>Using our custom provider, we’ll be able address two of our migration concerns with minimal effort. Since we can validate user information and passwords on demand, we can migrate user accounts without users resetting their passwords and without downtime. Additionally, because the system of record remains our legacy system until a user logs in and we haven’t forced a password change, we can migrate back to our legacy system if something unexpected happens with our Keycloak implementation. Using an on demand approach to user migration mitigates the risk of a catastrophic failure rippling out of control.</p><p>We migrate our users to Keycloak in two steps via our federation provider. During login, we confirm that the user exists in our legacy system and import the user and any metadata, such as roles and custom attributes, into Keycloak. Secondly, we confirm the password entered on the Keycloak login screen matches the password in the legacy system and break the federation link. After these steps are complete, Keycloak will become the system of record for the user.</p><p>Writing our on demand migration provider starts by implementing the UserFederationProvider and UserFederationProviderFactory interfaces. The UserFederationProviderFactory<br> tells Keycloak what properties need to be set for the UserFederationProvider to work. Since we’re using a RESTful API in our federation provider, we just need to set the base URI to our legacy identity server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*vDO4ix5S-pDYScI0.png" /></figure><p>The actual work is done by our custom user federation provider. By implementing a few key methods:</p><p>1UserModel getUserByUsername(RealmModel realm, String username);</p><p>2UserModel getUserByEmail(RealmModel realm, String email);</p><p>3boolean isValid(RealmModel realm, UserModel local);</p><p>4boolean validCredentials(RealmModel realm, UserModel user, List&lt;UserCredentialModel&gt; input);</p><p>In getUserByUsername() and getUserByEmail(), we call our legacy user system to request a JSON representation of the user to be migrated. Using this information we create a Keycloak user model, populate it with the information from our legacy system, and return the model to Keycloak for storage. Additionally, we set a federation link between the Keycloak user and our migration provider. This allows us to validate the user’s password with our legacy user system in a future API call.</p><p>Our isValid() method simply makes a request to our legacy user system to check if a user exists. Keycloak calls this method to verify that we want to proceed with credential validation.<br> A successful response means the user exists.</p><p>In our migration process, implementing a real check in isValid() may seem redundant, but it’s important. If a user has been created in Keycloak but fails to provide a correct password, the user will remain in Keycloak with a federation link to our migration provider. We need to be able to communicate to Keycloak if the user is still valid for migration if they return to login again hours or even days later.</p><p>Our validCredentials() implementation is also pretty simple. We send the username and password the user entered into the Keycloak login form over to our legacy system for validation. A successful response means the password validates; any other response means the entered password is incorrect. Upon successful validation, we save the password the user entered in the login form into Keycloak’s storage and remove the federation link between the Keycloak user and our migration provider. Keycloak is now the system of record for this user.</p><p>Our open sourced user federation provider comes with two sample applications. A sample legacy user service and a demo portal that can be used to prompt a Keycloak login and thus an on demand migration. Give it a try and hit us up in the comments below if you have any questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ae232c07a78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate to Keycloak with Zero Downtime]]></title>
            <link>https://medium.com/@olgaatsmartling/migrate-to-keycloak-with-zero-downtime-74d4997d91ad?source=rss-a0e471c44840------2</link>
            <guid isPermaLink="false">https://medium.com/p/74d4997d91ad</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[downtime]]></category>
            <dc:creator><![CDATA[Olga Totskaya]]></dc:creator>
            <pubDate>Wed, 20 Jan 2016 16:22:01 GMT</pubDate>
            <atom:updated>2016-01-20T16:22:01.952Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://tech.smartling.com/author/kbogdanovs/">by Scott Rossillo</a></p><p><a href="http://keycloak.jboss.org/">Keycloak</a> is an excellent Single Sign-On and identity management server, implementing both OpenID Connect 1.0 (OIDC) and SAML 2.0 specifications. It provides an Authorization Server and adapters for Java clients, including a Spring Security implementation. Since Keycloak implements the standard OIDC protocol, it works great with applications developed in other languages as well.</p><p>Migrating your users from one identity management system to another is something that requires careful upfront planning. You’re probably focused on the new features the new software will give you to build out your product. However, it’s important to plan and test your strategy for moving your users from your legacy system to your new identity management system, since a failed user migration process will cause headaches for your users and support team.</p><p>Some questions you should ask yourself when planning your new identity management implementation include:</p><p><strong>1.</strong> Can users be migrated to the new system without them having to reset their passwords?<br> <strong>2.</strong> Can the new login system be turned on without downtime?<br> <strong>3.</strong> If something totally unexpected goes wrong with your new system launch, can it be rolled back?</p><p>When implementing Keycloak, the answer to all three questions is yes. The solution lies in Keycloak’s User Federation SPI, an interface allowing users to be imported from a legacy system into Keycloak’s local storage the first time they log into your application using Keycloak. This is called an on demand migration.</p><p>To help Keycloak implementers with user migration, we’ve open sourced our <a href="https://github.com/Smartling/keycloak-user-migration-provider">user federation provider</a>. It can be used to perform an on demand migration to Keycloak. Below, we’ll take a dive into the code to understand how the user migration process works.</p><p>Our user federation provider will:</p><p><strong>1.</strong> Confirm on demand if a user exists in our legacy user system.<br> <strong>2.</strong> Validate on demand if the password being typed into Keycloak’s login page matches their password in our legacy user system.<br> <strong>3.</strong> Import the user into Keycloak’s local storage and make Keycloak the system of record for the imported user after their first successful login.</p><p>Since we’re implementing Keycloak to support a service oriented architecture, our federation provider will use a RESTful API to request information about our users from the legacy system. This approach is very flexible because it supports a legacy user service written in any language and it provides a clear separation of concerns between Keycloak and the legacy system during the migration process.</p><p>Using our custom provider, we’ll be able address two of our migration concerns with minimal effort. Since we can validate user information and passwords on demand, we can migrate user accounts without users resetting their passwords and without downtime. Additionally, because the system of record remains our legacy system until a user logs in and we haven’t forced a password change, we can migrate back to our legacy system if something unexpected happens with our Keycloak implementation. Using an on demand approach to user migration mitigates the risk of a catastrophic failure rippling out of control.</p><p>We migrate our users to Keycloak in two steps via our federation provider. During login, we confirm that the user exists in our legacy system and import the user and any metadata, such as roles and custom attributes, into Keycloak. Secondly, we confirm the password entered on the Keycloak login screen matches the password in the legacy system and break the federation link. After these steps are complete, Keycloak will become the system of record for the user.</p><p>Writing our on demand migration provider starts by implementing the UserFederationProvider and UserFederationProviderFactory interfaces. The UserFederationProviderFactory<br> tells Keycloak what properties need to be set for the UserFederationProvider to work. Since we’re using a RESTful API in our federation provider, we just need to set the base URI to our legacy identity server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*77s0q0CTC0Nl7w_9.png" /></figure><p>The actual work is done by our custom user federation provider. By implementing a few key methods:</p><p>1UserModel getUserByUsername(RealmModel realm, String username);</p><p>2UserModel getUserByEmail(RealmModel realm, String email);</p><p>3boolean isValid(RealmModel realm, UserModel local);</p><p>4boolean validCredentials(RealmModel realm, UserModel user, List&lt;UserCredentialModel&gt; input);</p><p>In getUserByUsername() and getUserByEmail(), we call our legacy user system to request a JSON representation of the user to be migrated. Using this information we create a Keycloak user model, populate it with the information from our legacy system, and return the model to Keycloak for storage. Additionally, we set a federation link between the Keycloak user and our migration provider. This allows us to validate the user’s password with our legacy user system in a future API call.</p><p>Our isValid() method simply makes a request to our legacy user system to check if a user exists. Keycloak calls this method to verify that we want to proceed with credential validation.<br> A successful response means the user exists.</p><p>In our migration process, implementing a real check in isValid() may seem redundant, but it’s important. If a user has been created in Keycloak but fails to provide a correct password, the user will remain in Keycloak with a federation link to our migration provider. We need to be able to communicate to Keycloak if the user is still valid for migration if they return to login again hours or even days later.</p><p>Our validCredentials() implementation is also pretty simple. We send the username and password the user entered into the Keycloak login form over to our legacy system for validation. A successful response means the password validates; any other response means the entered password is incorrect. Upon successful validation, we save the password the user entered in the login form into Keycloak’s storage and remove the federation link between the Keycloak user and our migration provider. Keycloak is now the system of record for this user.</p><p>Our open sourced user federation provider comes with two sample applications. A sample legacy user service and a demo portal that can be used to prompt a Keycloak login and thus an on demand migration. Give it a try and hit us up in the comments below if you have any questions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74d4997d91ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Translation Context for Drupal Content — Universal Language]]></title>
            <link>https://medium.com/@olgaatsmartling/creating-translation-context-for-drupal-content-universal-language-4d33a2e614c6?source=rss-a0e471c44840------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d33a2e614c6</guid>
            <category><![CDATA[context]]></category>
            <category><![CDATA[translation-companies]]></category>
            <category><![CDATA[drupal]]></category>
            <dc:creator><![CDATA[Olga Totskaya]]></dc:creator>
            <pubDate>Wed, 06 Jan 2016 14:48:46 GMT</pubDate>
            <atom:updated>2016-02-20T16:51:36.495Z</atom:updated>
            <content:encoded><![CDATA[<p>The word ‘context’ has a lot of meanings in the Drupal community, but to Smartling, context is a snapshot of an HTML page we show to translators inside the Smartling dashboard. Translators working on the page can see their translations replace the source text as they work on them. Providing context helps translators provide great translations fast by taking the guesswork out of translation. They can see instantly if their translation fits the available space on the page and are less likely to be confused by the meaning of strings. For example, translating the string ‘Home’ is much easier when you can look at the page and see that it’s a navigation button, rather than a house. Context is especially useful when the source content isn’t yet published, as it allows the translator to see what content looks like even if it is not published in the production environment yet.</p><p>This is what the Smartling translator interface looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*p0sZ8c76MQaN-UPyzWjH0Q.gif" /><figcaption>z</figcaption></figure><p>Smartling has been using translation context for a long time. We already had a manual approach to provide context to translators with Drupal, but we wanted to automate the way context is created.</p><p>The manual approach was based on the <a href="http://support.smartling.com/hc/en-us/articles/202007178">Chrome Context Capture Extension</a>. After installing the module, you could either send HTML context by manually pushing the plugin button on every page you wanted to be included, or you could use javascript automation to trigger the plugin to send snapshots automatically.</p><p>Smartling has asynchronous socket-based context API and we naturally started to look there. However, it proved very challenging to do websockets work due to limited availability of libraries for PHP 5.3. The libraries we found just did not work that well. So, we’ve settled on another approach — to ask Drupal to render and send us an HTML page automatically whenever a page is sent for translation.</p><p>The user selects and submits content for translation using built-in Smartling Connector module interfaces. The module uploads content to Smartling asynchronously, to speed up user interfaces and use server resources gently — after all, multiple users can request thousands of content nodes to be translated at the same time. Once content is uploaded, the module starts generating html context and sends it to Smartling API as well.</p><p>This is how context is generated:</p><p>Step 1: Impersonate a preconfigured user<br> Step 2: Retrieve a full html page and all its resources<br> Step 3: Send context to Smartling API</p><p><strong>Step 1: Impersonate a preconfigured user</strong></p><p>The Drupal Connector configuration allows us to define a user under which we will retrieve the context for several reasons: firstly, in case of background tasks we need to see full content of the page, while anonymous users, under whom background processes run, may not have access to the page. On the other hand we do not want context to include content not visible to an end user, such as admin menus. So, a separate user to impersonate is the way to go. The third reason is that we don’t want to raise the privileges of the anonymous user session of background tasks, as it may have security implications.</p><p>To accomplish all the points mentioned above, we do the following trick:</p><p><strong>a.</strong> Store current user session to temp storage.<br> <strong>b.</strong> Request Drupal to generate a session for our preconfigured user (we use it later).<br> <strong>c.</strong> Restore the original session for current user.</p><p>This approach also allows us to add a “debug mode” for the module, which lets you see the page “through the eyes” of Smartling Drupal context, without being logged-out.</p><p>You can find session handling code <a href="http://cgit.drupalcode.org/smartling/tree/smartling_translation_context/includes/context_authorize.inc#n86">here</a>, if you’d like.</p><p><strong>Part 2. Retrieve full page, including all resources</strong></p><p>We’ve Googled to see if there was an existing solution for parsing a page and retrieving/embedding all the assets of the page in PHP. Luckily for us, we found a solution at <a href="http://www.phpclasses.org/package/8305-PHP-Save-HTML-pages-complete-with-images-CSS-and-JS.html">PHP Classes</a>.</p><p>That was a good starting point, but there were 2 issues with this solution: it didn’t support images from CSS files, and it was too slow. It could easily take 30–40 seconds to render a single page without CSS images and almost an eternity to include them.</p><p>So, after another round of thought, we decided to use the flexibility of Drupal. The issue is that 95% of the time was spent waiting for the result of http requests for the page assets. But why would we need to make http-requests when we are dealing with our own site? We’ve substituted these requests with local file-reads, and made Drupal do most of work on embedding those resources into the page.</p><pre>1function smartling_translation_context_css_alter(&amp;$css) {</pre><pre>2 global $user;</pre><pre>3 if (!isset($_GET[‘smartling_context’]) || ($user-&gt;name != variable_get(‘smartling_translation_context_username’, ‘’))) {</pre><pre>4 return;</pre><pre>5 }</pre><pre>6</pre><pre>7 $exclude_files = variable_get(‘smartling_translation_context_exclude_files’, ‘’);</pre><pre>8 $exclude_files = explode(“\n”, $exclude_files);</pre><pre>9 if (is_array($exclude_files) &amp;&amp; count($exclude_files) &gt; 0) {</pre><pre>10 foreach ($exclude_files as $filename) {</pre><pre>11 if (isset($css[$filename])) {</pre><pre>12 unset($css[$filename]);</pre><pre>13 }</pre><pre>14 }</pre><pre>15 }</pre><pre>16</pre><pre>17 foreach ($css as $filename =&gt; $settings) {</pre><pre>18 if ($filename === ‘settings’) {</pre><pre>19 continue;</pre><pre>20 }</pre><pre>21</pre><pre>22 $path = drupal_realpath($filename);</pre><pre>23 if (empty($path)) {</pre><pre>24 continue;</pre><pre>25 }</pre><pre>26 $file_content = file_get_contents($path);</pre><pre>27</pre><pre>28</pre><pre>29 $matches = array();</pre><pre>30 preg_match_all(‘/url\(([\d\D^)]+)\)/iU’, $file_content, $matches);</pre><pre>31</pre><pre>32 foreach ($matches[1] as $k =&gt; $img_url) {</pre><pre>33 $img_url = trim($img_url, ‘\’”’);</pre><pre>34 # make sure that it is an image and convert to data uri</pre><pre>35 $fileType = trim(strtolower(pathinfo($img_url, PATHINFO_EXTENSION)));</pre><pre>36 if (!preg_match(‘#^(gif|png|jp[e]?g|bmp)$#i’, $fileType)) {</pre><pre>37 continue;</pre><pre>38 }</pre><pre>39</pre><pre>40 $src = pathinfo($path, PATHINFO_DIRNAME) . ‘/’ . $img_url;</pre><pre>41</pre><pre>42 $mimType = ‘png’;</pre><pre>43 $dataUri = file_get_contents($src);</pre><pre>44 $dataUri = ‘url(https://medium.com/%E2%80%9Cdata:image/%E2%80%99%20.%20$mimType%20.%20%E2%80%98;base64,%E2%80%99%20.%20base64_encode($dataUri) . ‘”)’;</pre><pre>45 $file_content = str_replace($matches[0][$k], $dataUri, $file_content);</pre><pre>46 }</pre><pre>47</pre><pre>48 $css[$filename][‘type’] = ‘inline’;</pre><pre>49 $css[$filename][‘data’] = $file_content;</pre><pre>50 }</pre><p>The code above does the following:</p><p><strong>a.</strong> get CSS file URIs and retrieve their content as plain text<br> <strong>b.</strong> parse each file to find if it contains any images<br> <strong>c.</strong> embed images into each css file<br> <strong>d.</strong> replace CSS file URI with the parsed content of this CSS file<br> <strong>e.</strong> let Drupal know that we are dealing with the “inline” CSS<br> <strong>f.</strong> Drupal properly handles CSS content and puts it into the page</p><p>The same trick can be easily implemented with JavaScript.</p><p>The only thing left on the page was html content images. We parse the DOM and embed images into our HTML page to include them into a single HTML snapshot to send to Smartling.</p><p>Processing of a single page usually takes 2–5 sec, which is 8–20 times faster than prior solution.</p><p><strong>Part 3. Send to Smartling</strong></p><p>To send this context HTML page to Smartling, all we need to do is send a simple POST HTTP request to our publicly available <a href="http://docs.smartling.com/pages/API/HTML-Context/">HTML Context API</a>.</p><p><strong>Conclusions</strong></p><p>We recognize that this approach is somewhat limited and, for example, doesn’t support ajax queries. So not all sites can be fully handled with this module. But in our experience, this approach works well for most Drupal sites, and if some site or page is really so complex that it can’t be handled with our module, then we can always deploy the <a href="http://support.smartling.com/hc/en-us/articles/202007178">Chrome browser plugin</a>.</p><p>It is also interesting that, when we talked about this feature to some community members at DrupalCon Amsterdam, it was considered to be nearly impossible to implement. So, as you can see, the limits of impossible can sometimes be pushed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/72/0*WtTxOlyxVoMBN5fn.png" /></figure><p>P.S. We’re excited about the new Drupal 8 release and we <a href="https://www.drupal.org/project/smartling">fully support it</a> with <a href="https://www.drupal.org/project/tmgmt_smartling">the new TMGMT</a> as well as the <a href="https://www.drupal.org/project/smartling">original Drupal 7 translation approach</a>. It is also worth menting that 4 major PHP releases since PHP 5.3 a decent amount of libraries have appeared and are maturing — we may find another approach to implement translation context moving forward.</p><p>Creating Translation Context for Drupal Content</p><p><em>Originally published at </em><a href="http://tech.smartling.com/creating-translation-context-for-drupal-content/"><em>tech.smartling.com</em></a><em> on January 6, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d33a2e614c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>