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     */
019    package org.apache.shiro.session.mgt.eis;
020    
021    import org.apache.shiro.session.Session;
022    
023    import java.io.Serializable;
024    
025    /**
026     * Interface allowing pluggable session ID generation strategies to be used with various {@link SessionDAO}
027     * implementations.
028     * <h2>Usage</h2>
029     * SessionIdGenerators are usually only used when ID generation is separate from creating the
030     * Session record in the EIS data store.  Some EIS data stores, such as relational databases, can generate the id
031     * at the same time the record is created, such as when using auto-generated primary keys.  In these cases, a
032     * SessionIdGenerator does not need to be configured.
033     * <p/>
034     * However, if you want to customize how session IDs are created before persisting the Session record into the data
035     * store, you can implement this interface and typically inject it into an {@link AbstractSessionDAO} instance.
036     *
037     * @see org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator JavaUuidSessionIdGenerator
038     * @see org.apache.shiro.session.mgt.eis.RandomSessionIdGenerator RandomSessionIdGenerator
039     * @since 1.0
040     */
041    public interface SessionIdGenerator {
042    
043        /**
044         * Generates a new ID to be applied to the specified {@code Session} instance.
045         *
046         * @param session the {@link Session} instance to which the ID will be applied.
047         * @return the id to assign to the specified {@link Session} instance before adding a record to the EIS data store.
048         */
049        Serializable generateId(Session session);
050    
051    }