Java Code Examples for javax.servlet.http.HttpSessionBindingEvent#getValue()

The following examples show how to use javax.servlet.http.HttpSessionBindingEvent#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginSessionListener.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@Override
public void attributeAdded(HttpSessionBindingEvent event) {
	String name = event.getName();

	// 登录
	if (name.equals("personInfo")) {

		PersonInfo personInfo = (PersonInfo) event.getValue();

		if (map.get(personInfo.getAccount()) != null) {

			// map 中有记录,表明该帐号在其他机器上登录过,将以前的登录失效
			HttpSession session = map.get(personInfo.getAccount());
			PersonInfo oldPersonInfo = (PersonInfo) session.getAttribute("personInfo");

			logger.debug("帐号" + oldPersonInfo.getAccount() + "在" + oldPersonInfo.getIp() + "已经登录,该登录将被迫下线。");

			session.removeAttribute("personInfo");
			session.setAttribute("msg", "您的帐号已经在其他机器上登录,您被迫下线。");
		}

		// 将session以用户名为索引,放入map中
		map.put(personInfo.getAccount(), event.getSession());
		logger.debug("帐号" + personInfo.getAccount() + "在" + personInfo.getIp() + "登录。");
	}
}
 
Example 2
Source File: LoginSessionListener.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@Override
public void attributeReplaced(HttpSessionBindingEvent event) {
	String name = event.getName();

	// 没有注销的情况下,用另一个帐号登录
	if (name.equals("personInfo")) {

		// 移除旧的的登录信息
		PersonInfo oldPersonInfo = (PersonInfo) event.getValue();
		map.remove(oldPersonInfo.getAccount());

		// 新的登录信息
		PersonInfo personInfo = (PersonInfo) event.getSession().getAttribute("personInfo");

		// 也要检查新登录的帐号是否在别的机器上登录过
		if (map.get(personInfo.getAccount()) != null) {
			// map 中有记录,表明该帐号在其他机器上登录过,将以前的登录失效
			HttpSession session = map.get(personInfo.getAccount());
			session.removeAttribute("personInfo");
			session.setAttribute("msg", "您的帐号已经在其他机器上登录,您被迫下线。");
		}
		map.put("personInfo", event.getSession());
	}
}
 
Example 3
Source File: WebSystemHttpSessionListener.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
/**
 * 清除之前已有相同帳戶登入的 sessionId 紀錄
 * 
 * @param arg0
 * @throws Exception
 */
private void cleanBeforeLoginUser(HttpSessionBindingEvent event) throws Exception {
	if (!"Y".equals(invalidateSameAccountSession)) {
		return;
	}
	String name=event.getName();
	Object value=event.getValue();
	if (Constants.SESS_ACCOUNT.equals(name)) {
		String account=((AccountObj)value).getAccount();
		List<String> sessionIdList=uSessLogHelper.findSessionIdByAccount(account);
		for (int ix=0; sessionIdList!=null && ix<sessionIdList.size(); ix++) {
			String sessId=sessionIdList.get(ix);
			HttpSession beforeUserHttpSession=sessionsMap.get(sessId);
			beforeUserHttpSession.invalidate();
			sessionsMap.remove(sessId);
			//uSessLogHelper.delete(sessId); invalidate 時 sessionDestroyed 有做刪除紀錄的功能
			log.warn("invalidate before session:"+sessId + " account:"+account);
		}
	}
}
 
Example 4
Source File: HttpFlexSession.java    From flex-blazeds with Apache License 2.0 6 votes vote down vote up
/**
 * HttpSessionAttributeListener callback; processes the addition of an attribute to an HttpSession.
 *
 * NOTE: Callback is not made against an HttpFlexSession associated with a request
 * handling thread.
 * @param event the HttpSessionBindingEvent
 */
public void attributeAdded(HttpSessionBindingEvent event)
{
    if (!event.getName().equals(SESSION_ATTRIBUTE))
    {
        // Accessing flexSession via map because it may have already been unbound from httpSession.
        Map httpSessionToFlexSessionMap = getHttpSessionToFlexSessionMap(event.getSession());
        HttpFlexSession flexSession = (HttpFlexSession)httpSessionToFlexSessionMap.get(event.getSession().getId());
        if (flexSession != null)
        {
            String name = event.getName();
            Object value = event.getValue();
            flexSession.notifyAttributeBound(name, value);
            flexSession.notifyAttributeAdded(name, value);
        }
    }
}
 
Example 5
Source File: HttpFlexSession.java    From flex-blazeds with Apache License 2.0 6 votes vote down vote up
/**
 * HttpSessionAttributeListener callback; processes the removal of an attribute from an HttpSession.
 *
 * NOTE: Callback is not made against an HttpFlexSession associated with a request
 * handling thread.
 * @param event the HttpSessionBindingEvent
 */
public void attributeRemoved(HttpSessionBindingEvent event)
{
    if (!event.getName().equals(SESSION_ATTRIBUTE))
    {
        // Accessing flexSession via map because it may have already been unbound from httpSession.
        Map httpSessionToFlexSessionMap = getHttpSessionToFlexSessionMap(event.getSession());
        HttpFlexSession flexSession = (HttpFlexSession)httpSessionToFlexSessionMap.get(event.getSession().getId());
        if (flexSession != null)
        {
            String name = event.getName();
            Object value = event.getValue();
            flexSession.notifyAttributeUnbound(name, value);
            flexSession.notifyAttributeRemoved(name, value);
        }
    }
}
 
