Spring Boot with Docker

In this project there is a simple rest backend which will be running inside docker container. We’ll have multiple instances of this application and we’ll be using HAProxy for load balancing for the backend apps. The network diagram is as follows The project source code can be found at this github link. The backend app […]

Injecting custom object to controller in Spring Boot

In Spring, you can inject your custom object to the controller methods like this Here are the steps of this implementation. In my sample project I have ClientRequest object which contains incoming request related variables. These variables are basically taken from the HttpServletRequest object. So we could inject HttpServletRequest instead of ClientRequest and would generate […]

Returning user requested variables with Spring

When implementing a REST API, you may want to provide flexibility for users about filtering the content based on their requests. when requesting GET /movies/1 and when user sets fields, GET /movies/1?fields=year,subject,director the result would be Implementation of this behavior is very similar to my previous tutorial about Role Based Content in Spring. I’m using […]

Returning role based content in Spring Rest Controller

When implementing a rest backend, you may be looking for a way to hide the variables of an entity based on the logged in user’s role. Here’s a sample entity. Movie It has id, year, length, title, subject, actor, actress, director variables. And in my application, I have two user roles which are admin and […]

Getting current Authenticated User in Spring Rest controller

When you need to get the active logged in user in your controller, the most common way would be injecting Principal to your controller methods. But when you need this to be done in multiple methods, you may be looking for a cleaner approach like injecting the exact User instead of Principal object. To inject […]