List of usage examples for org.springframework.security.core.session SessionInformation expireNow
public void expireNow()
From source file:com.sshdemo.common.security.core.session.EwcmsSessionRegistryImpl.java
@Override public void expiredSessionInformationByUsername(String username) { Object principal = getPrincipal(username); if (principal == null) { if (logger.isDebugEnabled()) { logger.debug("{} has't session", username); }/* w w w . j av a 2 s .c om*/ return; } List<SessionInformation> sessionInformations = getAllSessions(principal, false); for (SessionInformation sessionInformation : sessionInformations) { sessionInformation.expireNow(); } }
From source file:com.yqboots.security.web.controller.SessionController.java
@PreAuthorize(SecurityPermissions.SESSION_DELETE) @RequestMapping(params = { WebKeys.ID, WebKeys.ACTION_DELETE }, method = RequestMethod.GET) public String delete(@RequestParam final String id, final ModelMap model) { final SessionInformation sessionInformation = sessionRegistry.getSessionInformation(id); if (!sessionInformation.isExpired()) { sessionInformation.expireNow(); }// w w w.j a va 2 s .co m model.clear(); return REDIRECT_VIEW_PATH; }
From source file:com.artivisi.belajar.restful.ui.controller.HomepageController.java
@RequestMapping(value = "/homepage/kick/{sessionid}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK)/*from w ww .j a v a2 s .c o m*/ public void forceLogout(@PathVariable String sessionid) { SessionInformation info = sessionRegistry.getSessionInformation(sessionid); if (info != null) { info.expireNow(); } }
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(); }//from w ww. j a va2s .c o m } } } }
From source file:org.opentides.service.impl.UserServiceImpl.java
public void forceLogout(String username) { // let's logout all sessions of this user for (Object prince : sessionRegistry.getAllPrincipals()) { if (prince instanceof SessionUser) { SessionUser user = (SessionUser) prince; if (user.getUsername().equals(username)) { for (SessionInformation si : sessionRegistry.getAllSessions(prince, false)) { si.expireNow(); }//from www . jav a 2 s . c o m } } } }
From source file:com.rr.wabshs.ui.controller.mainController.java
/** * The '/loginfailed' request will serve up the login page displaying the login failed error message * * @param request/* w ww .ja va2 s . c om*/ * @param response * @return the error object and the login page view * @throws Exception */ @RequestMapping(value = "/loginfailed", method = RequestMethod.GET) public ModelAndView loginerror(HttpServletRequest request, HttpServletResponse response) throws Exception { List<loggedInUsers> loggedInUsers = new ArrayList<loggedInUsers>(); if (sessionRegistry.getAllPrincipals() != null) { Date rightNow = new Date(); for (Object principal : sessionRegistry.getAllPrincipals()) { loggedInUsers loggedInUser = new loggedInUsers(); UserDetails userDetails = (UserDetails) principal; for (SessionInformation information : sessionRegistry.getAllSessions(userDetails, true)) { long diff = rightNow.getTime() - information.getLastRequest().getTime(); long minuteDiff = diff / (60 * 1000) % 60; long hourDiff = diff / (60 * 60 * 1000); if (hourDiff > 0) { information.expireNow(); sessionRegistry.removeSessionInformation(information.getSessionId()); } else if (minuteDiff > 30) { information.expireNow(); sessionRegistry.removeSessionInformation(information.getSessionId()); } } } } program programDetails = programmanager.getProgramById(programId); ModelAndView mav = new ModelAndView(); mav.setViewName("/login"); mav.addObject("programName", programDetails.getProgramName()); mav.addObject("error", "true"); return mav; }
From source file:com.rr.wabshs.ui.users.userController.java
/** * The 'expireLoggedInUser.do' POST request will expired the logged in users session. * // w ww. ja va 2 s.c om * @param username The username to expire * @return * @throws Exception */ @RequestMapping(value = "/expireLoggedInUser.do", method = RequestMethod.POST) public @ResponseBody Integer expireLoggedInUser(@RequestParam String username) throws Exception { boolean userFound = false; for (Object principal : sessionRegistry.getAllPrincipals()) { UserDetails userDetails = (UserDetails) principal; if (username.equals(userDetails.getUsername())) { for (SessionInformation information : sessionRegistry.getAllSessions(userDetails, true)) { information.expireNow(); userFound = true; } } } if (userFound) { return 1; } else { return 0; } }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicConcurrentSessionControlStrategy.java
/** * Allowable sessions exceeded.//from ww w. j av a2 s . co m * * @param sessions * the sessions * @param allowableSessions * the allowable sessions * @param sameIp * the same ip * @param registry * the registry * @throws SessionAuthenticationException * the session authentication exception */ protected void allowableSessionsExceeded(java.util.List<SessionInformation> sessions, int allowableSessions, boolean sameIp, SessionRegistry registry) throws SessionAuthenticationException { // new IP handle if (!sameIp) { // deny login if exceptionIfMaximumExceeded if (exceptionIfMaximumExceeded || (sessions == null)) { throw new SessionAuthenticationException( messages.getMessage("ConcurrentSessionControllerImpl.exceededAllowed", new Object[] { Integer.valueOf(allowableSessions) }, "Maximum sessions of {0} for this principal exceeded")); } } // Determine least recently used session, and mark it for invalidation SessionInformation leastRecentlyUsed = null; for (int i = 0; i < sessions.size(); i++) { if ((leastRecentlyUsed == null) || sessions.get(i).getLastRequest().before(leastRecentlyUsed.getLastRequest())) { leastRecentlyUsed = sessions.get(i); } } if (sessions.size() > allowableSessions && !sameIp) { BasicPrincipal basicPrincipal = (BasicPrincipal) leastRecentlyUsed.getPrincipal(); for (int i = 0; i < sessions.size(); i++) { if (sessions.get(i).getPrincipal().equals(leastRecentlyUsed.getPrincipal())) { if (basicPrincipal.equalsIp((BasicPrincipal) (sessions.get(i).getPrincipal()))) { sessions.get(i).expireNow(); } } } leastRecentlyUsed.expireNow(); } else if (!sameIp) { leastRecentlyUsed.expireNow(); } else { // TODO } }
From source file:org.codenergic.theskeleton.user.impl.UserServiceImpl.java
@Override public List<SessionInformation> findUserActiveSessions(@NotNull String username) { return sessionRegistry.getAllPrincipals().stream().filter(principal -> principal instanceof User).distinct() .filter(principal -> ((User) principal).getUsername().equals(username)) .flatMap(principal -> sessionRegistry.getAllSessions(principal, true).stream()).map(session -> { SessionInformation newSession = new SessionInformation(username, session.getSessionId(), session.getLastRequest()); if (session.isExpired()) newSession.expireNow(); return newSession; }).collect(Collectors.toList()); }