Example 6
Source File: HttpFlexSession.java    From flex-blazeds with Apache License 2.0 6 votes vote down vote up
/**
 * HttpSessionAttributeListener callback; processes the replacement of an attribute in an HttpSession.
 *
 * NOTE: Callback is not made against an HttpFlexSession associated with a request
 * handling thread.
 * @param event the HttpSessionBindingEvent
 */
public void attributeReplaced(HttpSessionBindingEvent event)
{
    if (!event.getName().equals(SESSION_ATTRIBUTE))
    {
        // Accessing flexSession via map because it may have already been unbound from httpSession.
        Map httpSessionToFlexSessionMap = getHttpSessionToFlexSessionMap(event.getSession());
        HttpFlexSession flexSession = (HttpFlexSession)httpSessionToFlexSessionMap.get(event.getSession().getId());
        if (flexSession != null)
        {
            String name = event.getName();
            Object value = event.getValue();
            Object newValue = flexSession.getAttribute(name);
            flexSession.notifyAttributeUnbound(name, value);
            flexSession.notifyAttributeReplaced(name, value);
            flexSession.notifyAttributeBound(name, newValue);
        }
    }
}
 
Example 7
Source File: OpendapSessionAttributeListener.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void attributeRemoved(HttpSessionBindingEvent e) {

    if (e.getValue() instanceof GuardedDataset) {
      GuardedDataset gdataset = (GuardedDataset) e.getValue();
      gdataset.close();
      // System.out.printf(" close gdataset %s in session %s %n", gdataset, e.getSession().getId());
      // if (log.isDebugEnabled()) log.debug(" close gdataset " + gdataset + " in session " + e.getSession().getId());
    }
  }
 
Example 8
Source File: UserCounterListener.java    From jivejdon with Apache License 2.0 5 votes vote down vote up
public void attributeAdded(HttpSessionBindingEvent hsbe) {
	if (!"online".equals(hsbe.getName())) {
		return;
	}
	String username = (String) hsbe.getValue();
	if (username == null) {
		return;
	}
	List userList = (List) servletContext.getAttribute(OnLineUser_KEY);
	userList.add(username);
}
 
Example 9
Source File: UserCounterListener.java    From jivejdon with Apache License 2.0 5 votes vote down vote up
public void attributeRemoved(HttpSessionBindingEvent se) {
	if (!"online".equals(se.getName())) {
		return;
	}
	String username = (String) se.getValue();
	if (username == null) {
		return;
	}
	List userList = (List) servletContext.getAttribute(OnLineUser_KEY);
	userList.remove(username);

}
 
Example 10
Source File: MyHttpSessionAttributeListener.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Override
public void attributeReplaced(HttpSessionBindingEvent se) {
	HttpSession session = se.getSession();
	String name = se.getName();
	Object oldValue = se.getValue();
	logger.info("修改session属性:" + name + ", 原值:" + oldValue + ", 新值:" + session.getAttribute(name));
}
 
Example 11
Source File: LoginSessionListener.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Override
public void attributeRemoved(HttpSessionBindingEvent event) {
	String name = event.getName();

	// 注销
	if (name.equals("personInfo")) {
		// 将该session从map中移除
		PersonInfo personInfo = (PersonInfo) event.getValue();
		map.remove(personInfo.getAccount());
		logger.debug("帐号" + personInfo.getAccount() + "注销。");
	}
}
 
Example 12
Source File: MCRSessionResolver.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void valueBound(HttpSessionBindingEvent hsbe) {
    Object obj = hsbe.getValue();
    if (LOGGER.isDebugEnabled() && obj instanceof MCRSessionResolver) {
        LOGGER.debug("Bound MCRSession {} to HttpSession {}", ((MCRSessionResolver) obj).getSessionID(),
            hsbe.getSession().getId());
    }
}
 
Example 13
Source File: WebSystemHttpSessionListener.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
private void writeLoginUser(HttpSessionBindingEvent event) throws Exception {
	String sessionId=event.getSession().getId();
	String name=event.getName();
	Object value=event.getValue();
	if (Constants.SESS_ACCOUNT.equals(name)) {
		if (uSessLogHelper.count(sessionId)>0) {
			uSessLogHelper.delete(sessionId);
		}
		uSessLogHelper.insert(sessionId, ((AccountObj)value).getAccount());
	}		
}
 
Example 14
Source File: NonSerializableSessionListener.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Tests whether the attribute value is serializable and logs an error if it isn't.  Note, this can be expensive
 * so we avoid it in production environments.
 * @param se the session binding event
 * @param action the listener event for logging purposes (added or replaced)
 */
protected void checkSerialization(final HttpSessionBindingEvent se, String action) {
    final Object o = se.getValue();
    if(o != null) {
        if (!isSerializable(o)) {
            LOG.error("Attribute of class " + o.getClass().getName() + " with name " + se.getName() + " from source " + se.getSource().getClass().getName() + " was " + action + " to session and does not implement " + Serializable.class.getName());
        } else if (!canBeSerialized((Serializable) o)){
            LOG.error("Attribute of class " + o.getClass().getName() + " with name " + se.getName() + " from source " + se.getSource().getClass().getName() + " was " + action + " to session and cannot be Serialized");
        }
    }
}