<?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 Hansika Samaraweera on Medium]]></title>
        <description><![CDATA[Stories by Hansika Samaraweera on Medium]]></description>
        <link>https://medium.com/@hansika.m99?source=rss-f11cf47336c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LVmHi46uA92VHT5J</url>
            <title>Stories by Hansika Samaraweera on Medium</title>
            <link>https://medium.com/@hansika.m99?source=rss-f11cf47336c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:33:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hansika.m99/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[Distributed Computing]]></title>
            <link>https://medium.com/@hansika.m99/distributed-computing-1403371a5e66?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1403371a5e66</guid>
            <category><![CDATA[remote-method-invocation]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Fri, 22 Jul 2022 08:25:47 GMT</pubDate>
            <atom:updated>2022-07-22T08:25:47.552Z</atom:updated>
            <content:encoded><![CDATA[<p>Methods calls for objects in the same heap. Also, can invoke method on object in different machine. Machines get information from another machines using sockets and I/O. OutputStram send data t another machine through a socket connection. We can call another method on another computer that running on different JVM. But it cannot do directly. Remote Method Invocation is a mechanism that allow to invoke another machined method.</p><p>RMI design have four things as server, client, server helper, and client helper. Create client and server apps and the server app is remote service that has object with the invoking method, the client server helpers are responsible for communication. It helps client to act on local object of calling method. As real-world client helper is a proxy. But client helper is not a remote service and doesn’t contain actual method logic. It connects the server and send details of the method call. The server helper gets the request from client helper through a socket connection, and it get the details about method call. Server helper is the one who invoke the real method on real service object. Service helper return the value to the client helper and it unpack details and gives to client object.</p><p>RMI build client and service helper object and it look like a real service. The runtime environment provides by RMI including lookup service and allow client to find the client helper. RMI doesn’t have to write I/O or network configurations. The difference between RMI and normal method call is client looks like finding local method, but client helper sends the call through the network.</p><p>When using RMI have to choose protocols like JRMP, IIOP.JRMP from RMI native protocols. Java vs Java RMI use IIOP protocol, and it is use for CORBA.</p><p>The client helper called as stub and server helper called as skeleton in RMI. To create them first wants to create Remote Interface. It is use as stub and actual service. Then another class for remote implementation. Then generate the stub and skeleton can do by using rmic.</p><p>rmic MyRemoteImpl</p><p>the RMI registry should start, and it is similar to a phonebook. User can get stub and client helper from this registry. Then the remote service can start.</p><p>The remote interface should extend the java.rmi.Remote interface. Then the throwing a RemoteException is important because when client invoking the remote method some exceptions can occur. The return values and arguments should be primitive or serializable because those are travel through the network.</p><p>The remote implementation should implement the Remote interface. Also, should extend the UnicastRemoteObject for to give some functionalities to the object relating remote. There should be a default constructor with no arguments and declare the RemoteException. Also, it should register with the RMI registry.</p><p>Generating stubs and skeletons should do by run rmic on remote implementation class. RMI automatically creates the stub and skeleton. Then start the RMI registry and start other services. Client gets the stub object when does a lookup and RMI registry gives the stub.</p><h3>Reference</h3><p>[1] Bates, Bert, and Kathy Sierra. “Head First Java Second Edition.” (2021).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1403371a5e66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create REST service with nestJS]]></title>
            <link>https://medium.com/@hansika.m99/create-rest-service-with-nestjs-4e467ef91c08?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e467ef91c08</guid>
            <category><![CDATA[create-project]]></category>
            <category><![CDATA[nestjs]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 14:39:10 GMT</pubDate>
            <atom:updated>2022-07-21T14:39:10.815Z</atom:updated>
            <content:encoded><![CDATA[<p>Node has become stronger backend framework to write backends, but the problem node has is in no opinion back the node.js govern the backend architecture. nowadays there is a solution for that nest.js is a typescript framework which use to write backends. The JavaScript is not type dependent and not govern by types, but typescript is deal with the types. In nest.js backend the code writes by typescript and nest.js transcompiled and run which is compile one source language to another. Spring boot has controllers, services, repository, dependency injection all take as a family and nest.js take those opinions and put into a framework make work easy.</p><p>Nest is a efficient and scalable node server side framework.it is a combination of object oriented and functional programming. It uses HTTP server frameworks like express.</p><p>Node can install as following and can see the version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ziMAs_x3o1HmZ-hOr7kehw.png" /></figure><p>Then create a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*EdbhhMIkcDU0q_jjkql_lA.png" /></figure><p>This is the file structure and include with config files and module files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7mK_tBaBsBdawQMSHMqdoQ.png" /></figure><p>Module concept is a major role on nest.js architecture. each application has a module called root and it use internal data structure to resolve module and provider relationships and dependencies. These modules are encapsulated and singleton in default. It is impossible to inject providers from current module or external module. So, use export providers from a module as interface. Because it is singleton the same interface can provider between multiple modules. All the modules are reusable by any module because its automatically shared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*kGNxBCjaWS_txqc396iVXw.png" /></figure><p>Then the employee module has created. Then need to create a controller to get the employee data and controller for handle the requests. Also, the controller has created as same way as module created. Controllers handle the request and return the response to the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*WA68JRtc_6P2eRXPfUm5og.png" /></figure><p>The spec.ts file has no use for now. So, its fine to delete that file. The controller delegate the request.</p><p>The providers are fundamental concept, and it can inject dependencies. Objects create relationships each other and wiring up function instance of object can largely delegate. Controllers handle HTTP request and provide complex tasks to providers and all providers are not services.</p><p>Then the services generated as the same way without.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*F4zyZ92_TTioJmBy_EBg3Q.png" /></figure><p>The controller handles the get request and service expose the employee array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*26PVAtjRpVEDJTe33ZgAmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*ko9IjV96FZhOJz7-Y8W7ew.png" /></figure><h3>Reference</h3><p>[1] Krish Dinesh.” Create rest services with NestJS” Available: <a href="https://www.youtube.com/watch?v=n7R8fwLTfDg&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;index=22&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=n7R8fwLTfDg&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;index=22&amp;ab_channel=KrishDinesh</a> [Accessed: July 21,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e467ef91c08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create and Deploy Service on Docket]]></title>
            <link>https://medium.com/@hansika.m99/create-and-deploy-service-on-docket-361e916adf23?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/361e916adf23</guid>
            <category><![CDATA[doker]]></category>
            <category><![CDATA[deploy]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 10:28:10 GMT</pubDate>
            <atom:updated>2022-07-21T10:28:10.477Z</atom:updated>
            <content:encoded><![CDATA[<p>In the docker technology the number of course and number of containers doesn’t relevant each other directly. Docker is a container which is another process to the operation system. The docker should configure in proper way to run in the production without using out of the box containers or bus blockers. When run docker can give the instruction how much of time for the container. Docker use a principle called allocate and share that means can do process allocation for container. If the container running can say need to allocate this much of microseconds to the container from the processing power. Then out of 100000 microseconds for this container takes. After that docker engine will take care of allocating the requested processing power into the CPU into the container. In that case container not going to take that all. Container running a program which causing a CPU hog if that problem should take care. Even though that happened since properly CPU has allocated time to the container it won’t affect of other containers. Because no matter how much CPU born it won’t go beyond the allocation.</p><p>Usually, kernels have a process called lines and read eyes which means it may have a 32 course but does not say can only run 32 processors on the machine. When have multiple processers more than have in the core docker take care of the allocating the processors or CPU into a thread.</p><p>Installing docker into the windows need to have operating system at least windows 10. If not, there is a other tool called docker toolbox and work on docker. If download that it has to face few problems. It installs docker toolbox to the computer along with VM and it installs Linux VM automatically. After installation when run docker commands on the terminal it passed that to the VM. Then the Linux VM will process those commands. After installing docker toolbox it needs to run environment command on local machine. If its behind the proxy may have to install a proxy to download docker images but the confusing thing is if proxy is configuring on the local machine, it does not work. So, should go to the VM and clean ups the images and configure the proxy over there.</p><p>Docker desktop can install easily to the machine and can create a standard file using following command.</p><p>touch Dockerfile</p><p>To work with the file, open the file in editor. A specific docker image can download to the machine which go to the docker hub and carapace it whenever the docker repository download.</p><h3>Reference</h3><p>[1] Krish Dinesh.” How to create and deploy services on Docker. Step by Step guide from the scratch .” Available: <a href="https://www.youtube.com/watch?v=iY55wEiYFQY&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=8&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=iY55wEiYFQY&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=8&amp;ab_channel=KrishDinesh</a> [Accessed: July 20,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=361e916adf23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservice vs Serverless]]></title>
            <link>https://medium.com/@hansika.m99/microservice-vs-serverless-11c59f89d5ac?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/11c59f89d5ac</guid>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 07:36:30 GMT</pubDate>
            <atom:updated>2022-07-21T07:36:46.750Z</atom:updated>
            <content:encoded><![CDATA[<p>Microservice is an architecture and serverless is a protocol. The difference between architecture and protocol is in architecture can apply some modification after build. But should be able to handle the risk. So, in the microservice architecture can use any language, platform, or any tool to build the system. Microservice should be developed to work independently and independently scalable. Also, should have bounded context.</p><p>When there is a microservice architecture system with employee service and HR service they should interact with each other but have deploy independently. If those two services had the same database when employee service have a huge traffic and wanted to scale it can be scale but create a bottleneck on the HR service. It is fine to have a shared database until it does not impact other when scale.</p><p>Serverless is a different context. Once the microservice created and if there are three services, they develop using different languages and deploy independently. This is possible because they communicate with each other over http protocol which is commonly use. The three services can deploy in docker in different platforms. But to do that should have devOps team. Because they should take care of creating clusters, memory allocation, security and administrating etc. then have to manage development and deployment. Serverless means only focusing on program, function, or developer. It doesn’t have to care about how the system deploy or how it scales. Also, when microservice try to write serverless services, can request scale from the cloud space. There are some disadvantages as well. If this deploy in ECS or Kubernetes instance are running on the cloud and have to pay for them even though not working with them. If a serverless function has built on it cost on only whatever usage. Behind the scenes there is a container that deploy the code and it is like on sleeping state. The serverless function either from API gateway or from irrespective AWS S3 can trigger the container to wake up. The wake-up time call as cold start which is sleep state come awake and start. The cold start time adding as a latency time, and it is a disadvantage. As a solution it can keep warm and pay for keep warm or send request per defined time. But in general, its suffering from cold start from problem. Serverless is a deployment mechanism after development a system. There is not only serverless in microservice system. Design the system as microservice and deploy as serverless.</p><p>Serverless is a serverless framework among multiple ways to implement serverless systems like CDK, SAM, and AWS native frameworks. So serverless framework is popular among those because it is easy to use. Framework take care of the deployment and other things while developers only have to write the function.</p><p>AWS node serverless project can create with the following command.</p><p>Serverless create -t aws-node-typescript -p employee-service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*KlMd5eFkHIfqohMJh4MBtQ.png" /></figure><p>Initial typescript project looks like this and there is serverless configuration file. Then should import all the packages with npm install. The file structure includes index file and function file and the libs file use to store common libraries or services.</p><p>Then a new function has created which is an endpoint.</p><p>Then this code deploys on AWS to see the framework help with the code and when deploy it create cloud formation scripts and then push in to S3 bucket to deploy.</p><h3>Reference</h3><p>[1] Krish Dinesh.” Microservices vs Serverless” Available: <a href="https://www.youtube.com/watch?v=xQtyEK5yZFQ&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=35&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=xQtyEK5yZFQ&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=35&amp;ab_channel=KrishDinesh</a> [Accessed: July 20,2022].</p><p>[2] Krish Dinesh.” Microservices to the Next level | Serverless with typescript” Available: <a href="https://www.youtube.com/watch?v=bcFdV7STCqg&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=39&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=bcFdV7STCqg&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=39&amp;ab_channel=KrishDinesh</a> [Accessed: July 20,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11c59f89d5ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous Microservices]]></title>
            <link>https://medium.com/@hansika.m99/asynchronous-microservices-e569d99ba871?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e569d99ba871</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[saga-pattern]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 07:13:03 GMT</pubDate>
            <atom:updated>2022-07-21T07:13:03.170Z</atom:updated>
            <content:encoded><![CDATA[<p>Since the HTTP protocol is not suitable for microservices backends because of the synchronous behavior, the microservices need an asynchronous method to communication. As the previous example the distributed transactions as some data added to the database and others not added to other databases. The Saga pattern will solve that problem. It is a non-microservice implementation pattern and can customize as want as long as following the repercussion.</p><p>Saga can implement in two different ways as choreographic and orchestration. choreographic means event based, and orchestration means command based. Both can use on different use cases and has own problems.</p><p>First take the choreography pattern and consider about a use case. There is a new connection service and when new connection request comes need to validate weather customer has good reputation or has tv connection. When every verification success this inform to finance service can build the bill of the customer. Then if billing is success operation service convey to start the connection. The event broker is Kafka broker and services talk with Kafka topic.</p><p>When new connection come to the service publish the message the event to topic and the verification services same time listen to the requests. Both verification success and there is a topic as verification response and response has published too there. New connection service waiting for the response meanwhile listening to verification response topic. Then new connection service identifies the verification has successes then send different event to new connection topic saying verification is success. The finance service listens to the topic and see the success take the payment and send payment success message to verification response topic. New connection gets the payment success response and again publish in the new connection topic as payment is success. The operation service listens to the new connection topic and when see payment is success it initiates new connection. It again publishes as activate success as to verification response topic. So, there is the solution to the problem and no service waiting for the response everything works fine. If the messaging system is down the microservices cannot communicate but if use MSK or any Kafka cluster and there are multiple replicants and start quickly. This system is good to have a monitoring service because if any service is down can add an alert. If a request has published and no one is waiting the monitoring service can send a notification to the services.</p><p>The orchestration model has same new connection service and there is separate command model service. When new connection request coms it tells the command service, and it goes to verify the user details as having a tv connection and legitimate user. that process can do parallelly as well. After verify success command go to finance service and say to get the payment. When it done command service go to activation service and tell to active the new connection. The process is governed by command service and the system can go with hybrid solution with an event driver. Then a new request comes to command service, and it publish to the message broker with a target service.</p><p>The disadvantage of choreography there are bunch of events and may create a deadlock situation. Its hard to solve a deadlock situation and would have to do integration testing for thousand of events. Having centralized command module is because it doesn’t change anything and decide own to do next.</p><h3>Reference</h3><p>[1] Krish Dinesh.” Lets do it right..! Real Async Microservices | SAGA Microservice Pattern | example inside” Available: <a href="https://www.youtube.com/watch?v=GfB_z4Y6YD4&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=GfB_z4Y6YD4&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;ab_channel=KrishDinesh</a> [Accessed: July 21,2022].</p><p>[2] Krish Dinesh.” Do it RIGHT..!!! Real Async MIcroservices | SAGA Microservices Architecture Patterns” Available: <a href="https://www.youtube.com/watch?v=pb0-HvDxGLI&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;index=36&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=pb0-HvDxGLI&amp;list=PLD-mYtebG3X-wOVHINZf_GKknpJs3Oa3O&amp;index=36&amp;ab_channel=KrishDinesh</a> [Accessed: July 21,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e569d99ba871" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why HTTP based Microservices is Bad]]></title>
            <link>https://medium.com/@hansika.m99/why-http-based-microservices-is-bad-6ef1b131c62d?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ef1b131c62d</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[http-request]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 18:55:50 GMT</pubDate>
            <atom:updated>2022-07-20T18:55:50.639Z</atom:updated>
            <content:encoded><![CDATA[<p>HTTP is wrong choice for microservice can explain by an example. If someone providing mobile connection to the phone wants a system with unique identification of the user. when someone come to the application a new connection is creating. In microservices there is isolate bounded context for each service. Then there is a new connection service and when user apply new connection weather like to have other features. The connection service needs to check the user has TV connection, fixed line connection, if this is a blacklisted user and check other provides have banned this user. if everything has in success user get a new connection. Meanwhile the user has attached to the billing table, connection table, account table and support table, packages table.</p><p>This system own organization has other different services use the user id and go to the new connection service parallelly checking the user details about having a TV connection or fixed line connection. If all the details verified, then store details in the tables. Then another problem has to face that the databases can be in different departments. Probably some table get successfully insert the recode, but some tables may not. If all verification service HTTP protocol has used the request can send same time. If 4G connection service is offline and another providers user verification service has become very slow then the requests come, verify other service and wait until the response comes from another providers system. If 100 of requests are coming at a time all are waiting and until that response comes after visited other verify services. This problem called as Cascade Failure. So, the entire transaction failed because cannot activate another provider service because don’t know the 4G connection result because it is offline. The UI have to wait and should have to run batch job to visit the transaction is happening or what is failed. Because of this problem the system has to have a backup process. This is a scenario that prove the HTTP is bad for microservices backend processed.</p><p>There is A service and B service sending multiple requests to the one server. A send 500 request to B and expecting for the responses. HTTP works as synchronous mode and when send requests the responses come same order. Since HTTP is synchronous when using asynchronous based system, it doesn’t work. So, it is not good to use HTTP at backends of microservices.</p><p>As a solution a message framework like Kafka can use. New connection request redirect to Kafka and all of the other verify services listen to the Kafka. They take the request from Kafka and verify it using the databases and send the response back to another topic. New connection service listening to the Kafka and collect the responses. When there is service is offline Kafka keeps the request and send when it back online. So, the response time and the order does not matter and work as asynchronous way.</p><h3>Reference</h3><p>[1] Krish Dinesh.”Why HTTP based Microservices is a BAD idea. | explained with example” Available: <a href="https://www.youtube.com/watch?v=bkpNvADPKZE&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=40&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=bkpNvADPKZE&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=40&amp;ab_channel=KrishDinesh</a> [Accessed: July 20,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ef1b131c62d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OAuth and OpenID Connect]]></title>
            <link>https://medium.com/@hansika.m99/oauth-and-openid-connect-9b417be476a7?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b417be476a7</guid>
            <category><![CDATA[openid]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[oauth]]></category>
            <category><![CDATA[open-connect]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 15:48:44 GMT</pubDate>
            <atom:updated>2022-07-19T15:48:44.244Z</atom:updated>
            <content:encoded><![CDATA[<p>OAuth2 is protocol that token based authorization. OAuth has resource owner and authorization server and then resource server. Recourse owners give the consent to authorization server client to the website to the resource server. Recourse servers verify the token with authentication server.</p><p>Access token is the token talks about user and what user can do like the user role and permission. The refresh token is exchange and get new access token when it is expires.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*WmyyEJmH-2tf7QiWxyPL4A.png" /></figure><p>Client goes to the website and request to create an account. The resource owner asks to login with social account and redirect to the authentication server. Authorization servers issue a token to the client and client send it to resource server. Resource servers send the token to the authorization server to validate the token. Then resource sever give access to the client.</p><p>There are few grant types in OAuth like authorization code, client credentials, implicit, password, and device code. Authorization code grant type is the widely use grant type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*fmEsIkoiBtaB-XPlrDSq-g.png" /></figure><p>Client sends the request to the authorization server, and it grant the request to resource owner. The resource server sends OK. Authorization servers send a code and client again send the token request. The authorization sever sends token to the client and it send the token to resource server. It validates the token against the authorization server. The JWT token depends on the architecture design. If don’t have certification and keys it can validate against authorization server. After validating can send the resources to the client. This is ideal for resource owner don’t trust the client.</p><p>When the resource owner trusts the owner and application and don’t hesitate to give the credentials it can use password grant type. When don’t trust user then authentication code grant type can use. Also, there is a reason to have token request separately instead of sending the code first and then code back to client and get the token. But actually, happen authorization server send code to client, client send it back then authorization server sends the token to client. The problem is mostly we are dealing with web applications and when go to source can see everything. If the token gets directly from the frontend, then someone can see the credentials which authorization server is register the client and give client id and secret. To obtain the code only need the client id. But obtain the token it needs client id and secret both. Backend talks with the authorization server and share the token, but frontend don’t do that because client credentials are visible. Sometime only have front end and doesn’t have backend. When there is no one to send the token request can use implicit flow which directly ask for token. Then won’t get the code and directly get the token.</p><p>OAuth is used to solve the problem to don’t need share the credentials to untrust application and access the resources. But the OAuth is not designed to hand the authentication. But Facebook and other techs used to handle the authentication from OAuth. So, this misuse turned to OpenID connect as solution. Binding oidc and OAuth2 together can use these authentication or authorization content.</p><p>A mobile app wants to connect with an application and redirect clients to the application. So mobile app has the client id and the secret of the application. The mobile app redirects the client using their client id to the application authentication server. There are four scopes which are four functionalities in the application as create, delete, update and read. Then the mobile app asking permission to read the content. When that happen the authorization server request as consent screen to the users the mobile application wants to read the content. So the client’s authorization server give a token to the mobile app as permission to read the content. Then mobile app wants to delete something in the application. But authorization server check the token and the request is denied.</p><h3>Reference</h3><p>[1] Krish Dinesh.” oAuth and OpenID connect | Most confusing topic in plain english ” Available:<a href="https://www.youtube.com/watch?v=yWuhTxRyVAA&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=31&amp;ab_channel=KrishDinesh"> </a><a href="https://www.youtube.com/watch?v=GTT-hg-F1Zo&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=32&amp;ab_channel=KrishDinesh">https://www.youtube.com/watch?v=GTT-hg-F1Zo&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=32&amp;ab_channel=KrishDinesh</a> [Accessed: July 18,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b417be476a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Enterprise Microservice Architecture with SSO]]></title>
            <link>https://medium.com/@hansika.m99/secure-enterprise-microservice-architecture-with-sso-3aa571433046?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aa571433046</guid>
            <category><![CDATA[single-sign-on]]></category>
            <category><![CDATA[open-policy-agent]]></category>
            <category><![CDATA[sso]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 10:39:17 GMT</pubDate>
            <atom:updated>2022-07-19T10:39:17.608Z</atom:updated>
            <content:encoded><![CDATA[<p>Security is an important part in every system. Usually in microservices OAuth2 is widely used. In the real-world application does not have facility to create users on the own server because the designing application might use by thousands of users. The requirement might be even though the system has implemented, wants to validate users in customers own identity management system. So, the developing system has to cooperate with the existing systems. So, this system wants to use single sign on mechanism.</p><p>That works as when sign into the system the sign in token can share in entire application. In the OAuth solution was implementing own OAuth server. In this case also that solution works but problem is needed to ensure security of that solution also. So, the alternative solutions for the problems are use keylock which is a open source project and other is AWS Cognito which is customizable and pre token generation. Then there is WSO2 IS which can use without cloud. All these solutions commonly share the OAuth2 facilities to run authentication and OpenID for authorization.</p><p>Authentication is who the person is, and authorization is what the user can do. When creating system solution for organization with several departments, the employee needs to authorize for read the employee profiles only the department he assigned to. Then the authorization has two parts as what can do and on what that can do.</p><p>Then imagine a support ticket management system and support engineer can read profile of users only they are assigning to him. That means support engineer has profile read access, but he can only read assign to him not other profiles. Implementing this scenario to give read access is easy but give access on same part is not easy with authorization server. These are called capabilities or user policies.</p><p>Usually when implementing these types of scenarios, create users and roles. There are permissions can give to the users like read, update, create, delete, and list. So, can assign these permissions to a role and assign a role to a user. without implement own authorization server it is easy to use service like Keyclock because it is a standard, open source with community support. If think the Keyclock somehow authenticate the user and the token comes to UI. The token submits with every service request. When service request comes to the API gateway and check the token carries the user permission. Then the which department can access can be defined using policy management solution like OPA. OPA is open policy agent and simple, scalable and virtually can put with anything. After user getting permission just before that the request talk to OPA and ask about user is allowed to read the profile in this department. OPA validate user roles permission and capabilities of the user. OPA says true or false and based on the policy decision user get the permission.</p><p>The authentication can achieve by multiple ways. One is identity brokering which is implements with social logins. When login with social accounts it redirects to identity provider after logging, and it gives token back to the Keyclock. Keyclock can generate its own token with user roles and JWT token back. Second method is use identity federation which is Keyclock can validate users against multiple data sources. They have custom adapters to talk data source and validate users. With all these services the system can secure solution. Ldap, Active directory, Kerberose are the services that go with similar authentication mechanisms. They can work separately for authenticate users. If the active directory implemented in the system and configure Keycloak or identity brokering to the active directory. So, when user is already logged in to active directory and keylock talk to the active directory and it tell user is already signed in. Then keylock trust and issue a token give to the user. that means user don’t need to log in second time. That means single sign on or SSO.</p><h3>Reference</h3><p>[1] Krish Dinesh.”How to Secure Enterprise Microservice architecture with SSO | Keycloak with Open Policy Agent ” Available:<a href="https://www.youtube.com/watch?v=yWuhTxRyVAA&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=31&amp;ab_channel=KrishDinesh"> https://www.youtube.com/watch?v=DZeXqbFvYNA&amp;list=PLD-mYtebG3X9HaZ1T39-aF4ghEtWy9-v3&amp;index=5&amp;ab_channel=KrishDinesh</a> [Accessed: July 18,2022].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aa571433046" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Release the Java Application after Implementation]]></title>
            <link>https://medium.com/@hansika.m99/release-the-java-application-after-implementation-bb8bb6d5abe9?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb8bb6d5abe9</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-web-start]]></category>
            <category><![CDATA[packaging]]></category>
            <category><![CDATA[executable-jar]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 06:04:53 GMT</pubDate>
            <atom:updated>2022-07-19T06:04:53.425Z</atom:updated>
            <content:encoded><![CDATA[<p>After the development the delivery phase is beginning. Java applications can deploy locally and including extendable jars can deploy local with remote called as java web. There are several deployment options. The local deployment happens in user’s computer entirely as standalone application and there might be GUI and deployed as executable JARs. The combination of half local and half remote deployment is distributed with client half running in users’ local system. The application connected to the server while two half’s of application running. The remote deployment is the entire application run on a server and client access the system from non-java system like browser.</p><p>In the java program after the compile there are code and class files. Before the deployment the class files and codes are organized to prevent the mess. With an organizational recommended schema can create a project directory and create directory called source and under that create classes directory. Then the class files assign to the classes’ directory.</p><p>cd MyProject/source</p><p>javac -d ../classes MyApp.java</p><p>the -d flag use to decide the directory of compiled code store. The JAR means the Java Archive files. It is follows the pkzip file format and allow to bundle the classes together. The executable JAR means the end user don’t have to take the class file out from the JAR before running the files. They can run whole JAR without getting files out. The manifest file goes to the JAR and take information about the files to make them executable.</p><p>Before making a JAR executable all the class files should be in classes directory. The create the manifest.txt that holds the main method to start the file. Manifest file also located in the class directory. After that can run the JAR file making tool to create a JAR. Java can load the classes from the JAR and execute the main() method. The JVM can find the JAR and can look for load a class. Depending on the operating system the JAR file could be simply double click and launch.</p><p>The class files can reuse, and two classes can have the same name. but the naming collisions and other difficulties can occur because of the same name. as a solution the packaging has available in Java. The key feature of packages is preventing name conflicts in the classes. Package is collecting a set of classes that related together. The package has fully qualified name. even though the packages prevent name conflicts in classes the package names also can conflicts. So, the package naming convention reduce the problem by reverse the domain name. domain names are guaranteed to be unique, and two domains cannot have the same name. using the domain name, the package name conflicts can be reduced.</p><p>When create packages first should choose a name as fully qualified. Then put the classes into the package and the package statement should define in the class. It always comes above the imports and there can be only one package statement in class file. It is important to have matching directory structure. Still without proper structure can compile the program but having directory name properly make easy to manage the code and classes.</p><p>When compiling and running the package include program the JVM should be able to find the classes and referenced classes. The solution is to compile with the -d flag. It let the compiler class files into a directory and put the class into correct directory structure for the package. When there is no matching directory structure, the -d flag put the classes to the right places.</p><p>Ehen creating the jar all the class files should withing the correct package structure and correct class directory.</p><p>jar -tf packEx.jar</p><p>this command lists the content inside the JAR.</p><p>cd Skyler</p><p>jar -xf packEx.jar</p><p>these commands extract the content from a JAR.</p><p>Java Web Start is application run as standalone application in the browser first time. That means a java program stay at the client machine and work as a browse plugin. The Java Web Start helper app is for manage the download and update and launch of JWS apps. JWS download the application and start the main() method. Then the end-user launches the application directory using JWS helper app. JWS can detect small changes on the server without end-user interaction and it download and integrate the change for the application. JWS apps can behave as plain old HTML or JPEG image. Also, JWS application is an executable JAR that end-user can download.</p><p>the client can click on web page link to JWS application, and the web server get the request. It sends the .jnlp file back and JWS started in the browser, it helps to read the .jnlp file and get application JAR from the server. JWS start the JAR and application calling a main() method. The .jnlp file which is Java Network Launch Protocol file is describe the application. This hels to JWS to find the JAR and the main() method to run. .jnlp file written on XML and many things can include in the file.</p><h3>Reference</h3><p>[1] Bates, Bert, and Kathy Sierra. “Head First Java Second Edition.” (2021).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb8bb6d5abe9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures]]></title>
            <link>https://medium.com/@hansika.m99/data-structures-275f2a6d9fa1?source=rss-f11cf47336c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/275f2a6d9fa1</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Hansika Samaraweera]]></dc:creator>
            <pubDate>Tue, 19 Jul 2022 04:36:53 GMT</pubDate>
            <atom:updated>2022-07-19T04:36:53.523Z</atom:updated>
            <content:encoded><![CDATA[<p>In java there is tools and collections to manipulate data for operations like sorting. The collection framework has built with data structure that do such kind of operations.</p><p>The arraylist is one of a data structure in collection framework that the elements keep in order as a list. Also, the TreeSet is keeping the elements sorted and without duplicate values. The HashMap is for store and access element as name-value pairs. The LinkedList is creating structure same as stacks or queues. The HashSet is responsible for keep the element in the collection without duplicates and can find an element quickly. Linked HashMap is similar to the HashMap and keep the element in order.</p><p>The TreeSet is keep the stings in alphabetical order automatically. But when adding element, it takes some time to place the element in the right place.</p><p>Generics are collection related code and can use in other ways. Generics means that type-safe collection. Generics revels the more errors in compile time before going to the runtime.</p><p>Generic class instances can make as following.</p><p>new ArrayList&lt;Animal&gt;()</p><p>also can declare variable of generic types.</p><p>List&lt;Animal&gt; catlist = new ArrayList&lt;Animal&gt;();</p><p>There are method declaration from generic types.</p><p>void foo(List&lt;Animal&gt; list)</p><p>x.foo(list)</p><p>there are generic class belongs to two areas as the class declaration and the method declaration.</p><p>public class ArrayList&lt;E&gt; extends AbstractList&lt;E&gt; {</p><p>public boolean add(E o)</p><p>}</p><p>The E is a generic type of representation and instead of E there can be ant type can pass. E will replace by a real type and add method expecting any type of object.</p><p>The generic methods include type parameter in method declaration. The type parameter can use for the defined class declaration in a method. The same parameter comes through the class can use for the method also. When the type parameter not defined in the class declaration still methods can use generic types.</p><p>public &lt;T extends Animal&gt; void takeThing(ArrayList&lt;T&gt; list)</p><p>public void takeThing(ArrayList&lt;Animal&gt; list)</p><p>both of these method declarations are legal. First method is declaring animal type ArrayList with other type like cat or dog. The second one includes only a list from animal type. The first version takes any type of animal ArrayList while second take a list of animal type.</p><p>Generics can implement as polymorphic type. If the method gets array of animals and other subtype the animal class has extended by the sub class. Then can call both types.</p><p>Then the HashSet is removing duplicate values from the set. How it happens is, HashSet use the object hash code to compare all other object hash sets. If there are no matching hash code the HashSet assume new object don’t have duplicate values. When implementing the HashSet it is a must to override the hashCode() method to prevent having same values. But there can be two objects with the same hash code might not equal. If HashSet found a matching object it calls the equals() method for one of object. After checking equality HashSet add() method returns a Boolean when new object added. If it is false, the value is a duplicated value.</p><p>The TreeSet object should has one of two characteristics. The elements in the list must be a type of implements comparable. The TreeSet add() method cannot sort the elements when they add. So, the set should implement the comparable interface. Second one is using the TreeSet’s overloaded constructor that takes a comparable. There is a choose to use the To() method to compare the elements and assume as element type implemented the comparable interface. Also, there are custom comparator to sort the elements in the set.</p><p>The Maps are the collection that act as property list. When give the name it gives back the associated value with the name. They can be a string or any Java object. There can be duplicate values but cannot have duplicate keys.</p><h3>Reference</h3><p>[1] Bates, Bert, and Kathy Sierra. “Head First Java Second Edition.” (2021).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=275f2a6d9fa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>