<?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 Visweshwar Ganesh on Medium]]></title>
        <description><![CDATA[Stories by Visweshwar Ganesh on Medium]]></description>
        <link>https://medium.com/@visweshwar?source=rss-fbf6ff79988c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Wo8B5GfJ-qsLEQBy</url>
            <title>Stories by Visweshwar Ganesh on Medium</title>
            <link>https://medium.com/@visweshwar?source=rss-fbf6ff79988c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 12:34:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@visweshwar/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[The Resolution My Samsung Monitor Forgot to Tell macOS About]]></title>
            <link>https://visweshwar.medium.com/the-resolution-my-samsung-monitor-forgot-to-tell-macos-about-feafdca7a9a1?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/feafdca7a9a1</guid>
            <category><![CDATA[gaming-monitors]]></category>
            <category><![CDATA[work-from-home]]></category>
            <category><![CDATA[remote-working]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 13:16:44 GMT</pubDate>
            <atom:updated>2026-09-07T13:16:44.986Z</atom:updated>
            <content:encoded><![CDATA[<h3>Samsung Monitor wasn’t advertising the scaling mode macOS needed</h3><h3>TL;DR</h3><p>The Samsung S85TH was not advertising the right scaling mode to macOS in normal operation. <strong>3840×1620 only appeared when PIP was enabled</strong>, because the monitor exposed a different EDID.</p><p>I used BetterDisplay to capture that PIP-on EDID and apply it while PIP was off. Once I did that, <strong>3840×1620 appeared as a normal macOS scaling option</strong>.</p><p>So the fix was not forcing a custom resolution. It was making the monitor advertise the right one.</p><h3>What was the problem?</h3><p>I recently started using a Samsung 40-inch 5K2K ultrawide with my 14-inch M1 Pro MacBook Pro.</p><p>The monitor’s native resolution is <strong>5120×2160</strong>, and at that resolution the image is extremely sharp. The problem is that on a 40-inch display, the text and UI are simply too small for me to use comfortably all day.</p><p>So the obvious next step was to use macOS scaling.</p><p>That is where things became strange.</p><p>By default, macOS offered only a handful of scaled resolutions:</p><ul><li>3440×1440…</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*ds0huqf-nGehG2lJPh1Bow.png" /></figure><p>Those choices were not just oddly spaced; they were the wrong scaling choices for this display. Even after turning on “Show all resolutions,” macOS still did not offer 3840×1620 as one of its normal scaling options.</p><p>That was the real problem. The resolution I wanted was not merely absent from the short default list. <strong>It was not being advertised to macOS in the way that would make it appear as a normal, first-class scaling option. </strong>Like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*wqQ8tr5BZBZP1W0uIFZ9MA.png" /></figure><h3>What happens because of the wrong scaling factors?</h3><p>That softness is hard to describe until you see it. It is the kind of thing that makes a brand-new monitor feel slightly wrong even when you cannot immediately explain why. The screen is large, the resolution is high, and everything should look great, but <strong>small text feels just a little blurred.</strong> You start wondering whether it is the cable, the monitor, macOS, or simply your eyes.</p><p>In my case, 3440×1440 was usable, but the text never looked quite as crisp as I expected from a new 5K2K monitor.</p><h3>The troubleshooting journey</h3><p>My first instinct was that this had to be a connection problem.</p><p>I tried HDMI. I tried DisplayPort. I changed cables and connection paths. The image changed in some cases, but the underlying scaling problem did not.</p><p>That pushed me toward <a href="https://github.com/waydabber/BetterDisplay">BetterDisplay</a>.</p><p>BetterDisplay exposed far more control than macOS does by default, including flexible scaling and virtual displays. I tried both.</p><p>Flexible scaling gave me more intermediate resolutions, but the text still did not look right. Some modes were technically closer to the size I wanted, yet fine text looked softer and more washed out than at the default 3440×1440 setting.</p><p>I even created a virtual 3840×1620 display with the same shape as the monitor. It gave me the workspace size I wanted, but the image still did not look right.</p><p>That got me the workspace size I wanted, but the image still did not look like a true native scaling mode.</p><h3>Installing Samsung Display Manager</h3><p>As part of troubleshooting, I also installed <strong>Samsung Display Manager (</strong><a href="https://org.downloadcenter.samsung.com/downloadfile/ContentsFile.aspx?CDSite=UNI_HK_EN&amp;OriginYN=N&amp;ModelType=N&amp;ModelName=S27D600EAU&amp;CttFileID=10748457&amp;CDCttType=SW&amp;VPath=SW%2F202606%2F20260611123634938%2FSamsungDisplayManagerMSIX64_2026May26_Ver1.2.6.msi"><strong>Link</strong></a><strong>) </strong>to see whether the monitor itself exposed any controls that macOS was not showing me.</p><p>That gave me access to features like Picture-in-Picture and Picture-by-Picture directly from the Mac.</p><p>At the time, I was not expecting those features to have anything to do with scaling. I was simply exploring the monitor’s settings to see if there was something I had missed.</p><p>That is what led to the accidental discovery.</p><h3>The accidental clue</h3><p>The breakthrough came by accident.</p><p>While experimenting with Samsung’s Picture-in-Picture mode, I noticed that macOS suddenly offered <strong>3840×1620</strong> as a normal scaling option.</p><p>That immediately stood out because nothing else had changed. Same Mac, same monitor, same connection.</p><p>When I turned PIP off, the resolution disappeared again.</p><p>That was the moment I realized this was probably not just a macOS scaling limitation. The monitor itself was changing what it told macOS it could do.</p><h3>Comparing the EDID</h3><p>EDID is basically the monitor’s résumé. It tells the Mac what the display is, what resolutions it supports, and how it should be treated.</p><p>Once I saw 3840×1620 appear only when PIP was enabled, I went back to BetterDisplay and looked at the monitor’s EDID information in both states.</p><p>With PIP off, the Samsung identified itself as: <strong>SAM, 7A30</strong></p><p>With PIP on, it identified itself as: <strong>SAM, 7A32</strong></p><p>The EDID payload was different as well.</p><p>That was the key. Samsung was effectively presenting a different version of the monitor to macOS when PIP was enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OwJpcQLr5e93hY81IuQy6Q.png" /><figcaption>BetterDisplay EDID with PIP off</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TK4bbGS-oVYc_NwG1wEQTg.png" /><figcaption>BetterDisplay EDID with PIP on</figcaption></figure><p>That explained why macOS suddenly exposed 3840×1620. It was not simply reacting to PIP as a picture mode. It was receiving a different description of the monitor and building a different set of scaling options from it.</p><p>The next experiment was obvious. I saved the PIP-on EDID, turned PIP back off, and applied that EDID to the monitor in its normal mode using BetterDisplay.</p><p>3840×1620 appeared immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*JQqAmz6TlITdmshqQYt2kg.png" /></figure><p>At that point, the problem finally made sense. The resolution had not been impossible. It had simply not been advertised to macOS in the normal EDID.</p><h3>Closing note</h3><p>This is a workaround for something Samsung should fix.</p><p>The S85TH is clearly capable of exposing the correct 3840×1620 scaling mode, because it does exactly that when PIP is enabled. The problem is that Samsung’s normal EDID does not advertise the display in a way that lets macOS expose that mode properly.</p><p>Samsung needs to publish a <strong>firmware update</strong> that corrects the normal EDID behavior so 3840×1620 is available without relying on PIP or a third-party EDID override.</p><p>A premium 5K2K monitor should not require BetterDisplay and a custom EDID workaround just to expose a sensible scaling mode on macOS. Until Samsung fixes it in firmware, this is the cleanest workaround I found.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=feafdca7a9a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WFH Communication Protocols: If your question can wait 24 hours try Email instead of messaging]]></title>
            <link>https://visweshwar.medium.com/wfh-communication-protocols-if-your-question-can-wait-24-hours-try-email-instead-of-messaging-4c6f308761a9?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c6f308761a9</guid>
            <category><![CDATA[email]]></category>
            <category><![CDATA[messaging]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[wfh]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Tue, 01 Dec 2020 13:41:21 GMT</pubDate>
            <atom:updated>2020-12-01T22:32:53.017Z</atom:updated>
            <content:encoded><![CDATA[<h3>Has communication become actual work?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*vO8_bF1oe6IMltmtOocElw.png" /></figure><p>In the ever changing sphere of communication we missed a beat on protocols on different mediums.</p><h3>Evolution of Office Communication Technology</h3><p>We started with Phone calls / Email and the prioritization was clear, Urgent Interruption vs communication. This allowed one to compartmentalize time to attend to work (yes, also that) in addition to communication.</p><p>This then led to a middle path of 1–1 messaging platforms like Microsoft Lync(Skype).. (Not accounting for personal Chat platforms like Google,Yahoo…). This introduced a middle path between Phone calls and Emails.</p><p>Then came even better platforms like Slack, Rocket Chat, Microsoft Teams… This now further sliced into your priorities.</p><p>Now it’s the era of video communication, thanks to Zoom, Teams.</p><h3>Where are we now</h3><p>This is not representational of everyone but,most of us are left with</p><p>Phone,Email,1–1 Messaging,Group Messaging and Video chat. It’s time we try to attach a priority to these because, apart from “communicating” there is also “work”.</p><h4>Phone / Video Chat</h4><p>These squarely fall into the territory of 100% interruption, these should be used for conversations which has a lot of back and forth. Ditch the chat platforms/emails, if you’re going to spend more than 10 minutes on chat. Most likely you’re staring at the dots waiting for the person to reply.</p><h4>1–1 Messaging</h4><p>This falls into the category where you are expecting a response in less than 30 mins and your work is stalled without an answer to that question.</p><h4>Group Messaging</h4><p>This works great where you don’t expect participation from all members and are just crowdsourcing ideas or sharing information on a #topic. Channels work great for this purpose and becomes a great go to space.</p><h4>Email</h4><p>This is perfect for FYI, General Messaging and issues which are not time sensitive. Again long email threads should move into the Phone territory and just the summary should become an email.</p><p><strong>Communication is key but, when communication takes over your day, it’s time to stop and reflect.</strong></p><h3>Guess the medium</h3><p>Here are some conversations, try to see which communication method should you use.</p><p>Scenario 1</p><p><em>“Hey, can you get me a financial report by end of next week”</em></p><p>Scenario 2</p><p><em>“Hey, what are your thoughts on slide 4,6,29” — Joe</em></p><p><em>Jane — “ I think we need to improve the language on 6, 15”</em></p><p><em>“That, great what do you think it should change to” — Joe</em></p><p><em>Jane — “Let me try to comment on the slides”</em></p><p><em>“That would be great, should we cut out slides 3,7?” — Joe</em></p><p>Scenario 3</p><p><em>“ I’m having issues with an excel formula, I can use a second set of eyes”</em></p><h3>Final Thoughts</h3><p>Different protocols work for different people/organizations, what is risky is not having a set of rules which can lead to false assumptions of productivity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c6f308761a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Reactive Multi MongoTemplate Configuration]]></title>
            <link>https://visweshwar.medium.com/spring-reactive-multi-mongotemplate-configuration-593e949456be?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/593e949456be</guid>
            <category><![CDATA[spring-mongo-db]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[spring-webflux]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Fri, 27 Nov 2020 18:28:01 GMT</pubDate>
            <atom:updated>2020-11-27T22:49:38.198Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*niQkv_L40dz8600T" /></figure><p>Configuring your application with Spring Data and MongoDB is quite well documented on the internet. Be it the <a href="https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference">Spring Data documentation</a> or the great starter projects from <a href="https://www.baeldung.com/spring-data-mongodb-reactive">baeldung.com</a>.</p><p>What I was missing was a reference example for a multi mongoTemplate configuration.</p><h3>Why Multi MongoTemplate Configuration?</h3><p>There are instances where your application interacts with more than just one instance of a mongoDB database. When you get into this state, the out of the box configurations fail to recognize this state.</p><h4>What do we need to solve?</h4><p>There are a few unique issues which you’d experience when you encounter this condition.</p><ul><li>How do we define our Database Properties?</li><li>How do we does the repository differentiate which Database to interact with?</li><li>How do we configure DB options?</li></ul><p>Let’s go about answering these questions using a very simple command line example.</p><h3>Defining MongoDB Properties</h3><p>To define the properties in this case we break away from the “traditional” spring parameters.</p><p>Here is a sample Configuration.</p><h4>application.yml</h4><pre>spring:<br>  data:<br>    mongodb:<br>      <strong>coffee</strong>:<br>        database: coffee<br>        uri: mongodb://localhost:27017<br>      <strong>burger</strong>:<br>        database: burger<br>        uri: mongodb://localhost:27017<br>  autoconfigure:<br>    exclude: org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration</pre><p>We have two databases coffee and burger these could represent the same replicaset or different replicaset. <em>In this case they refer to the same replicaset.</em></p><p>Similar to the Non Reactive Mongo Autoconfiguration, we have exclude the autoconfiguration as we are going to take it over.</p><h4>Reading the Config file</h4><p>There is nothing unusual here, this is the general way we reach the property files. Note the ConfigurationProperty Prefix.</p><pre>package com.acme.multimongo.config;<br><br>import lombok.Getter;<br>import lombok.Setter;<br>import org.springframework.boot.autoconfigure.mongo.MongoProperties;<br>import org.springframework.boot.context.properties.ConfigurationProperties;<br>import org.springframework.context.annotation.Configuration;<br> <em><br></em>@Configuration<br><strong>@ConfigurationProperties(prefix = &quot;spring.data.mongodb&quot;)<br></strong>@Getter<br>@Setter<br>public class CustomMongoProperties {<br>   private MongoProperties coffee;<br>   private MongoProperties burger;<br><br>}</pre><h3>Define The Configuration</h3><p>To define the configuration there are 2 parts</p><ul><li>MongoConfig</li><li>MongoTemplate</li><li>MongoClient</li></ul><h4>Defining the Mongo Config</h4><p>Now we have to define a Config for each Database</p><pre>package com.acme.multimongo.config;<br><br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;<br><br> <em><br></em>@Configuration<br><strong>@EnableReactiveMongoRepositories(basePackages = &quot;com.acme.multimongo.repository.burger&quot;,<br>reactiveMongoTemplateRef = &quot;mongoTemplateBurger&quot;)</strong><br>public class BurgerMongoConfig {<br>}</pre><p><strong>NOTE: </strong>We have Separated the Annotation @EnableReactiveMongoRepositories by defining basePackage and a reactiveMongoTemplateRef<em> (We’ll see the </em><em>reactiveMongoTemplateRef in the next section)</em></p><pre>package com.acme.multimongo.config;<br><br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;<br><br> <em><br></em>@Configuration<br><strong>@EnableReactiveMongoRepositories(basePackages = &quot;com.acme.multimongo.repository.coffee&quot;,<br>reactiveMongoTemplateRef = &quot;mongoTemplateCoffee&quot;)</strong><br>public class CoffeeMongoConfig {<br>}</pre><h4>Defining MongoClient and MongoTemplates</h4><p>Let’s define the configuration for the Coffee Client</p><p>As you can see below we have defined the MongoClient, where we inject the ClientSettings and then inject the MongoClient into the template.</p><p>NOTE: We have to define any one of the MongoTemplate as @Primary.</p><pre><strong>@Primary<br></strong>@Bean<br>public MongoClient reactiveMongoClientCoffee() {<br>   return MongoClients.<em>create</em>(createMongoClientSettings(customMongoProperties.getCoffee()));<br>}</pre><pre><strong>@Primary<br>@Bean(&quot;mongoTemplateCoffee&quot;)<br></strong>public ReactiveMongoTemplate reactiveMongoTemplateCoffee(){<br>   return new ReactiveMongoTemplate(reactiveMongoClientCoffee(),customMongoProperties.getCoffee().getDatabase());<br>}<br><br>private MongoClientSettings createMongoClientSettings(MongoProperties mongoProperties){<br><br>   ConnectionString ConnectionString = new ConnectionString(mongoProperties.getUri());<br><br>   MongoClientSettings mongoClientSettings = MongoClientSettings.<em>builder</em>()<br>                              .readConcern(ReadConcern.<em>DEFAULT</em>)<br>                              .writeConcern(WriteConcern.<em>MAJORITY</em>)<br>                              .readPreference(ReadPreference.<em>primary</em>())<br>                              .applyConnectionString(ConnectionString)<br>                              .build();<br>   return mongoClientSettings;<br>}</pre><p>Similarly for the burger client. Putting it now all together</p><pre>package com.acme.multimongo.config;<br><br>import com.mongodb.*;<br>import com.mongodb.reactivestreams.client.MongoClient;<br>import com.mongodb.reactivestreams.client.MongoClients;<br>import org.springframework.boot.autoconfigure.mongo.MongoProperties;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.context.annotation.Primary;<br>import org.springframework.data.mongodb.core.ReactiveMongoTemplate;<br> <em><br></em>@Configuration<br>public class MongoConfiguration {<br><br><strong>   private final CustomMongoProperties customMongoProperties;<br></strong><br>   public MongoConfiguration(CustomMongoProperties customMongoProperties) {<br>      this.customMongoProperties = customMongoProperties;<br>   }<br><br>   @Primary<br>   @Bean<br>   public MongoClient <strong>reactiveMongoClientCoffee</strong>() {<br>      return MongoClients.<em>create</em>(createMongoClientSettings(customMongoProperties.getCoffee()));<br>   }<br><br>   @Bean<br>   public MongoClient <strong>reactiveMongoClientBurger</strong>() {<br>      return MongoClients.<em>create</em>(createMongoClientSettings(customMongoProperties.getBurger()));<br>   }<br><br>  <strong> @Primary<br></strong>   @Bean(&quot;<strong>mongoTemplateCoffee</strong>&quot;)<br>   public ReactiveMongoTemplate reactiveMongoTemplateCoffee(){<br>      return new ReactiveMongoTemplate(reactiveMongoClientCoffee(),customMongoProperties.getCoffee().getDatabase());<br>   }<br>   @Bean(&quot;<strong>mongoTemplateBurger</strong>&quot;)<br>   public ReactiveMongoTemplate reactiveMongoTemplateBurger(){<br>      return new ReactiveMongoTemplate(reactiveMongoClientBurger(),customMongoProperties.getBurger().getDatabase());<br>   }<br><br><br>   private MongoClientSettings createMongoClientSettings(MongoProperties mongoProperties){<br><br>      ConnectionString ConnectionString = new ConnectionString(mongoProperties.getUri());<br><br>      MongoClientSettings mongoClientSettings = MongoClientSettings.<em>builder</em>()<br>                                 .readConcern(ReadConcern.<em>DEFAULT</em>)<br>                                 .writeConcern(WriteConcern.<em>MAJORITY</em>)<br>                                 .readPreference(ReadPreference.<em>primary</em>())<br>                                 .applyConnectionString(ConnectionString)<br>                                 .build();<br>      return mongoClientSettings;<br>   }<br>}</pre><h4>Using these Configuration in a simple class</h4><p>Details on how MongoDB and Reactive work are beyond the scope of this document. It’s worth referring to documentation for that purpose.</p><pre>package com.acme.multimongo;<br><br>import com.acme.multimongo.repository.burger.BurgerStoreRepository;<br>import com.acme.multimongo.repository.burger.StoreEntity;<br>import com.acme.multimongo.repository.coffee.CoffeeShopRepository;<br>import com.acme.multimongo.repository.coffee.ShopEntity;<br>import java.util.List;<br>import java.util.Random;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.boot.CommandLineRunner;<br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.web.reactive.config.EnableWebFlux;<br>import reactor.core.publisher.Flux;<br>import reactor.core.publisher.Mono;<br><br>@SpringBootApplication<br>@EnableWebFlux<br>public class MultimongoApplication implements CommandLineRunner {<br><br>  <strong> @Autowired<br>   private BurgerStoreRepository burgerStoreRepository;<br>   @Autowired<br>   private CoffeeShopRepository coffeeShopRepository;<br></strong><br><br><br>   public static void main(String[] args) {<br>      SpringApplication.<em>run</em>(MultimongoApplication.class, args);<br>   }<br><br>   @Override<br>   public void run(String ... args)  {<br>      Mono&lt;List&lt;StoreEntity&gt;&gt; storeList = this.testStore();<br>      Mono&lt;List&lt;ShopEntity&gt;&gt; cafeList = this.testCafe();<br><br>      storeList.then(cafeList).subscribe();<br>   }<br><br>   protected Mono&lt;List&lt;StoreEntity&gt;&gt; testStore(){<br>      Mono storeDeleteMono = this.burgerStoreRepository.deleteAll();<br><br><br>      Mono&lt;List&lt;StoreEntity&gt;&gt; rsp = storeDeleteMono<br>            .thenMany(<br>                  Flux.<em>just</em>(&quot;BK&quot;,&quot;MCD&quot;,&quot;FG&quot;)<br>                        .map(name -&gt; new StoreEntity(name,new Random().nextInt()%10))<br>                        .flatMap(burgerStoreRepository::save)<br>            ).thenMany(burgerStoreRepository.findAll())<br>            .collectList();<br><br>      return rsp;<br><br><br>   }<br>   protected Mono&lt;List&lt;ShopEntity&gt;&gt; testCafe(){<br>      Mono shopDeleteMono = this.coffeeShopRepository.deleteAll();<br><br><br>      return shopDeleteMono<br>            .thenMany(<br>                  Flux.<em>just</em>(&quot;SB&quot;,&quot;DD&quot;,&quot;TH&quot;)<br>                        .map(name -&gt; new ShopEntity(name,new Random().nextInt()%10))<br>                        .flatMap(coffeeShopRepository::save)<br>            ).thenMany(coffeeShopRepository.findAll())<br>            .collectList();<br>   }<br><br><br>}</pre><p>As always the code is available on <a href="https://github.com/visweshwar/multi-mongo-reactive">Github</a></p><h3>References</h3><p>Spring Data Documentation for MongoDB — <a href="https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference">https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference</a></p><p>Spring Reactive Configuration for MongoDB — <a href="https://www.baeldung.com/spring-data-mongodb-reactive">https://www.baeldung.com/spring-data-mongodb-reactive</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=593e949456be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB as Docker Container]]></title>
            <link>https://visweshwar.medium.com/mongodb-as-docker-container-6a5269be8a26?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a5269be8a26</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Mon, 02 Mar 2020 10:46:06 GMT</pubDate>
            <atom:updated>2020-03-02T10:46:06.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*EKZZFrHPOAatMb7_.png" /></figure><h3>Background</h3><p>There are times when you have to try to run a version of MongoDB without trying to install it locally.</p><p>This could be for testing or for just validating a new feature.</p><p>This can be achieved in many ways:</p><ul><li>Choose a version on MongoDB Atlas</li><li><strong>Building an image of the version you like and running it locally.</strong></li></ul><p>We’re going to explore option 2.</p><h3>Pre-existing Image</h3><p>Below are valid tags from DockerHub which can be used.</p><p><a href="https://hub.docker.com/_/mongo?tab=tags">mongo Tags - Docker Hub</a></p><p>One can run an pre existing docker image on a local machine</p><pre><em># This would snag the latest image of mongo community edition and run it on port 27017</em><br>docker run mongo</pre><p>You can improve upon this by choosing a version, changing the port (other than default port) and run it in the background</p><pre><em># Run on port 30001</em><br><em># Run process in the background</em><br><em># Run a custom image</em><br>docker run  --publish 30001:27017 --detach mongo:4.0.16</pre><h3>Customize and run your own image</h3><h3>Build the image</h3><p>Mongo does have a DockerFile which you could use to build your own image with passing arguments</p><p>This is available at</p><p>For 4.2</p><p><a href="https://github.com/docker-library/mongo/blob/master/4.2/Dockerfile">https://github.com/docker-library/mongo/blob/master/4.2/Dockerfile</a></p><p>This gives you the option to tailor your overrides</p><p>Here is an example of our override</p><h3>How to run Enterprise Edition</h3><p><strong>DISCLAIMER: Enterprise edition is a paid license. This is purely for illustration purposes</strong></p><pre><em># Note we&#39;ve overriden the base community edition with Enterprise edition</em><br>docker image  build -t mongo4.2:4.2.2e . --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com</pre><p>NOTE: The version is set in the DockerFile</p><pre>ENV MONGO_MAJOR 4.2<br>#The MONGO_VERSION should match a tag name.<br>ENV MONGO_VERSION 4.2.3</pre><p>If you want to make it generic , you can convert it into an argument and set it like MONGO_PACKAGE and MONGO_REPO</p><h3>Run the image</h3><p>We can run the image we configured above similar to the community version</p><pre><em># NOTE we&#39;ve configured a name for our image mongo42-enterprise</em><br>docker run  --publish 30000:27017 --detach --name mongo42-enterprise mongo4.2:4.2.2e</pre><h3>Interactive Mode</h3><p>To run the Mongo Image in an interactive mode. Essentially we’d like to interact with the mongo container.</p><pre><em>#NOTE: we&#39;ve chosen to use the image name </em><br><em># You can also use the container ID from $docker ps </em><br>docker exec -it mongo42-enterprise mongo</pre><h3>Run a script on the image</h3><p>You can execute on an existing image by running the following command.</p><pre>$docker exec -it --name &lt;Name_Of_Your_Image&gt; mongo</pre><p>This will give you an interface like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTf-8I88qbm2WgFrYUnmeg.png" /></figure><h3>Summary</h3><p>This should give you enough to get going to run the mongo image locally. Be it community or enterprise, this will allow you to experiment features within various releases without installing the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5269be8a26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MongoDB Client Side Field Level Encryption using Java-Spring: Part 2 Community Edition (Manual…]]></title>
            <link>https://visweshwar.medium.com/mongodb-client-side-field-level-encryption-using-java-spring-part-2-community-edition-manual-2e9775e8c169?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9775e8c169</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Sat, 25 Jan 2020 23:21:07 GMT</pubDate>
            <atom:updated>2020-01-26T00:00:35.809Z</atom:updated>
            <content:encoded><![CDATA[<h3>MongoDB Client Side Field Level Encryption using Java-Spring: Part 2 Community Edition (Manual Encryption)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*Gtcr8XUvx3yBkd0_Cqj0Mw.png" /></figure><p>If you’ve not read the Introduction to CSFLE I would strongly urge you to do the same. <a href="https://medium.com/@visweshwar/client-side-field-level-encryption-csfle-on-mongodb-community-ed-using-java-spring-a6489a5c9146">Link</a></p><p>As discussed in the introduction CSFLE is fully featured in all versions of MongoDB except for Automatic CSFLE.</p><h3>Minimum Requirements</h3><ol><li>A mongo instance 4.2+. (<a href="https://www.mongodb.com/download-center/community">Download</a>)</li><li>libmongocrypt library (<a href="https://github.com/mongodb/libmongocrypt">Download and configure</a>)</li><li>Java 1.8+</li><li>Basic understanding of Spring</li><li>Completed the <a href="https://medium.com/@visweshwar/client-side-field-level-encryption-csfle-on-mongodb-community-ed-using-java-spring-a6489a5c9146">Introduction</a></li></ol><h4>Github Project</h4><p><a href="https://github.com/paychex/mongo-csfl-encryption-java-demo">paychex/mongo-csfl-encryption-java-demo</a></p><p>For the purposes of this article we are going to use the <strong>mongo-csfle-community</strong> project.</p><h3>Dependencies</h3><p>For this project we would be using:</p><ul><li>Srping boot starter</li><li>Mongodb data starter</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aea773cf9b69ed9875367466998d839/href">https://medium.com/media/8aea773cf9b69ed9875367466998d839/href</a></iframe><h3>Generating Customer Master key(CMK)</h3><p>Considering this is our first step we will use a local KMS. <em>(An article with AWS KMS will be posted soon..)</em></p><p>To Generate a Master Key we would have to run the main method in the classCreateMasterKeyFile.java. This would generate a 96 character Master key. You are more than welcome to generate this master key through other languages or command line too.</p><p>For example :</p><pre><strong>$(</strong>echo &quot;<strong>$(</strong>head -c 96 /dev/urandom | base64 | tr -d &#39;\n&#39;<strong>)</strong>&quot;<strong>)</strong></pre><h4>Location of Master Key</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*RTQcnnvWp5hfsYy_Di2efA.png" /></figure><p>The master key should’ve got generated at the root of your project. The location is captured in application.yml as <strong>masterKeyPath</strong></p><p><strong>NOTE: This is for demonstration Only. It’s ideal to use a non-local KMS.</strong></p><h3>Generating Data Encryption Key (DEK)</h3><p>We are going to create a DEK at runtime if one doesn’t exist. This is done in the KMSHandler.java. Based on your implementation where and how you generate the DEK will depend on your security model.</p><p>The factors to take into account are:</p><ul><li>Should the data be on the same ReplicaSet as that of the KeyVault</li><li>Who gets to generate the DEK</li><li>The security model around the KeyVault DB</li></ul><p>To simplify the workflow we are creating a <strong>DEK </strong>with a key name if one doesn’t exist in our Key Vault.</p><p>To Generate a DEK we would be using the Driver Operation</p><pre>BsonBinary createDataKey(String kmsProvider, DataKeyOptions dataKeyOptions);</pre><p>DataKeyOptions is a Builder where we provide the <strong>CMK</strong>, Mongo Connections, Key Name and DB Details.</p><pre>String connectionString = &quot;mongodb://localhost:27017&quot;;<br>String keyVaultNamespace = &quot;encryption.__keyVault&quot;;<br><strong>//Client Encryption Settings...</strong><br>ClientEncryptionSettings clientEncryptionSettings = ClientEncryptionSettings.builder()<br>    .keyVaultMongoClientSettings(MongoClientSettings.builder()<br>        .applyConnectionString(<strong>new</strong> ConnectionString(connectionString))<br>        .build())<br>    .keyVaultNamespace(keyVaultNamespace)<br>    .kmsProviders(kmsProviders)<br>    .build();<br><strong>//ClientEncryption Object</strong><br>ClientEncryption clientEncryption = ClientEncryptions.create(clientEncryptionSettings);<br>BsonBinary dataKeyId = clientEncryption.createDataKey(kmsProvider, <strong>new</strong> DataKeyOptions());<br>System.out.println(&quot;DataKeyId [UUID]: &quot; + dataKeyId.asUuid());<br><br>String base64DataKeyId = Base64.getEncoder().encodeToString(dataKeyId.getData());<br>System.out.println(&quot;DataKeyId [base64]: &quot; + base64DataKeyId);</pre><p>Key Name is a friendly name for the <strong>DEK </strong>generated. This can be used to reference the keys in projects.</p><h4>DEK in the database</h4><p>As Seen below the DEK has metadata about the KMS , KeyID and KeyName.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJSdTE7ZhblKf4w5ULRy0g.png" /></figure><p>More about the <strong>DEK </strong>functions can be accessed at <a href="https://docs.mongodb.com/manual/reference/method/js-client-side-field-level-encryption/">link</a></p><p>We validate and create the DEK at the time we initialize the MongoClient in MongoConfig.java</p><pre>@Override<br><strong>public </strong>MongoClient mongoClient() {<br><strong><em>   kmsHandler.buildOrValidateVault();</em></strong><br>   MongoClient mongoClient = <strong>new </strong>MongoClientImpl(getMongoClientSettings(),getMongoDriverInfo());  <em><br>   </em><strong>return </strong>mongoClient;<br>}</pre><h3>Encrypting ,Decrypting and Searching Data</h3><p>As a part of CSFLE community, the client is responsible for manually performing encryption and decryption logic.</p><p>For the Ease of demonstrating this I’ve broken this logic off into it’s own EntityHelper class — <a href="https://github.com/paychex/mongo-csfl-encryption-java-demo/blob/master/mongo-csfle-community/src/main/java/com/paychex/mongo/community/entity/PersonEntityHelper.java">PersonEntityHelper.java</a></p><h4>Encrypting Data</h4><p>To Encrypt the data you will need an initialized instance of ClientEncryption. To keep the implementation standard, we expose clientEncryption as a Bean from KMSHandler.java.</p><p>The Snippet below would produce an Encrypted Instance of Person object.</p><p>NOTE: The type of the Object has to be Bson as we are encrypting the data right in code.</p><pre><strong>public </strong>EncryptedPerson getEncrypedPerson(Person p) {<br><br>   EncryptedPerson ep = <strong>new </strong>EncryptedPerson(p.getFirstName(),p.getLastName());<br>   ep.setSsn(<strong>kmsHandler</strong>.getClientEncryption().encrypt(<strong>new </strong>BsonInt32(p.getSsn()),getEncryptOptions(<strong><em>DETERMINISTIC_ENCRYPTION_TYPE</em></strong>)));<br>   ep.setPhone(<strong>kmsHandler</strong>.getClientEncryption().encrypt(<strong>new </strong>BsonString(p.getPhone()),getEncryptOptions(<strong><em>RANDOM_ENCRYPTION_TYPE</em></strong>)));<br>   ep.setBloodType(<strong>kmsHandler</strong>.getClientEncryption().encrypt(<strong>new </strong>BsonString(p.getBloodType()),getEncryptOptions(<strong><em>RANDOM_ENCRYPTION_TYPE</em></strong>)));<br>   <strong>return </strong>ep;<br>}<br></pre><h4>Decrypting Data</h4><p>A similar method is adopted while decrypting the data from the database.</p><pre><strong>public </strong>Person getPerson(EncryptedPerson ep){<br><br>   Person p = <strong>new </strong>Person(ep.getFirstName(),ep.getLastName());<br>   p.setSsn(<strong>kmsHandler</strong>.getClientEncryption().decrypt(ep.getSsn()).asNumber().intValue());<br>   p.setPhone(<strong>kmsHandler</strong>.getClientEncryption().decrypt(ep.getPhone()).asString().getValue());<br>   p.setBloodType(<strong>kmsHandler</strong>.getClientEncryption().decrypt(ep.getBloodType()).asString().getValue());<br>   <strong>return </strong>p;<br><br>}</pre><h4>Converters</h4><p>Some of the operations may not be supported by native converters. Which may result in an error similar to that below.</p><pre>Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.bson.types.Binary] to type [org.bson.BsonBinary]</pre><p>This means we have to supply our converters as a part of MongoConfig</p><pre><em>/**<br> * Returns the list of custom converters that will be used by the MongoDB template<br> *<br> **/<br></em><strong>public </strong>CustomConversions customConversions() {<br>   CustomConversions customConversions = <strong>new </strong>MongoCustomConversions(<br>         Arrays.<em>asList</em>(<strong>new </strong>BinaryToBsonBinaryConverter(),<br>               <strong>new </strong>BsonBinaryToBinaryConverter()));<br>   <strong>return </strong>customConversions;<br>}</pre><p>It’s as simple as</p><pre><strong>public class </strong>BinaryToBsonBinaryConverter <strong>implements </strong>Converter&lt;Binary, BsonBinary&gt; {<br>   @Override<br>   <strong>public </strong>BsonBinary convert(Binary source) {<br>      <strong>return new </strong>BsonBinary(source.getData());<br>   }<br>}</pre><h4>Searching by Encrypted Field</h4><p>NOTE: You cannot search by Encrypted field only if it was Encrypted with the Deterministic Algorithm.</p><p>To perform the search, Encrypt the field and perform a regular Mongo find() operation</p><pre><strong>public </strong>BsonBinary getEncryptedSsn(<strong>int </strong>ssn){<br>   <strong>return kmsHandler</strong>.getClientEncryption().encrypt(<strong>new </strong>BsonInt32(ssn),getEncryptOptions(<strong><em>DETERMINISTIC_ENCRYPTION_TYPE</em></strong>));<br>}</pre><pre><strong>public </strong>EncryptedPerson findBySsn(BsonBinary ssn);</pre><h3>Code Workflow</h3><p>KMSHandler is initialized to begin with and the DEK is extracted from the database to create the ClientEncryption Bean.</p><p>PersonHandler-runApplication() is invoked from the Application Class to:</p><ul><li>Create the Encrypted Person Object</li><li>Read the Encrypted Person Object</li><li>Search by an an Encrypted Field</li></ul><h3>References</h3><p>libmongocrypt :</p><p><a href="https://github.com/mongodb/libmongocrypt">mongodb/libmongocrypt</a></p><p>Client Encryption Methods:</p><p><a href="https://docs.mongodb.com/manual/reference/method/js-client-side-field-level-encryption/">Client-Side Field Level Encryption Methods - MongoDB Manual</a></p><p>Manual Client Side Field Encryption Documentation:<br><a href="https://docs.mongodb.com/manual/core/security-explicit-client-side-encryption/">https://docs.mongodb.com/manual/core/security-explicit-client-side-encryption/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9775e8c169" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Client Side Field Level Encryption (CSFLE) on MongoDB: Part 1 — An Introduction]]></title>
            <link>https://visweshwar.medium.com/client-side-field-level-encryption-csfle-on-mongodb-community-ed-using-java-spring-a6489a5c9146?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6489a5c9146</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[client-side-encryption]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Wed, 22 Jan 2020 12:23:38 GMT</pubDate>
            <atom:updated>2020-01-22T12:30:02.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>Client Side Field Level Encryption (CSFLE) on MongoDB: Part 1 — An Introduction</h3><p>Starting with Mongo 4.2 the official drivers provide a Client Side Field Level Encryption (CSFLE) framework. This basically brings in encryption and decryption down to the application and the data at REST is always encrypted. Only the application which possess the right encryption keys will be able to encrypt/decrypt the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*mp5p3IY3bLBPLDs7GmZu4A.png" /></figure><h3>Different Methods of Securing data Today</h3><p>Encryption of data is not new in MongoDB or for that matter in any system. Opportunities for Encryption is available at multiple stages. The critical questions are:</p><ul><li>Where should the data be visible in the clear?</li><li>Who should posses the keys to decryption?</li><li>How should the keys be accessed?</li></ul><p>Here is a visual representation of different areas of Encryption and where does CSFLE come into picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QpNvQSXNubZDQ9g_.png" /><figcaption>MongoDB Encryption and Security features <em>(Image Credits: </em><a href="https://docs.mongodb.com/ecosystem/_images/CSFLE_Security_Feature_Chart.png"><em>MongoDB</em></a><em>)</em></figcaption></figure><p>With MongoDB 4.2 we now have a relatively more flexible solution to the above questions with CSFLE.</p><h3>What is CSFLE at a high level?</h3><p>The Client will deal with Encryption and Decryption of Data using a secure key (DEK).</p><h4>What are the Keys we are dealing with?</h4><ul><li>There are two Keys in play namely <strong>Data</strong> <strong>Encryption Key(DEK)</strong> and <strong>Customer Master Key(CMK)</strong></li><li>Customer Master Key: This essentially is a root key which is used to Encrypt or Decrypt the <strong>DEK. </strong>This key has to be secured using a Key Management System (<strong>KMS</strong>)</li><li>The Data Encryption Key: A key generated by libmongocrypt and encrypted using the <strong>CMK</strong>. The <strong>DEK</strong> will be used to encrypt and decrypt data. This Strategy is based on <a href="https://ironcorelabs.com/docs/concepts/envelope-encryption/">Envelope Encryption</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ybf6p2GWpicF2KGkx_jJ9g.png" /></figure><p>We’ve answered two questions:</p><ul><li><strong>Who should posses the keys to decryption?</strong> There isn’t one entity that stores the key. The application will not only need access to the <strong>KMS</strong> but, will also need access to the key vault database. Possession of either the <strong>DEK</strong> or the <strong>CMK </strong>alone will not suffice.</li><li><strong>How should the keys be accessed? </strong>How the <strong>CMK</strong> and <strong>DEK </strong>are secured is upto the one’s implementation. The best practice is to use a <strong>KMS* </strong>and store the <strong>DEK </strong>on a cluster which doesn’t have the data.</li><li>MongoDB currently only supports Amazon’s KMS and Local.</li></ul><h4>How does the application use the DEK?</h4><p>As illustrated in the diagram, the Application delegates all the encryption and decryption activity to the driver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*Z05tdZSpsHnZ7r9t-H-FxA.png" /><figcaption>Client side Data Access</figcaption></figure><p>Now here is where the difference between the Enterprise and Community edition comes into play.</p><p><strong>Enterprise Edition &amp; Atlas </strong>will automatically encrypt and Decrypt data based on a Schema and a process called Mongocryptd</p><p><strong>Community Edition </strong>The application will have to request encryption and decryption on the data retrieved.</p><p>We will demo both workflows.</p><h4>What are the Encryption Algorithms supported?</h4><p>MongoDB supports two versions of AES-256-CBC Encryption Algorithm</p><blockquote>MongoDB client-side field level encryption uses the encrypt-then-MAC approach combined with either a deterministic or random initialization vector to encrypt field values. MongoDB <em>only</em> supports the <a href="https://en.wikipedia.org/w/index.php?title=Authenticated_encryption&amp;oldid=925133676">AEAD</a> AES-256-CBC encryption algorithm with HMAC-SHA-512 MAC. — <a href="https://docs.mongodb.com/manual/core/security-client-side-encryption/#encryption-algorithms">Official Documentation</a></blockquote><p>In plain language:</p><p><strong>Deterministic Encryption</strong></p><p>With Deterministic Encryption a given value will encrypt to the same output value every time. This should be used when the value being encrypted is going to be used in read operations i.e. as a query parameter. NOTE: This can be susceptible to Frequency analysis recovery.</p><p>Example: Encrypting Phone Number or DOB. These are values that will be queried against.</p><p><strong>Random Encryption</strong></p><p>With Random Encryption a given value will encrypt to a different output every time. This makes these fields ineligible to be queried against. NOTE: This means you can still retrieve the value, just that you cannot query against it. This makes it ideal to store highly sensitive data that one shouldn’t be allowed to query against.</p><p>Example SSN, Credit Card Information. These are not generally search fields on a document.</p><h3>Automatic Field Decryption</h3><p>Automatic Field Decryption is available only with the Enterprise Edition or Atlas of MongoDB.</p><p>This uses <em>mongocryptd </em>to achieve the same.</p><p>The data is stored in Binary format (BinData) and contains the following information. <br>NOTE: This is just for representational purposes.</p><pre>BinData: {<br>DEKMetaData:{<br>    keyId:Value<br>    KMS:AWS<br>},<br>Algorithm: Deterministic<br>}</pre><p>The Rules to process the data retrieved is represented as below. Please read the <a href="https://docs.mongodb.com/manual/core/security-client-side-encryption/#automatic-field-decryption">official documentation</a> for details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8J5AQHjcfAnowGr40geMpQ.png" /></figure><h3>Schema for Automatic Field Level Encryption</h3><p>MongoDB uses the extended version of JSON Schema for<a href="https://docs.mongodb.com/manual/reference/method/Mongo/#clientsidefieldlevelencryptionoptions"> automatic Client side encryption.</a></p><p>The schema contains the following information</p><ul><li>The algorithm</li><li>The <strong>DEK</strong></li><li>BSON Type of the field (Only required for Deterministic Encrypted Fields).</li></ul><p>This schema can be configured at two places</p><p>a) This schema can be configured at the client level: This is enforced at a driver level and automatically encrypts or decrypts the data.</p><p>b) This schema can also be enforced at the database level. In which case if a client fails to encrypt the data, the driver will retrieve the schema configured on the server side and use it to perform automatic FLE.</p><p>NOTE: This requires the client to trust the server has a valid schema with respect to AutoFLE.</p><p><strong>NOTE: The Schema used for FLE is not the same a schema used to validate a document.</strong></p><p><em>Coming up: How to perform FLE using community and enterprise edition of MongoDB.</em></p><h4>References:</h4><ul><li><a href="https://docs.mongodb.com/ecosystem/use-cases/client-side-field-level-encryption-guide/">Client-Side Field Level Encryption Guide - MongoDB Ecosystem</a></li><li><a href="https://docs.mongodb.com/ecosystem/use-cases/client-side-field-level-encryption-local-key-to-kms/">Client-Side Field Level Encryption: Use a KMS to Store the Master Key - MongoDB Ecosystem</a></li><li><a href="https://docs.mongodb.com/manual/core/security-automatic-client-side-encryption/">Automatic Client-Side Field Level Encryption - MongoDB Manual</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6489a5c9146" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Functions using Java Spring with CI/CD using Azure Pipelines— Part 2]]></title>
            <link>https://visweshwar.medium.com/azure-functions-using-java-spring-with-ci-cd-using-azure-pipelines-part-2-44b341e9728e?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/44b341e9728e</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Wed, 02 Oct 2019 01:52:41 GMT</pubDate>
            <atom:updated>2019-10-02T01:52:41.673Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5qAh_CIxlEYgOsFoMUkNjQ.jpeg" /></figure><p>This is a continuation from the<a href="https://medium.com/@visweshwar/azure-functions-using-java-spring-with-ci-cd-part-1-d63444a5b2fd"> Part 1 </a>which covered, setting up a local environment and publishing the application locally to Azure.</p><p>This part is going to cover the following</p><ol><li>Adding Spring Boot to the application</li><li>Enabling Azure Pipelines.</li></ol><h3>Azure Functions with Spring Boot 2</h3><p>Spring Boot 2.0 tries to keep the best of both worlds with Azure functions. It allows us to use native Azure Annotations and Spring Beans.</p><p><strong>Azure Annotations in a Spring Project</strong></p><p>A sample Azure Function</p><pre>@FunctionName(<strong>&quot;hellospring&quot;</strong>)<br><strong>public </strong>HttpResponseMessage run(<br>        @HttpTrigger(name = <strong>&quot;req&quot;</strong>, methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage&lt;Optional&lt;String&gt;&gt; request,<br>        <strong>final </strong>ExecutionContext context) {<br>...<br>...<br>}</pre><p>This can be used in it’s native form in a Java class that extends AzureSpringBootRequestHandler</p><p>This is now then followed up with a Spring Bean with the same name that of the function</p><pre>@Bean<br><strong>public </strong>Function&lt;String, String&gt; hellospring(){<br>   <strong>return </strong>name -&gt; <strong>name.toUpperCase()</strong>;<br>}</pre><p>We’ll get back to this later.</p><p><strong>Add Spring libraries to the project</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20530ac6d05e3bf771f2f635e6fd0b1a/href">https://medium.com/media/20530ac6d05e3bf771f2f635e6fd0b1a/href</a></iframe><p><strong>Note: With Spring you will have to indicate the location of the main class.</strong></p><pre>&lt;<strong>mainClass</strong>&gt;com.example.functions.Application&lt;/<strong>mainClass</strong>&gt;</pre><h3>Our Spring Azure Function</h3><p>Our example will retrieve a User object for a given User ID.</p><p><strong>The Application Class</strong></p><p>Let’s add Application to the root of the project</p><pre>package com.example.functions;<br><br>import com.example.functions.model.User;<br>import java.util.ArrayList;<br>import java.util.function.Function;<br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.context.annotation.Bean;<br><br>@SpringBootApplication<br>public class Application {<br><br>	public static void main(String[] args) {<br>		SpringApplication.run(Application.class,args);<br>	}<br><br>	private ArrayList&lt;User&gt; users = new ArrayList&lt;User&gt;(){{<br>		add(new User(1,&quot;userone&quot;,&quot;User&quot;,&quot;One&quot;));<br>		add(new User(2,&quot;usertwo&quot;,&quot;User&quot;,&quot;Two&quot;));<br>		add(new User(3,&quot;userthree&quot;,&quot;User&quot;,&quot;Three&quot;));<br>		add(new User(4,&quot;userfour&quot;,&quot;User&quot;,&quot;Four&quot;));<br>	}};<br>        <strong>// This bean basically returns the User Object..</strong></pre><pre>	@Bean<br>	public Function&lt;String, User&gt; GetUser(){<br>		return userId -&gt; users.get(Integer.valueOf(userId)-1);<br>	}<br>}</pre><p><strong>User POJO</strong></p><pre><strong>package </strong>com.example.functions.model;<br><br><strong>public class </strong>User {<br>   <strong>private int id</strong>;<br>   <strong>private </strong>String <strong>username</strong>;<br>   <strong>private </strong>String <strong>fName</strong>;<br>   <strong>private </strong>String <strong>lName</strong>;<br><br>   <strong>public </strong>User() {<br>   }<br><br>   <strong>public </strong>User(<strong>int </strong>id, String username, String fName, String lName) {<br>      <strong>this</strong>.<strong>id </strong>= id;<br>      <strong>this</strong>.<strong>username </strong>= username;<br>      <strong>this</strong>.<strong>fName </strong>= fName;<br>      <strong>this</strong>.<strong>lName </strong>= lName;<br>   }<br><br>   <strong>public int </strong>getId() {<br>      <strong>return id</strong>;<br>   }<br><br>   <strong>public void </strong>setId(<strong>int </strong>id) {<br>      <strong>this</strong>.<strong>id </strong>= id;<br>   }<br><br>   <strong>public </strong>String getUsername() {<br>      <strong>return username</strong>;<br>   }<br><br>   <strong>public void </strong>setUsername(String username) {<br>      <strong>this</strong>.<strong>username </strong>= username;<br>   }<br><br>   <strong>public </strong>String getfName() {<br>      <strong>return fName</strong>;<br>   }<br><br>   <strong>public void </strong>setfName(String fName) {<br>      <strong>this</strong>.<strong>fName </strong>= fName;<br>   }<br><br>   <strong>public </strong>String getlName() {<br>      <strong>return lName</strong>;<br>   }<br><br>   <strong>public void </strong>setlName(String lName) {<br>      <strong>this</strong>.<strong>lName </strong>= lName;<br>   }<br>}</pre><p><strong>Azure Handler for the function</strong></p><p>The Azure Function declared is very close to that in native Java. It’s just that it’s embedded inside a class which extends <a href="https://cloud.spring.io/spring-cloud-function/multi/multi__serverless_platform_adapters.html">AzureSpringBootRequestHandler</a>.</p><p>You can read more about the <a href="https://cloud.spring.io/spring-cloud-function/multi/multi__serverless_platform_adapters.html">AzureSpringBootRequestHandler</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/672e6c35a77d14c4fe9f6c82465f65cd/href">https://medium.com/media/672e6c35a77d14c4fe9f6c82465f65cd/href</a></iframe><p>The basic call flow is going to be as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GieLhbLBpHsnRWeJLBouoA.png" /></figure><h3>Azure CI/CD Pipeline</h3><p><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/?view=azure-devops">Azure Pipelines </a>enable us to be able to deploy code from source control directly into Azure.</p><p><strong>How to get to Pipelines and connect to Github</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*dw_IThnmDx_OQrXbbVLzjQ.png" /></figure><p>I’m planning to use Github as my Source control</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJ_UghmwBmihwuBE6fiNSA.png" /></figure><p>We’ll be using Azure Pipelines</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wYurn_CsGb9kpBJ7vnrmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvN_YiCsHULO_UHJxiR80w.jpeg" /></figure><p>Follow into next for Summary</p><p><strong>Build pipeline</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q8iL0zV3eRrvWPUp9ihQoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2JO3uR5fNDXy9V4wIKsng.png" /></figure><p>You will see the pipeline created. We can now edit this pipeline to perform the following</p><p>a) Build the code<br>b) Package the code<br>c) Deploy the code</p><p>Click the Edit Button on the Top right to configure your pipeline.</p><p>The initial Pipeline will have a few default steps, <strong>these don’t work with the java app </strong>and we will have to modify the same to match that below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQ3ht8_DIkLdTPQvMUE9vg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3oHfwE_pfoFWOfW9ZFEmfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ya7tfSyfWk9tHqPn0pZQrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xDhsvi_qPg55gsavs5KY4A.png" /></figure><p>The Azure Subscription will be set as a variable in the next step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FW7BQnnsEoYQCcm1ZQnPzQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yNdZSvSed2bJEcsGYWWqYA.png" /></figure><p>You may have to optionally approve the use of the subscription on a later step.</p><p>Once you Save &amp; Queue the job this should trigger a build and you’ll be able to follow the build steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyOFYEvf0pldwfC6p2aY7g.png" /></figure><p>You should be able to validate that the function is now published</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IGa835EUuBeVz8V97t1oiA.png" /></figure><p>Additionally you should be able to view your folder structure by using the command line view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxVltxY-aE_sUathSX_ttQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7WJzGEc1VvDF8LeG7I49WQ.png" /></figure><p>You optionally can source control the pipeline too..</p><h3>Conclusion</h3><p>This ends the 2 part document on how to publish Java Spring functions using CI/CD into Azure Functions using Azure Pipelines.</p><p>The Github location for all the files above is</p><p><a href="https://github.com/visweshwar/AzureFunctions-Java-CI-CD">https://github.com/visweshwar/AzureFunctions-Java-CI-CD</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44b341e9728e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Functions using Java Spring  with CI/CD — Part 1]]></title>
            <link>https://visweshwar.medium.com/azure-functions-using-java-spring-with-ci-cd-part-1-d63444a5b2fd?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d63444a5b2fd</guid>
            <category><![CDATA[azure-pipelines]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Mon, 30 Sep 2019 10:27:09 GMT</pubDate>
            <atom:updated>2019-10-02T02:10:18.782Z</atom:updated>
            <content:encoded><![CDATA[<h3>Azure Functions using Java Spring with CI/CD — Part 1</h3><p>Over the past few days I’ve been exploring using Azure functions, evaluating the feature set , CI / CD pipeline capabilities. In short, it checked all the boxes for a basic application.</p><p>This post will cover the following:</p><ul><li>Setting up a local environment for testing</li><li>Deploying a Simple Function To Azure</li><li>Using Spring Boot for Functions</li><li>Enabling Azure CI/CD with github and Azure Pipelines</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVQt7wg6u_iGW1itzg-wUw.png" /></figure><p>This Post is NOT intended to be</p><ul><li>A production deployment strategy</li><li>A reference implementation for code</li></ul><p>This Post is going to be Divided into Two Parts</p><ol><li>Local Setup, getting functions running in Azure</li><li>Setting Up Spring Boot, Github and Pipelines</li></ol><h3>Prerequisites for following along</h3><ul><li>JDK 8+ environment</li><li>Basic Knowledge of a Java build system (Maven)</li><li>Azure Subscription (Even Trial would suffice)</li><li>Github account (Thanks to <a href="https://medium.com/u/8df3bf3c40ae">GitHub</a> &amp; <a href="https://medium.com/u/940e606ec51a">Microsoft + Open Source</a> you can create a free private repos)</li></ul><h3>Local Environment Setup</h3><p>We need to install certain libraries.</p><ul><li><a href="https://maven.apache.org/install.html">mvn</a> 3+</li></ul><pre>$ mvn -v<br>Apache Maven 3.5.0</pre><ul><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">Azure-cli</a></li></ul><pre>$ az --version<br>azure-cli 2.0.74</pre><ul><li><a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#v2">Azure Functions Core Tools</a> version 2.6.666 or above</li></ul><pre>$ func -v<br>2.7.1633</pre><h3>Using an mvn archetype for our starter code</h3><p>You can go about this two ways:</p><ul><li>Command Line</li><li>IDE (I’m going to use IntelliJ for this Post)</li></ul><p><strong>Using Command Line to Generate the Project</strong></p><p>Go to a new Directory where you plan to work from</p><pre>Bash (Linux / Mac)</pre><pre>mvn archetype:generate \     <br>-DarchetypeGroupId=com.microsoft.azure \  -DarchetypeArtifactId=azure-functions-archetype</pre><pre>Windows (Cmd)</pre><pre>mvn archetype:generate ^<br> &quot;-DarchetypeGroupId=com.microsoft.azure&quot; ^<br> &quot;-DarchetypeArtifactId=azure-functions-archetype&quot;</pre><p>Below are the values to fill. Note appName has to be unique across Azure</p><pre>Define value for property &#39;groupId&#39; (should match expression &#39;[A-Za-z0-9_\-\.]+&#39;): com.example.functions <br>Define value for property &#39;artifactId&#39; (should match expression &#39;[A-Za-z0-9_\-\.]+&#39;): example-functions <br>Define value for property &#39;version&#39; 1.0-SNAPSHOT :  <br>Define value for property &#39;package&#39;: com.example.functions <br>Define value for property &#39;appName&#39; example-functions-20190927220323382: <br>Define value for property &#39;appRegion&#39; eastus: : <br>Define value for property &#39;resourceGroup&#39; java-functions-group: : Confirm properties configuration: Y</pre><p><strong>Using IntelliJ IDE to achieve the same</strong></p><p>Add the Azure Archetype and create the Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*qgHZvPoHOLH-4m4Zr9CQ-w.png" /><figcaption>Add the Azure Functions archetype to IntelliJ</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*dLSivNPQzViLxten_rLmTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*v0vNRB-C2sG6vjWqXAjHRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*z2YO4klvHmdZIcIrSefruA.png" /></figure><h3>File Structure</h3><p>You should have a file structure something similar to that below.</p><pre>bash-3.2$ tree examplefunctions/<br>examplefunctions/<br>├── examplefunctions.iml <strong>Ignore this file, intellij File</strong><br>├── host.json <strong>This is the Azure Host property file</strong><br>├── local.settings.json <strong>This is the file for local development</strong><br>├── package-lock.json<br>├── pom.xml<br>└── src<br>    ├── main<br>    │   └── java<br>    │       └── com<br>    │           └── example<br>    │               └── functions<br>    │                   └── Function.java<br>    └── test<br>        └── java<br>            └── com<br>                └── example<br>                    └── functions<br>                        ├── FunctionTest.java<br>                        └── HttpResponseMessageMock.java</pre><h3>Test Locally</h3><ol><li>Package the project mvn clean package</li><li>Modify the local-settings.json to choose your port (default 7071)</li><li>Add this to the settings</li></ol><pre><br><strong>&quot;Host&quot;</strong>: {<br>  <strong>&quot;LocalHttpPort&quot;</strong>: 8091,<br>  <strong>&quot;CORS&quot;</strong>: <strong>&quot;*&quot;</strong>,<br>  <strong>&quot;CORSCredentials&quot;</strong>: <strong>false<br></strong>}</pre><p>4. Run the project locally mvn azure-functions:run</p><p>You should see something like this in your console.</p><pre>Now listening on: <a href="http://0.0.0.0:8091/">http://0.0.0.0:8091</a><br>Application started. Press Ctrl+C to shut down.</pre><pre>Http Functions:</pre><pre>HttpTrigger-Java: [GET,POST] <a href="http://localhost:8091/api/HttpTrigger-Java">http://localhost:8091/api/HttpTrigger-Java</a></pre><p>5. Test the server</p><pre>bash-3.2$ curl -w &quot;\n&quot; <a href="http://localhost:8091/api/HttpTrigger-Java">http://localhost:8091/api/HttpTrigger-Java</a> -d LocalFunction<br>Hello, LocalFunction</pre><h3>Concepts</h3><p>What we’ve done so far is, we’ve downloaded and template and just ensured the template is working. The main activity happens in Function.java</p><p>The Annotation @FunctionName defines the name of the function which is unique to the project. There are <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings">different triggers</a> which you can associate to on Azure (<a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook">HttpTrigger</a> being the one being shown below).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d97bffb599411488803a8c509dd15fc0/href">https://medium.com/media/d97bffb599411488803a8c509dd15fc0/href</a></iframe><p>After we package the application, individual functions are exposed in the package with a manifest on how to trigger the jar. See below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25CUrOZzWwZuobXle8uNhw.png" /></figure><h3>Deploying to Azure</h3><p>We will deploy to azure through the command line.</p><p>To begin with we have to login into Azure through the command line</p><p>az login</p><pre>bash-3.2$ az login<br>Note, we have launched a browser for you to login. For old experience with device code, use &quot;az login --use-device-code&quot;<br>You have logged in. Now let us find all the subscriptions to which you have access...</pre><p>We will then have to initiate a deploy using maven</p><p>mvn azure-functions:deploy</p><pre>[INFO] Trying to deploy artifact to example-functions-20190929215243949...<br>[INFO] Successfully deployed the artifact to <a href="https://example-functions-20190929215243949.azurewebsites.net/">https://example-functions-20190929215243949.azurewebsites.net</a><br>[INFO] Successfully deployed the function app at <a href="https://example-functions-20190929215243949.azurewebsites.net/">https://example-functions-20190929215243949.azurewebsites.net</a></pre><p>Navigate to <a href="https://portal.azure.com/">https://portal.azure.com</a></p><p>You can then go to the Resource called Function App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*95pnhnEjjEp3m5mZpMi_0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpbKXMF5rMmImr4WPjr28Q.png" /></figure><p>This has been Successfully deployed. Let us retrieve the code to test this. You can capture the hosty key for master or create a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N--TfuxSMO1VynTllYBJSg.png" /></figure><p>To Test this we can use the published URL and curl at it.</p><pre>curl -G <a href="https://example-functions-20190929215243949.azurewebsites.net/">https://example-functions-20190929215243949.azurewebsites.net</a>/api/HttpTrigger-Java -d AzureFunction -d code=&lt;code&gt;</pre><p>or You can use the browser</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*4b6w0euWUttLCPpSdZZV0g.png" /></figure><p><strong>Part 2</strong></p><p>Azure Functions using Java Spring with CI/CD using Azure Pipelines — Part 2 <a href="https://link.medium.com/sSPPLEVHr0">https://link.medium.com/sSPPLEVHr0</a></p><h3>References</h3><p>Azure Functions <a href="https://azure.microsoft.com/en-us/services/functions/">https://azure.microsoft.com/en-us/services/functions/</a><br>Azure Functions using Java <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven">https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-java-maven</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d63444a5b2fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging a custom Spring Security Filterchain]]></title>
            <link>https://visweshwar.medium.com/debugging-a-custom-spring-security-filterchain-3a2ea3f5ee38?source=rss-fbf6ff79988c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a2ea3f5ee38</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-security]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[troubleshooting]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Visweshwar Ganesh]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 01:00:01 GMT</pubDate>
            <atom:updated>2020-03-21T22:55:41.531Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Spring Security allows you to intersperse Filters in your application for a given URI pattern. This can get quite complex with multiple URIs and different filter combinations for a given URI (<a href="https://www.baeldung.com/spring-security-custom-configurer">Configurer</a>). Spring Security has a default filterchain and is very well documented. (As Below). But this can get a bit complex with<a href="https://www.baeldung.com/spring-security-custom-configurer"> custom Configurers</a></p><p><a href="https://docs.spring.io/spring-security/site/docs/3.0.x/reference/security-filter-chain.html">The Security Filter Chain</a></p><p>But there comes a times where you have to identify the <a href="https://www.baeldung.com/spring-boot-add-filter">Order</a> of a given configuration or URI, in addition to the order of the filters for that configuration.</p><p>One way is to document your Filters for an complex application but, at times it can get unwieldy in the age of annotations.</p><p>Below are two quick ways to identify the following</p><p>a) The Order of the Configurers<br>b) The order of Filters in a given Configurer</p><p><strong>The Order of the Configurers</strong></p><p>There can be multiple filters in a given FilterChainProxy. This gives us the flexibility to tailor the filters by URI</p><p>Now In addition the the flexibility of the Filters for a given URI Pattern, you can also dictate the order the URI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tD76AZrjXvfpqJ8C.png" /></figure><p>The best way to debug the Order of your configuration is to place a breakpoint in SpringSecurityFilterChain.java at startup. This will reveal the Order of the Configurers.</p><p>To Illustrate this I’m going to use an implementation of OpenID. The screenshot below illustrates the list of configurers and the order of Configurers that the application is going to encounter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NR3Muclv8aTTzEJ1Q7-4Qg.png" /><figcaption>List of Configurers for the application</figcaption></figure><p><strong>The order Filters in a given Configurer</strong></p><p>The order of filters in a given configurer can be quite complex and debugging a configuration at runtime can get quite time consuming. A bird’s eye view of the filters can be again obtained at startup.</p><p>A quick view can be obtained from SpringSecurityFilterChain.java</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPykcj9tYyB-2xwLVRdXhA.png" /><figcaption>High level List of Filters for a given Configurer.</figcaption></figure><p>Now you can also go very detailed down to the filter order number (Note: The Filter order number here may not match the number you’ve had provided. But, it will still be place relatively in the same order)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1h6L53CmQWmZnl_7y0tzA.png" /><figcaption>Detailed Filter Order</figcaption></figure><p>This should give you enough to not only debug your ordering but, also will give you a better insight into the chain.</p><h3>Checking the Filter chain at runtime</h3><p>Every request goes through process of identifying and matching for a filter chain in ApplicationFilterFactory</p><pre><strong>public static </strong>ApplicationFilterChain createFilterChain(ServletRequest request,<br> Wrapper wrapper, Servlet servlet)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*_1CNtSFDnRUoe3v6lzq9kQ.png" /></figure><p>This is where it matches for a given URI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*VZmRTjmLBvXuzYFsMbTJmg.png" /></figure><p>The match can help you identify which Filter chain was picked up and how the match was performed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bAPy4FZvhccBDQH2GeUj3g.png" /></figure><p>This will ultimately provide the list of filters that got added to the chain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Absjq6v5tMBscfpKTkrIQ.png" /></figure><p><strong>Recommended Reading</strong></p><ul><li><a href="https://spring.io/guides/topicals/spring-security-architecture">Spring Security Architecture</a></li><li><a href="https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/">Spring Security Reference</a></li></ul><p><strong>Summary</strong></p><p>For those who have really felt the pain and ignorance of the “Spring magic”, I hope this adds helps you not reinvent the wheel or lose time debugging spring Security Filter chain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a2ea3f5ee38" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>