sessionRegistry.getAllPrincipals() is empty
<p>I trying to get all logged-in users using sessionRegistry in my Spring-MVC application, i found a lot of posts and answers on how to resolve it, but i could not fix it. I'm using configuration by annotation.</p>

<p>I'm new to spring mvc and i want to learn a best practice, so all comments about other configurations or about my code are welcome.</p>

<p>Here is my code</p>

<pre>
<code>

    @Configuration
    @ComponentScan(basePackages = {"com.uno"})
    @Import({ SecurityConfig.class })
    @EnableWebMvc
    public class AppConfig extends WebMvcConfigurerAdapter {

        @Bean
        public TilesViewResolver tilesViewResolver() {
            TilesViewResolver resolver = new TilesViewResolver();
            resolver.setViewClass(TilesView.class);
            resolver.setOrder(1);
            return resolver;
        }

        @Bean
        public TilesConfigurer tilesConfigurer() {
            TilesConfigurer tilesConfigurer = new TilesConfigurer();
            tilesConfigurer.setCompleteAutoload(true);
            tilesConfigurer.setCheckRefresh(true);
            return tilesConfigurer;
        }

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/resources/**").addResourceLocations(
                    "/resources/");
        }

        @Bean
        SessionFactory sessionFactory() {
            org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration();
            configuration.configure();

            LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(
                    dataSource());
            builder.scanPackages("com.uno.domain").addProperties(
                    configuration.getProperties());
            return builder.buildSessionFactory();
        }

        @Bean
        public DriverManagerDataSource dataSource() {

            DriverManagerDataSource ds = new DriverManagerDataSource();
            ds.setDriverClassName("com.mysql.jdbc.Driver");
            ds.setUrl("jdbc:mysql://localhost:3306/uno");
            ds.setUsername("root");
            return ds;
        }

        @Bean
        public HibernateTransactionManager transactionManager() {
            return new HibernateTransactionManager(sessionFactory());
        }

        @Bean
        UserDao userDao() {
            return new UserDaoImpl();
        }

        @Bean
        UserService userService() {
            return new UserServiceImpl();
        }

        @Bean
        RoleDao roleDao() {
            return new RoleDaoImpl();
        }

        @Bean
        RoleService roleService() {
            return new RoleServiceImpl();
        }

        @Bean
        ConnexionSucessHandler connexionSuccessHandler() {
            return new ConnexionSucessHandler();
        }

        @Bean
        PersistentTokenRepository remmeberMeTokenRepository() {
            JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl();
            db.setDataSource(dataSource());
            return db;
        }

        /* Localization section */
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(localeChangeInterceptor());
        }

        @Bean
        LocaleResolver localeResolver() {
            SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
            sessionLocaleResolver.setDefaultLocale(new Locale("en"));
            return sessionLocaleResolver;
        }

        @Bean
        LocaleChangeInterceptor localeChangeInterceptor() {
            LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
            localeChangeInterceptor.setParamName("lang");
            return localeChangeInterceptor;
        }

        @Bean
        ControllerClassNameHandlerMapping controllerClassNameHandlerMapping() {
            ControllerClassNameHandlerMapping controllerClassNameHandlerMapping = new ControllerClassNameHandlerMapping();
            Object[] interceptors = new Object[] { localeChangeInterceptor() };
            controllerClassNameHandlerMapping.setInterceptors(interceptors);
            return controllerClassNameHandlerMapping;
        }

        @Bean
        ReloadableResourceBundleMessageSource messageSource() {
            ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource = new ReloadableResourceBundleMessageSource();
            reloadableResourceBundleMessageSource.setBasename("resources/i18n/messages");
            reloadableResourceBundleMessageSource.setDefaultEncoding("UTF-8");
            return reloadableResourceBundleMessageSource;
        }
        /* Localization section */

        @Bean
        CommonsMultipartResolver filterMultipartResolver(){
            return new CommonsMultipartResolver();
        }
    }

</code>
</pre>

