package com.ots.framework.shiro.web.filter.sync; import com.ots.common.constant.ShiroConstants; import com.ots.framework.shiro.session.OnlineSessionDAO; import com.ots.project.monitor.online.domain.OnlineSession; import org.apache.shiro.web.filter.PathMatchingFilter; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class SyncOnlineSessionFilter extends PathMatchingFilter { @Autowired private OnlineSessionDAO onlineSessionDAO; @Override protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception { OnlineSession session = (OnlineSession) request.getAttribute(ShiroConstants.ONLINE_SESSION); if (session != null && session.getUserId() != null && session.getStopTimestamp() == null) { onlineSessionDAO.syncToDb(session); } return true; } }