SessionLocaleResolver langage changed but not see

SessionLocaleResolver langage changed but not see

I use spring boot 2, spring security. I create cache for User. In my user class, I have a lang field: FR, EN... That allow user to select langage ui they want.

I use spring boot 2, spring security. I create cache for User. In my user class, I have a lang field: FR, EN... That allow user to select langage ui they want.

Actually, user have possibility to change it's lang.

@EnableCaching
public class CacheConfig {

@Bean
public UserCache userCache() throws Exception {

    return new SpringCacheBasedUserCache(new ConcurrentMapCache("userCache"));

}

}

public class I18nLocaleResolver extends SessionLocaleResolver {

@Override
public Locale resolveLocale(HttpServletRequest request) {

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null && !"anonymousUser".equals(auth.getPrincipal())) {
        CustomUserDetails user = (CustomUserDetails) auth.getPrincipal();

        String lang = user.getLang();
        if (lang == null) {
            lang = LanguagesEnum.FR.getLanguage();
        }
        Locale locale = new Locale(lang);

        WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale);

        return locale;
    }

    Locale locale = (Locale) WebUtils.getSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME);
    if (locale == null) {
        locale = determineDefaultLocale(request);
    }
    WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale);

    return locale;
}

@Override
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
    WebUtils.setSessionAttribute(request, LOCALE_SESSION_ATTRIBUTE_NAME, locale);

}

}

In UserDetailsServiceImpl

@Transactional
    @Override
    public void updateLang(Integer userId, String newLanguage) {
        Optional<Users> optUserApp = repository.findById(userId);

    if (!optUserApp.isPresent()) {
        throw new UsernameNotFoundException("Username id " + userId + " not found");
    }

    Users user = optUserApp.get();

    user.setLang(newLanguage);

    repository.save(user);

    userCache.removeUserFromCache(user.getUsername());
}

Scenario

User lang is EN, so it change it for FR, we passe by updateLang method, change it's done on the db side, after debugger go to I18nLocaleResolver. At this place it's the old value who are see (EN). It's there a way to refresh that without logout user?

spring

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

Spring | Spring JDBC Tutorial | Java Spring Tutorial Spring Training

Spring | Spring JDBC Tutorial | Java Spring Tutorial Spring Training . Spring Framework Certification Training This post Spring JDBC Tutorial video will help you

Spring Live | Introduction to Spring Framework | Java Spring Tutorial | Spring Training

Spring Live , Introduction to Spring Framework, Java Spring Tutorial ,Spring Training .Spring Framework Certification Training "Introduction to Spring Framework"

Spring Boot Tutorials - Spring Boot Full Course

Spring Boot Tutorials | Full Course - What is Spring? Spring Boot is an open source Java-based framework used to create a Micro Service. Spring Boot contains a comprehensive infrastructure support for developing a micro service and enables you to develop enterprise-ready applications that you can “just run”.

Spring Boot - Spring Security + JWT Complete Tutorial With Example

Learn how to implement spring security using JWT (JSON Web Token). What is JWT? Why JWT? JSON Web Token (JWT) is a compact URL-safe means of representing claims to be transferred between two parties. Spring Boot - Spring Security + JWT Complete Tutorial With Example

Mapping a Path Query in Spring Data Neo4j

Since Spring Data does not support automatically mapping queries that contain paths, take a look at how to do this manually. In this post, we will look at how you can query a path and map the results using Spring Data Neo4j.