View Javadoc

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.mgt.eis;
20  
21  import org.apache.shiro.session.Session;
22  
23  import java.io.Serializable;
24  
25  /**
26   * Interface allowing pluggable session ID generation strategies to be used with various {@link SessionDAO}
27   * implementations.
28   * <h2>Usage</h2>
29   * SessionIdGenerators are usually only used when ID generation is separate from creating the
30   * Session record in the EIS data store.  Some EIS data stores, such as relational databases, can generate the id
31   * at the same time the record is created, such as when using auto-generated primary keys.  In these cases, a
32   * SessionIdGenerator does not need to be configured.
33   * <p/>
34   * However, if you want to customize how session IDs are created before persisting the Session record into the data
35   * store, you can implement this interface and typically inject it into an {@link AbstractSessionDAO} instance.
36   *
37   * @see org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator JavaUuidSessionIdGenerator
38   * @see org.apache.shiro.session.mgt.eis.RandomSessionIdGenerator RandomSessionIdGenerator
39   * @since 1.0
40   */
41  public interface SessionIdGenerator {
42  
43      /**
44       * Generates a new ID to be applied to the specified {@code Session} instance.
45       *
46       * @param session the {@link Session} instance to which the ID will be applied.
47       * @return the id to assign to the specified {@link Session} instance before adding a record to the EIS data store.
48       */
49      Serializable generateId(Session session);
50  
51  }