I am working on a Spring-MVC application in which I would periodically require to get the onlineUsers to persist them in the database. I checked on net and I can use @Scheduled from Spring to achieve this task. I have written a method, but it does not seem to auto-fire. I have no error log, as the method does not autofire, but the program compiles normally. I just don't see the output in console. Any help would be nice. Thanks a lot.
Here goes my code :
@Scheduled(fixedRate = 5000)
public void listUsers(){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
List<Object> principals = sessionRegistry.getAllPrincipals();
List<Person> usersInfoList = new ArrayList<>();
for (Object principal: principals) {
if (principal instanceof Person) {
for(SessionInformation sess :sessionRegistry.getAllSessions(principal, false)){
if(!sess.isExpired()){
usersInfoList.add((Person) sess.getPrincipal());
System.out.println("Logged in users are "+((Person) sess.getPrincipal()).getUsername());
}
}
}
}
}
I have also made changes in session management in security-application-context to get non-expired sessions like this :
<security:session-management>
<security:concurrency-control session-registry-ref="sessionRegistry" max-sessions="1" expired-url="/login"/>
</security:session-management>
<bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" />
Any help would be nice. Thanks a lot... :-)
Aucun commentaire:
Enregistrer un commentaire