<pre>
<code>

    @Configuration
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {

        @Autowired
        @Qualifier("userService")
        UserService userDetailsService;

        @Autowired
        ConnexionSucessHandler connexionSucessHandler;

        @Autowired
        SessionRegistry sessionRegistry;

        @Autowired
        PersistentTokenRepository remmeberMeTokenRepository;

        @Autowired
        ConcurrentSessionControlAuthenticationStrategy concurrentSessionControlAuthenticationStrategy;

        @Autowired
        ConcurrentSessionFilter concurrentSessionFilter;

        @Autowired
        RegisterSessionAuthenticationStrategy registerSessionAuthenticationStrategy;

        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {

            http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN").antMatchers("/mailManagement/**")
                    .hasAnyRole("USER", "ADMIN").antMatchers("/user/**").hasAnyRole("USER", "ADMIN")
                    .antMatchers("/login/**").permitAll().and().formLogin().successHandler(connexionSucessHandler)
                    .loginPage("/login").failureUrl("/login?error").usernameParameter("username")
                    .passwordParameter("password").and().logout().invalidateHttpSession(true).deleteCookies("JSESSIONID")
                    .logoutUrl("/logout").logoutSuccessUrl("/login?logout").and().csrf().and().exceptionHandling()
                    .accessDeniedPage("/403").and().rememberMe().rememberMeParameter("uno-remember-me")
                    .rememberMeCookieName("uno-remember-me").tokenValiditySeconds(1296000)
    .tokenRepository(remmeberMeTokenRepository).and().sessionManagement()
                    .sessionAuthenticationStrategy(concurrentSessionControlAuthenticationStrategy).maximumSessions(-1);
        }

        @Bean
        public SessionRegistry sessionRegistry() {      
            return new SessionRegistryImpl();
        }

        @Bean
        public ConcurrentSessionFilter concurrentSessionFilter(){
            return new ConcurrentSessionFilter(sessionRegistry);
        }

        @Bean
        public ConcurrentSessionControlAuthenticationStrategy concurrentSessionControlAuthenticationStrategy(){
            return new ConcurrentSessionControlAuthenticationStrategy(sessionRegistry);
        }

        @Bean
        public RegisterSessionAuthenticationStrategy registerSessionAuthenticationStrategy(){
            return new RegisterSessionAuthenticationStrategy(sessionRegistry);
        }
    }

</code>
</pre>

<pre>
<code>

    public class SecurityInitializer extends
            AbstractSecurityWebApplicationInitializer {

        @Override
        protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {     
            insertFilters(servletContext, new MultipartFilter());
        }

        @Override
        protected boolean enableHttpSessionEventPublisher() {
            return true;
        }
    }

</code>
</pre>

<pre>
<code>

    public class MvcWebApplicationInitializer extends
            AbstractAnnotationConfigDispatcherServletInitializer {

        @Override
        protected Class[] getRootConfigClasses() {
            return new Class[] { AppConfig.class };
        }

        @Override
        protected Class[] getServletConfigClasses() {
            return null;
        }

        @Override
        protected String[] getServletMappings() {
            return new String[] {"/"};
        }

         @Override
         public void onStartup(ServletContext servletContext) throws ServletException {

             servletContext.addListener(new RequestContextListener());
             super.onStartup(servletContext);
         }
    }

</code>
</pre>

<pre>
<code>

    public class ConnexionSucessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

        @Autowired
        UserProfile userProfile;

        @Override
        public void onAuthenticationSuccess(HttpServletRequest request,
                HttpServletResponse response, Authentication auth) throws IOException,
                ServletException {

            RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

            Collection authorities = auth.getAuthorities();

            userProfile.loadUser(auth.getName());

            for(GrantedAuthority grantedAuthority : authorities){
                switch (grantedAuthority.getAuthority()) {
                case "ROLE_ADMIN":
                    redirectStrategy.sendRedirect(request, response, "/admin");
                    break;

                case "ROLE_USER":
                    redirectStrategy.sendRedirect(request, response, "/user");
                    break;
                }

            }
        }

    }

</code>
</pre>