Browsed by
Category: Spring

Asynchronous methods using @Async annotation (Spring)

Asynchronous methods using @Async annotation (Spring)

Let’s imagine that you need to call a time-consuming service method from a controller and its result can be postponed. For example, it can import a huge number of records to a database and you can’t force the client to wait minutes/hours for a response. In such a case, it makes sense to make such a method asynchronous, i.e. a separate thread will be created to process the task, but the controller will immediately return to the user. Spring can easily help to configure asynchronous methods using @Async annotation.

Stateless OAuth2 Google authentication (JWT)

Stateless OAuth2 Google authentication (JWT)

Stateful authentication stores authentication sessions in some internal storage (in-memory, database, Redis, etc.) and returns a session identifier to a user.
In this tutorial, we’re going to cover stateless OAuth2 Google authentication when after a successful authentication a user receives an independent token (JWT in 99% of cases) with all required information in it. Both types of authentication have their own advantages and disadvantages. Stateless authentication is widely used for SPA applications and mobile clients.

Java Bean Validation

Java Bean Validation

Overview Data validation is a crucial process in software development. Invalid data may easily break the application. So, ideally, the input data should be validated as soon as possible and handled in a corresponding way. Since data validation is one of the most common programming logic, it makes sense to find a way to reduce code duplication. Bean Validation 2.0, defined by JSR 380, is a specification of the Java API for bean validation. It defines a way to validate…

Read More Read More

Aspect-oriented programming (AOP) with Spring Boot

Aspect-oriented programming (AOP) with Spring Boot

Overview Aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. Cross–cutting concerns are parts of a program that rely on or must affect many other parts of the system. Commonly used cross-cutting concerns are: logging transaction management performance monitoring security checks etc. AOP concepts Aspect: The concern that cuts across multiple classes or modules. Transaction and security are examples. Spring Transaction is implemented as Aspects. Join point: A point during the execution of the program at which you…

Read More Read More

Sessions in Redis (Spring Boot)

Sessions in Redis (Spring Boot)

Overview HTTP is a stateless protocol. It means that every time a new request is sent from the client to the server the state information of the previous request is lost. Sessions are used to store some state between requests. When a client successfully authenticates into a website, a new session is created. The next time the client visits a website, he will get access immediately without passing credentials again. How does this work technically? After successful authentication, the new…

Read More Read More

WebSockets Spring Boot

WebSockets Spring Boot

Overview WebSocket is a bi-directional communication protocol between a browser and a server. Let’s imagine that we need to check new incoming messages without reloading a page. One way could be sending regular AJAX requests. It’s called polling. Another way could be long polling. In this case, a server holds an AJAX request and returns a response only when new messages appear. In mentioned approaches the client asks a server and gets a response. In case of web sockets, there…

Read More Read More

Google/Facebook OAuth (Spring)

Google/Facebook OAuth (Spring)

Overview Probably all modern websites or applications nowadays provide the possibility of authenticating to a system via Google/Facebook/Twitter/etc. It’s indeed more convenient because a user doesn’t have to create yet another account and remember credentials, but can just use e.g. Google account to get access to various services. This is possible thanks to OAuth. OAuth is an open standard for access delegation, commonly used as a way for Internet users to grant websites or applications access to their information on other websites but…

Read More Read More