In this post under JJWT, I will show with example how to parse unsigned JWT containing plaintext as payload instead of serialized Claims object. As shown in previous post under JJWT, whenever we need to parse a JWT string. We need to create an instance of “JwtParser” as shown below JwtParserBuilder jwtParserBuilder = Jwts.parser(); jwtParserBuilder.unsecured();…… Continue reading Parsing simple unsigned JWT containing plaintext as payload
Creating a simple unsecured JSON Web Token containing payload
In this post under JJWT, I will show with example how to generate unsecured JWT containing payload. In previous post under JJWT, I talked about JWT containing claims. So what is the difference between claims and payload. Its simple, payload is noting but any String data, whereas claims is a map. Now with the difference…… Continue reading Creating a simple unsecured JSON Web Token containing payload
Creating and Parsing a secret key signed JWT containing claims
In this post under JWT, I will show with example how to create and parse a signed JWT containing claims. As mentioned in previous posts we will use an instance of “JwtBuilder” to construct a JSON Web Token. Below is the code snippet for your recap Snippet 1 1 JwtBuilder jwtBuilder = Jwts.builder();2 3 jwtBuilder.header().add(“alg”,…… Continue reading Creating and Parsing a secret key signed JWT containing claims
AssertDoesNotThrow Example
In this post under JUnit, I will explain with example what is the purpose and how to use “AssertDoesNotThrow” assertion method. AssertDoesNotThrow takes an executable code and assert that the method doesn’t throw any exception during execution. Below is the javadoc of “assertDoesNotThrow” exception public static void assertDoesNotThrow(Executable executable) Where “Executable” is a functional interface…… Continue reading AssertDoesNotThrow Example
Checking whether JWT is secured or not
In this post under JJWT I will show with example how to check whether a JWT is secured or not. JwtParser class has a “isSigned” method which will figure out whether the JWT is secured or not. All we need is to pass the test JWT string as an argument to this method. This method…… Continue reading Checking whether JWT is secured or not
Assumptions in JUnit5
In this post under Junit5, I will show with example, how to use Assumptions feature. Sometimes test case assertions depend on certain conditions. If a condition is met, then test case should be asserted otherwise we should skip the assertion. To test whether the condition is met or not, we take the help of “assumeTrue”…… Continue reading Assumptions in JUnit5
Parsing simple unsecured JWT containing claims
In this post under JJWT, I will show with example how to parse a simple unsecured JSON Web Token containing claims as payload. Below is the complete main code for your reference Main class 1 package defaultPackage;2 import io.jsonwebtoken.Claims;3 import io.jsonwebtoken.Header;4 import io.jsonwebtoken.Jwt;5 import io.jsonwebtoken.JwtParser;6 import io.jsonwebtoken.JwtParserBuilder;7 import io.jsonwebtoken.Jwts;8 9 public class Example2 {10 public…… Continue reading Parsing simple unsecured JWT containing claims
Creating a simple unsecured JSON Web Token containing claims
In this post under JJWT, I will explain how to create a simple unsecured JSON Web Token whose payload is a set of claims. I will be using JJWT framework for this example and for all the upcoming examples under JJWT. Below is the complete code for your reference Main class 1 package defaultPackage;2 3…… Continue reading Creating a simple unsecured JSON Web Token containing claims
Disabling the tests
In this post under Junit 5, I will show how to disable a test method or all test methods of a class. Junit 5 added a new annotation named “Disabled” to disable a test method or all the test methods of a class. When applied at a particular method, that particular method is disabled. When…… Continue reading Disabling the tests
assertTrue and assertFalse with Supplier Interface
In this post under JUnit 5, I will introduce you to a new overloaded version of “assertTrue” and “assertFalse” methods. In the earlier versions, we used to stored the result of a comparison in local variable of type boolean and when calling assertTrue or assertFalse, we used to pass that local variable as an argument…… Continue reading assertTrue and assertFalse with Supplier Interface