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?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

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

Spring Boot With Spring Data JPA

Welcome to the Spring Boot with Spring Data JPA tutorial! In this tutorial, we are going to see how Spring Data JPA provides complete abstraction over the DAO layer. We don’t need to write the implementation for the DAO layer anymore; Spring Data auto-generates the implementation DAO implementations.