当前位置: 首页>>代码示例>>Java>>正文


Java SessionInformation.expireNow方法代码示例

本文整理汇总了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();
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:17,代码来源:ConcurrentSessionControlStrategyImpl.java

示例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();
                }
            }
        }
    }

}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:18,代码来源:UserServiceImpl.java

示例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";
}
 
开发者ID:dovier,项目名称:coj-web,代码行数:20,代码来源:GeneralConfigController.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:19,代码来源:SpringSessionBackedSessionRegistryTest.java

示例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/";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:10,代码来源:UserSessionController.java

示例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/";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:10,代码来源:UserSessionController.java

示例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
	}

}
 
开发者ID:rockagen,项目名称:gnext,代码行数:56,代码来源:BasicConcurrentSessionControlStrategy.java


注:本文中的org.springframework.security.core.session.SessionInformation.expireNow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。