Search in sources :

Example 6 with ClientDetails

use of io.jmix.core.security.ClientDetails in project jmix by jmix-framework.

the class LastSecurityFilter method parseRequestLocale.

/**
 * Method parses the request locale and sets it to the authentication
 */
protected void parseRequestLocale(ServletRequest request) {
    Locale locale = localeProvider.getLocale((HttpServletRequest) request);
    if (locale != null) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication instanceof OAuth2Authentication) {
            Authentication userAuthentication = ((OAuth2Authentication) authentication).getUserAuthentication();
            if (userAuthentication.getDetails() instanceof ClientDetails && userAuthentication instanceof AbstractAuthenticationToken) {
                ClientDetails clientDetails = (ClientDetails) userAuthentication.getDetails();
                ((AbstractAuthenticationToken) userAuthentication).setDetails(ClientDetails.builder().of(clientDetails).locale(locale).build());
            }
        }
    }
}
Also used : Locale(java.util.Locale) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) ClientDetails(io.jmix.core.security.ClientDetails) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication)

Aggregations

ClientDetails (io.jmix.core.security.ClientDetails)6 Authentication (org.springframework.security.core.Authentication)3 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)3 Locale (java.util.Locale)2 AbstractAuthenticationToken (org.springframework.security.authentication.AbstractAuthenticationToken)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 VaadinServletRequest (com.vaadin.server.VaadinServletRequest)1 SystemAuthenticationToken (io.jmix.core.security.SystemAuthenticationToken)1 UserRepository (io.jmix.core.security.UserRepository)1 RestAPIException (io.jmix.rest.exception.RestAPIException)1 AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)1 RememberMeAuthenticationToken (org.springframework.security.authentication.RememberMeAuthenticationToken)1 UserDetails (org.springframework.security.core.userdetails.UserDetails)1