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 module hunt.shiro.mgt.SubjectDAO; 20 21 import hunt.shiro.subject.Subject; 22 23 /** 24 * A {@code SubjectDAO} is responsible for persisting a Subject instance's internal state such that the Subject instance 25 * can be recreated at a later time if necessary. 26 * <p/> 27 * Shiro's default {@code SecurityManager} implementations typically use a {@code SubjectDAO} in conjunction 28 * with a {@link SubjectFactory}: after the {@code SubjectFactory} creates a {@code Subject} instance, the 29 * {@code SubjectDAO} is used to persist that subject's state such that it can be accessed later if necessary. 30 * <h3>Usage</h3> 31 * It should be noted that this component is used by {@code SecurityManager} implementations to manage Subject 32 * state persistence. It does <em>not</em> make Subject instances accessible to the 33 * application (e.g. via {@link hunt.shiro.SecurityUtils#getSubject() SecurityUtils.getSubject()}). 34 * 35 * @see DefaultSubjectDAO 36 */ 37 interface SubjectDAO { 38 39 /** 40 * Persists the specified Subject's state for later access. If there is a no existing state persisted, this 41 * persists it if possible (i.e. a create operation). If there is existing state for the specified {@code Subject}, 42 * this method updates the existing state to reflect the current state (i.e. an update operation). 43 * 44 * @param subject the Subject instance for which its state will be created or updated. 45 * @return the Subject instance to use after persistence is complete. This can be the same as the method argument 46 * if the underlying implementation does not need to make any Subject changes. 47 */ 48 Subject save(Subject subject); 49 50 /** 51 * Removes any persisted state for the specified {@code Subject} instance. This is a remove operation such that 52 * the Subject's state will not be accessible at a later time. 53 * 54 * @param subject the Subject instance for which any persistent state should be deleted. 55 */ 56 void remove(Subject subject); 57 }