How to handle user information after login succeed in Spring Security

How to handle user information after login succeed in Spring Security

I want to use user-information after login succeed. I thought about storing it into session attribute. or using @scope('session) annotation. but I haven't found the best way of doing it. so I just stored it into model-attribute.

I want to use user-information after login succeed. I thought about storing it into session attribute. or using @scope('session) annotation. but I haven't found the best way of doing it. so I just stored it into model-attribute.

@Controller
@RequestMapping(value = "/user")
public class UserController {

@Autowired
private UserService userService;

@Autowired
private UserProfileService userProfileService;

@ModelAttribute("user") 
public User getUserModel () {

    return userService.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName());
}

@ModelAttribute("userProfile")
public UserProfile getUserProfile() {

    return userProfileService.findByUser(userService.findByEmail(SecurityContextHolder.getContext().getAuthentication().getName()));
}

@GetMapping("/")
public String userIndex() { 

    logger.info("UserIndex");
    return "userPage";
}

As you can see, SecurityContextHolder.getContext().getAuthentication().getName() --> this method repeated. every time user make HTTP request, is this good practice? or any better way of store user-infomation in application?

java spring security

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Install OpenJDK 11 on CentOS 8

What is OpenJDK? OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE).

How to Keep Your Java Applications Secure - DZone Security

The solution to keeping your Java applications secure is simple: make sure they stay up to date. Check out the details within.

Json Web Token: How to Secure a Spring Boot REST API - DZone Security

In this post, I show how to secure Spring Boot REST API using Json Web Tokens for authorization. We will also use Spring Security in this tutorial.

Spring Security Tutorial For Beginners | Spring Security Basics

This Edureka video on Spring Security will help you understand the different security concepts implemented in the Spring framework with examples.

Spring Beans in Java

Spring IoC container is the core of the Spring Framework.In spring-based applications, objects live inside a spring containerThe container instan.