Example usage for org.springframework.security.core.session SessionRegistry getAllSessions

List of usage examples for org.springframework.security.core.session SessionRegistry getAllSessions

Introduction

In this page you can find the example usage for org.springframework.security.core.session SessionRegistry getAllSessions.

Prototype

List<SessionInformation> getAllSessions(Object principal, boolean includeExpiredSessions);

Source Link

Document

Obtains all the known sessions for the specified principal.

Usage

From source file:org.schedoscope.metascope.service.MetascopeUserService.java

public void logoutUser(SessionRegistry sessionRegistry, String username) {
    final List<Object> allPrincipals = sessionRegistry.getAllPrincipals();
    for (final Object principal : allPrincipals) {
        if (principal instanceof User) {
            User springUserDetails = (User) principal;
            if (springUserDetails.getUsername().equals(username)) {
                for (SessionInformation sessionInformation : sessionRegistry.getAllSessions(principal, true)) {
                    sessionInformation.expireNow();
                }/* w ww . ja  v a 2s  . c  o  m*/
            }
        }
    }
}