本文整理汇总了Java中org.springframework.security.core.session.SessionInformation.expireNow方法的典型用法代码示例。如果您正苦于以下问题:Java SessionInformation.expireNow方法的具体用法?Java SessionInformation.expireNow怎么用?Java SessionInformation.expireNow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.core.session.SessionInformation
的用法示例。
在下文中一共展示了SessionInformation.expireNow方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allowableSessionsExceeded
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@Override
protected void allowableSessionsExceeded(List<SessionInformation> sessions, int allowableSessions,
SessionRegistry registry) throws SessionAuthenticationException {
SessionInformation leastRecentlyUsed = null;
for (SessionInformation session : sessions) {
if ((leastRecentlyUsed == null)
|| session.getLastRequest().before(leastRecentlyUsed.getLastRequest())) {
leastRecentlyUsed = session;
}
}
if(leastRecentlyUsed instanceof SessionInformationObject){
SessionInformationObject sessionObject=(SessionInformationObject)leastRecentlyUsed;
sessionObject.setKickAway(true);
}
leastRecentlyUsed.expireNow();
}
示例2: kickUser
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void kickUser(String ssoId){
final List<Object> allPrincipals = sessionRegistry.getAllPrincipals();
for (final Object principal : allPrincipals) {
if (principal instanceof UserDetails && ((UserDetails) principal).getUsername().equals(ssoId)) {
List<SessionInformation> activeUserSessions =
sessionRegistry.getAllSessions(principal, false);
if (!activeUserSessions.isEmpty()) {
for(SessionInformation i : activeUserSessions){
i.expireNow();
}
}
}
}
}
示例3: expireSession
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@RequestMapping(value = "/expire.xhtml", method = RequestMethod.GET)
public String expireSession(Model model, @RequestParam("session") String sessionid, RedirectAttributes redirectAttributes) {
boolean expire = true;
Object[] principals = cojSessionRegistryImpl.getAllPrincipals().toArray();
for (int i = 0; i < principals.length && expire; i++) {
Object[] sessions = cojSessionRegistryImpl.getAllSessions(principals[i], true).toArray();
for (int j = 0; j < sessions.length && expire; j++) {
SessionInformation s = (SessionInformation) sessions[j];
if (sessionid.equals(s.getSessionId())) {
s.expireNow();
s.refreshLastRequest();
expire = false;
cojSessionRegistryImpl.removeSessionInformation(sessionid);
}
}
}
redirectAttributes.addFlashAttribute("message", Notification.getSuccesfullDelete());
return "redirect:/admin/sessions.xhtml";
}
示例4: expireNow
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@Test
public void expireNow() {
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.isExpired()).isFalse();
sessionInfo.expireNow();
assertThat(sessionInfo.isExpired()).isTrue();
ArgumentCaptor<Session> captor = ArgumentCaptor.forClass(Session.class);
verify(this.sessionRepository).save(captor.capture());
assertThat(captor.getValue().<Boolean>getAttribute(
SpringSessionBackedSessionInformation.EXPIRED_ATTR))
.isEqualTo(Boolean.TRUE);
}
示例5: removeSession
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@DeleteMapping(value="/user/sessions/{sessionId}")
public String removeSession(@PathVariable String sessionId, RedirectAttributes redirectAttrs) {
SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId);
if(sessionInformation != null) {
sessionInformation.expireNow();
}
redirectAttrs.addFlashAttribute("message", "Session was removed");
return "redirect:/user/sessions/";
}
示例6: removeSession
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
@RequestMapping(value="/user/sessions/{sessionId}", method = RequestMethod.DELETE)
public String removeSession(@PathVariable String sessionId, RedirectAttributes redirectAttrs) {
SessionInformation sessionInformation = sessionRegistry.getSessionInformation(sessionId);
if(sessionInformation != null) {
sessionInformation.expireNow();
}
redirectAttrs.addFlashAttribute("message", "Session was removed");
return "redirect:/user/sessions/";
}
示例7: allowableSessionsExceeded
import org.springframework.security.core.session.SessionInformation; //导入方法依赖的package包/类
/**
* Allowable sessions exceeded.
*
* @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
}
}