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.mgt; 020 021import org.apache.shiro.subject.Subject; 022 023/** 024 * A {@code SubjectDAO} is responsible for persisting a Subject instance's internal state such that the Subject instance 025 * can be recreated at a later time if necessary. 026 * <p/> 027 * Shiro's default {@code SecurityManager} implementations typically use a {@code SubjectDAO} in conjunction 028 * with a {@link SubjectFactory}: after the {@code SubjectFactory} creates a {@code Subject} instance, the 029 * {@code SubjectDAO} is used to persist that subject's state such that it can be accessed later if necessary. 030 * <h3>Usage</h3> 031 * It should be noted that this component is used by {@code SecurityManager} implementations to manage Subject 032 * state persistence. It does <em>not</em> make Subject instances accessible to the 033 * application (e.g. via {@link org.apache.shiro.SecurityUtils#getSubject() SecurityUtils.getSubject()}). 034 * 035 * @see DefaultSubjectDAO 036 * @since 1.2 037 */ 038public interface SubjectDAO { 039 040 /** 041 * Persists the specified Subject's state for later access. If there is a no existing state persisted, this 042 * persists it if possible (i.e. a create operation). If there is existing state for the specified {@code Subject}, 043 * this method updates the existing state to reflect the current state (i.e. an update operation). 044 * 045 * @param subject the Subject instance for which its state will be created or updated. 046 * @return the Subject instance to use after persistence is complete. This can be the same as the method argument 047 * if the underlying implementation does not need to make any Subject changes. 048 */ 049 Subject save(Subject subject); 050 051 /** 052 * Removes any persisted state for the specified {@code Subject} instance. This is a delete operation such that 053 * the Subject's state will not be accessible at a later time. 054 * 055 * @param subject the Subject instance for which any persistent state should be deleted. 056 */ 057 void delete(Subject subject); 058}