use of org.springframework.security.core.session.SessionInformation in project theskeleton by codenergic.
the class ProfileRestController method findProfileActiveSessions.
@GetMapping("/sessions")
public List<SessionInformation> findProfileActiveSessions(Authentication authentication) {
if (authentication == null || authentication.getPrincipal() == null)
return Collections.emptyList();
List<SessionInformation> sessions = new ArrayList<>();
for (Object principal : sessionRegistry.getAllPrincipals()) {
UserEntity user = (UserEntity) principal;
if (!user.getUsername().equals(authentication.getName()))
continue;
sessions.addAll(sessionRegistry.getAllSessions(user, true));
}
return sessions.stream().map(i -> new SessionInformation(authentication.getName(), i.getSessionId(), i.getLastRequest())).collect(Collectors.toList());
}
use of org.springframework.security.core.session.SessionInformation in project ma-modules-public by infiniteautomation.
the class ServerRestV2Controller method listSessions.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "List session information for all sessions", notes = "Admin only")
@RequestMapping(method = RequestMethod.GET, value = "/http-sessions")
public ResponseEntity<List<SessionInformation>> listSessions(@AuthenticationPrincipal User user, HttpServletRequest request, HttpServletResponse response) throws IOException {
List<SessionInformation> sessions = new ArrayList<SessionInformation>();
final List<Object> allPrincipals = MangoSecurityConfiguration.sessionRegistry().getAllPrincipals();
for (final Object principal : allPrincipals) {
List<SessionInformation> sessionInfo = MangoSecurityConfiguration.sessionRegistry().getAllSessions(principal, true);
// Expire sessions, the user was deleted
for (SessionInformation info : sessionInfo) {
sessions.add(info);
}
}
return new ResponseEntity<>(sessions, HttpStatus.OK);
}
use of org.springframework.security.core.session.SessionInformation in project ma-modules-public by infiniteautomation.
the class ServerRestController method listSessions.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "List session information for all sessions", notes = "Admin only")
@RequestMapping(method = RequestMethod.GET, value = "/http-sessions", produces = { "application/json" })
public ResponseEntity<List<SessionInformation>> listSessions(@AuthenticationPrincipal User user, HttpServletRequest request, HttpServletResponse response) throws IOException {
List<SessionInformation> sessions = new ArrayList<SessionInformation>();
final List<Object> allPrincipals = MangoSecurityConfiguration.sessionRegistry().getAllPrincipals();
for (final Object principal : allPrincipals) {
List<SessionInformation> sessionInfo = MangoSecurityConfiguration.sessionRegistry().getAllSessions(principal, true);
// Expire sessions, the user was deleted
for (SessionInformation info : sessionInfo) {
sessions.add(info);
}
}
return new ResponseEntity<>(sessions, HttpStatus.OK);
}
use of org.springframework.security.core.session.SessionInformation in project spring-session by spring-projects.
the class SpringSessionBackedSessionRegistryTest method sessionInformationForExpiredSession.
@Test
public void sessionInformationForExpiredSession() {
Session session = createSession(SESSION_ID, USER_NAME, NOW);
session.setAttribute(SpringSessionBackedSessionInformation.EXPIRED_ATTR, Boolean.TRUE);
when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session);
SessionInformation sessionInfo = this.sessionRegistry.getSessionInformation(SESSION_ID);
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
assertThat(sessionInfo.getLastRequest().toInstant()).isEqualTo(NOW);
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
assertThat(sessionInfo.isExpired()).isTrue();
}
use of org.springframework.security.core.session.SessionInformation in project spring-session by spring-projects.
the class SpringSessionBackedSessionRegistryTest method sessionInformationForExistingSession.
@Test
public void sessionInformationForExistingSession() {
Session session = createSession(SESSION_ID, USER_NAME, NOW);
when(this.sessionRepository.findById(SESSION_ID)).thenReturn(session);
SessionInformation sessionInfo = this.sessionRegistry.getSessionInformation(SESSION_ID);
assertThat(sessionInfo.getSessionId()).isEqualTo(SESSION_ID);
assertThat(sessionInfo.getLastRequest().toInstant()).isEqualTo(NOW);
assertThat(sessionInfo.getPrincipal()).isEqualTo(USER_NAME);
assertThat(sessionInfo.isExpired()).isFalse();
}
Aggregations