Posts

Mocking in Java using Mockito

Image
Before talking about Mockito Framework. Let’s see why do we need it at the first place and how it can be helpful. Last year, I was working on one project which talks to other third party services as well as with the database connection and to test the functionality of my application, third party application should be up and running. There can be a chance where all these services might not available during unit testing. As you can see, your application is completely dependent on other application and what if: Third party application is down              You cannot connect to database to test your functionality At such situation, mocking becomes a natural solution for unit testing. Using Mockito, you don’t really need a database connection. You just need a mock object that returns the expected result. Mockito: Introduction Mockito is a mocking framework, the JAVA-based library that is used for effective unit tes...

OAuth vs SSO: Which One Should I Use?

Image
Currently, I am working on one project which provided me a lot of opportunities to learn about OAuth 2.0 and SAML and better understanding on which one to choose for SSO strategy. I am choosing this topic because most of the people get confused between these two. While they have some similarities but they are very different too and to put it one line. I would say “OAuth is not Single Sign-On” What is the difference between OAuth 2.0 and SSO? OAuth (Open Authorization) is a standard for authorization of resources. It does not deal with authentication. It allows secure authorization in a simple and standard method from web, mobile and desktop applications. If you try to log into Stack Overflow using Facebook, you’ll be redirected to Facebook’s website and will see something like the following: Once authenticated with Facebook, it will ask for Stack Overflow’s permission to access your resources l ike your name, Email id, Profile picture and so on. This is an authoriz...

Set up Shibboleth SP as a SAML 2.0 service provider with G Suite

Prerequisite: Basic understanding of SAML 2.0, SSO and Shibboleth SP.   SP setup up and working on your instance. Must having administrator account to register your SP on G suite G Suite setup: Login to  https://admin.google.com  using your administrator account. Click  Security > Set up single sign-on (SSO) Click the  Download  button to download the Google IdP metadata and the X.509 Certificate Now click on  Apps > SAML apps . Select the  Add a service/App to your domain  link or click the plus (+) icon in the bottom corner. The  Enable SSO for SAML Application  window opens. Click  SET UP MY OWN CUSTOM APP We have already downloaded the certificate and Idp Metadata, click  NEXT On the Basic application information window, Enter the  Application name  and Description values. In the Service Provider Details section, enter the following URLs into the  Entity ID, ACS URL , and...

Singleton Class Vs Singleton bean scope

I have seen people getting confused between singleton scope vs singleton design pattern. Basically, there is a bit difference between these two. Singleton scope: The spring support five different scopes and it is used to decide which type of bean instance should be returning from Spring container back to the caller. One of the scope is Singleton and the by default scope too. It returns a single bean instance per Spring IoC container. <bean id=”object1” class=“com.package.classname”/> When I said, single bean instance per spring Ioc Container i.e. you will always get the same object regardless of the number of call of the same bean but if you declare another bean for the same class then you will get another object for another bean. Let’s understand this with an example: <bean id=”object1” class=“com.package.classname”/> <bean id=”object2” class=“com.package.classname” scope=”prototype”/> <bean id=”object3” class=“com.package.classname”/...

How to uinstall MySQL completely from Windows OS?

I was running some script which did some changes to my database and corrupted my root permission. Tried so many things but didn't work out. Finally, I decided to uninstall the MySQL from my instance and install a new one but again it was not an easy job as MySQL stores file at the various locations that you have to removed manually before starting from the scratch. Simple steps to uninstall MySQL: Stop MySQL services and remove services by executing below command in command prompt (Start it as Administrator) Net stop MySQL Sc delete MySQL Uninstall MySQL program from the control panel. #2 will uninstall the program but will not remove all the files from your machine which we have to do it manually.(Removing all files will remove existing database. Take the backup, if you need it in future.) C:\Program Files\MySQL C:\Program Files (x86)\MySQL C:\ProgramData\MySQL C:\Users\<USERNAME>\AppData\Roaming\MySQL Restart your instance and install it again. ...

What is JSON Web Token?

Image
1. Overview JSON Web Token or JWT ( jot ) for short is an open standard (RFC 7519) that defines a compact, URL-safe means of representing claims to be transferred between two parties.  The claims in a JWT are encoded as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure, enabling the claims to be digitally signed or integrity protected with a Message Authentication Code (MAC) and/or encrypted. 2. Structure The compacted representation of a signed JWT is a string that has three parts, each separated by a dots (.) : Eg:  eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 . eyJzdWIiOiJBYmR1bCIsImlhdCI6MTIzNDU2Nzg5MCwiZXhwIjoxMjM0NTY3ODkwLCJuYmYiOjEyMzQ1Njc4OTAsImlzcyI6Imh0dHA6Ly93YWhlZWR0ZWNoYmxvZy5pbiIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJhZG1pbiI6dHJ1ZX0 . Ats92uWxgSjQ8vFgQieK9tpBi66csIFHxkTke70FGlI Each section is Base64Encoded and the first section is called header, the second section ...

@Embeddable and @Embedded in Hibernate Annotation

Image
Before jumping to @Embeddable and @Embedded annotation. Let me explain about hibernate different objects:          Entity Object o    Entity object are those object which can stand alone like Student or Professor and has its own database identity.          Value Object o    Objects which cannot stand alone like Address as you need to map address with some Entities like Student. It will belongs to an entity, and its persistent state is embedded in the table row of the owning entity In short, always use @Embeddable for the value object and @Embedded with the entity class. Let's understand it by a simple example: We have one Address (Value object) and it is having attributes like city, state, zip code. Now we have two more different entity Student and Professor (Entity Object) . Student or Professor can have Address attributes just by embedding the Address into its Entity. The  @Embedd...