1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.shiro.session; 20 21 /** 22 * Interface to be implemented by components that wish to be notified of events that occur during a 23 * {@link Session Session}'s life cycle. 24 * 25 * @since 0.9 26 */ 27 public interface SessionListener { 28 29 /** 30 * Notification callback that occurs when the corresponding Session has started. 31 * 32 * @param session the session that has started. 33 */ 34 void onStart(Session session); 35 36 /** 37 * Notification callback that occurs when the corresponding Session has stopped, either programmatically via 38 * {@link Session#stop} or automatically upon a subject logging out. 39 * 40 * @param session the session that has stopped. 41 */ 42 void onStop(Session session); 43 44 /** 45 * Notification callback that occurs when the corresponding Session has expired. 46 * <p/> 47 * <b>Note</b>: this method is almost never called at the exact instant that the {@code Session} expires. Almost all 48 * session management systems, including Shiro's implementations, lazily validate sessions - either when they 49 * are accessed or during a regular validation interval. It would be too resource intensive to monitor every 50 * single session instance to know the exact instant it expires. 51 * <p/> 52 * If you need to perform time-based logic when a session expires, it is best to write it based on the 53 * session's {@link org.apache.shiro.session.Session#getLastAccessTime() lastAccessTime} and <em>not</em> the time 54 * when this method is called. 55 * 56 * @param session the session that has expired. 57 */ 58 void onExpiration(Session session); 59 }