001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.shiro.session; 020 021/** 022 * Interface to be implemented by components that wish to be notified of events that occur during a 023 * {@link Session Session}'s life cycle. 024 * 025 * @since 0.9 026 */ 027public interface SessionListener { 028 029 /** 030 * Notification callback that occurs when the corresponding Session has started. 031 * 032 * @param session the session that has started. 033 */ 034 void onStart(Session session); 035 036 /** 037 * Notification callback that occurs when the corresponding Session has stopped, either programmatically via 038 * {@link Session#stop} or automatically upon a subject logging out. 039 * 040 * @param session the session that has stopped. 041 */ 042 void onStop(Session session); 043 044 /** 045 * Notification callback that occurs when the corresponding Session has expired. 046 * <p/> 047 * <b>Note</b>: this method is almost never called at the exact instant that the {@code Session} expires. Almost all 048 * session management systems, including Shiro's implementations, lazily validate sessions - either when they 049 * are accessed or during a regular validation interval. It would be too resource intensive to monitor every 050 * single session instance to know the exact instant it expires. 051 * <p/> 052 * If you need to perform time-based logic when a session expires, it is best to write it based on the 053 * session's {@link org.apache.shiro.session.Session#getLastAccessTime() lastAccessTime} and <em>not</em> the time 054 * when this method is called. 055 * 056 * @param session the session that has expired. 057 */ 058 void onExpiration(Session session); 059}