Petre Popescu Dev Blog

0

How to invalidate a JWT

In a past article, I wrote about JWTs, how to generate one and how to use them for authorization. JSON Web Tokens, however, have one major drawback. Once it is generated and submitted to the client, it can’t be easily made invalid. This is a big problem if the JWT got leaked and it did not expire (or worse, it does NOT have an expiration date). That is why it is important to make sure that your JWT can be...

0

Handling Exceptions and Errors in Play Framework

When programming, it is important to always take into consideration exceptions. No matter how well your code is, there can always be invalid data summited by the user problems in other libraries that can trigger exceptions. Also, using this mechanism is an easy way of terminating invalid flows as soon as possible. Exceptions are normal and should be treated in all services. Even in case of an exception, we must provide a response to the user so that he knows...

3

How to make a custom message converter for Log4J2

I’ve been using Log4J for many years. It is a powerful logging library that is efficient and highly customizable. You can extend the functionality with ease and do custom actions on the message prior to it being logged. Without too much chit-chat, in this article I will be showing you how to implement a custom converter for Log4J2. What is a converter? Log4J2 has multiple components that are called when a message is logged. You have the actual logger, which...

2

Building a REST API in Play Framework

When building web applications, REST has become the most widely used approach because it is easy to use and easy to implement. In this tutorial I will be showing how to build a simple REST API in Play Framework and will cover the 4 basic functionalities: Create – POST Update – PUT Retrieve – GET Remove – DELETE We will be creating a simple API for a student’s management software where we can manipulate the students and retrieve the stored...

0

Using “pepper” to increase password storing security

In a previous article I wrote how to securely store a password in the database. The article got the attention of many fellow developers and so I decided to improve it even more by writing this article. You see, even though it is very secure to store the password as a salted hash, there is an additional layer of security that can be added in order to make things even harder to crack: pepper. The “pepper” part is not meant...

0

Using JSON Web Tokens for Authorization

A useful feature of a web application is the possibility to authorize a client to access certain features of the app. Once authentication happens, it is important to also check that a client has access to the requested feature. An easy to use method is provided by a JSON Web Token. These can be easily generated, can hold the data needed for authorization, and most importantly, are secure. Let us look at how a JWT is generated by the server...

0

Optimizing jQuery DOM manipulation

If you are working with JavaScript then most probably jQuery is a library you are using quite frequently. jQuery is useful and provides many features that are harder to achieve with basic JavaScript. Due to the fact that it usually runs on the client-side, many don’t pay too much attention to optimizing the code. That is why there are many websites that load slowly, have sluggish UIs, or seem to respond with delay. So, in this article, I will show...

0

Keep your code well organized. How I structure my web project

It is easy to get carried away and just write code. The code may even work as intended but trust me that, in 6 months time, you won’t know anymore what it does and where to find a specific functionality. Unless you have a clean and clear structure. I am not necessarily talking about the classes itself, but the way to properly organize functionalities in packages so that, when a change is needed 6 or 12 month later, you know...

6

Exposing sequential IDs is bad! Here is how to avoid it.

When working on LOGaritmical, I initially had my primary keys defined as UUIDs. I took this approach for two reasons: security and to avoid collisions even when there are many rows. My initial reasoning was that I will probably need to store each log line in a separate entry and considering that one log can have a few thousands of lines, there was a small risk of overflowing the Integer. Was my reasoning correct? Probably not. Furthermore, I stumbled upon...

2

Designing and Coding Event Management in Java

A few years ago, back when ActionScript 3 was still used, but barely, I wanted to try game development in Java. All major game engines use other programming languages like C#, C++ or Lua, so it was a real pain to get started. That is when I discovered LibGDX, a graphics library for Java. The downside is that LibGDX is not very friendly for beginners and for someone that used to do game dev in ActionScript 3, it was a...