I am trying to write a controller lists the logged in users. However, every time I call getAllPrincipals() on my session registry, it returns an empty list. Here is my spring security config:
here is the controller method:Code:<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <!-- HTTP security configurations --> <http auto-config="true" use-expressions="true" create-session="always"> <session-management session-fixation-protection="newSession" /> <form-login login-processing-url="/static/j_spring_security_check" login-page="/login" authentication-failure-url="/login?login_error=t"/> <logout logout-url="/logout" invalidate-session="true"/> <!-- Configure these elements to secure URIs in your application --> <intercept-url pattern="/choices/**" access="hasRole('ROLE_ADMIN')"/> <intercept-url pattern="/admin/**" access="hasRole('ADMIN')"/> <intercept-url pattern="/member/**" access="isAuthenticated()" /> <intercept-url pattern="/resources/**" access="permitAll" /> <intercept-url pattern="/static/**" access="permitAll" /> <intercept-url pattern="/login" access="permitAll" /> <intercept-url pattern="/accessDenied" access="permitAll" /> <intercept-url pattern="/**" access="isAuthenticated()" /> </http> <!-- Configure Authentication mechanism --> <authentication-manager alias="authenticationManager"> <authentication-provider ref="itxJPAAuthenticationProviderService"/> </authentication-manager> <beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" /> </beans:beans>
I have found some stack overflow and other such sites that say I need to create a ConcurrentSessionFilter or do something with the FilterChain. Unfortunately, there are not alot of examples on what that looks like. Does anyone have any idea how to get a session registry with some actual sessions in it?Code:@RequestMapping(value = "/sessions", method = RequestMethod.GET) @ResponseBody public String listSessions() { String s="[]"; try { List<Object> list= sessionRegistry.getAllPrincipals(); for (Object o: list) { s+=o.getClass().getCanonicalName()+","; } } catch (Exception e) { LOGGER.error("Exception=", e); } return s; }


Reply With Quote
