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.wiki.api.spi; 020 021import org.apache.wiki.api.core.Engine; 022import org.apache.wiki.api.core.Session; 023 024import javax.servlet.http.HttpServletRequest; 025 026 027/** 028 * SPI used to locate and provide {@link Session} instances. 029 */ 030public interface SessionSPI { 031 032 /** 033 * Removes the wiki session associated with the user's HTTP request from the cache of wiki sessions, typically as part of a logout process. 034 * 035 * @param engine the wiki engine 036 * @param request the users's HTTP request 037 */ 038 void remove( Engine engine, HttpServletRequest request ); 039 040 /** 041 * <p>Returns the Session object associated with the current HTTP request. If not found, one is created. 042 * This method is guaranteed to always return a Session, although the authentication status is unpredictable until the user 043 * attempts to log in. If the servlet request parameter is <code>null</code>, a synthetic {@link #guest(Engine)} is 044 * returned.</p> 045 * <p>When a session is created, this method attaches a WikiEventListener to the GroupManager, UserManager and AuthenticationManager, 046 * so that changes to users, groups, logins, etc. are detected automatically.</p> 047 * 048 * @param engine the engine 049 * @param request the servlet request object 050 * @return the existing (or newly created) session 051 */ 052 Session find( Engine engine, HttpServletRequest request ); 053 054 /** 055 * Creates a new "guest" session containing a single user Principal {@code org.apache.wiki.auth.WikiPrincipal#GUEST}, plus the role 056 * principals {@code Role#ALL} and {@code Role#ANONYMOUS}. This method also adds the session as a listener for GroupManager, 057 * AuthenticationManager and UserManager events. 058 * 059 * @param engine the wiki engine 060 * @return the guest wiki session 061 */ 062 Session guest( Engine engine ); 063 064}