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.RememberMeManager;
20 
21 import hunt.shiro.Exceptions;
22 import hunt.shiro.authc.AuthenticationInfo;
23 import hunt.shiro.authc.AuthenticationToken;
24 import hunt.shiro.subject.PrincipalCollection;
25 import hunt.shiro.subject.Subject;
26 import hunt.shiro.subject.SubjectContext;
27 
28 /**
29  * A RememberMeManager is responsible for remembering a Subject's identity across that Subject's sessions with
30  * the application.
31  *
32  */
33 interface RememberMeManager {
34 
35     /**
36      * Based on the specified subject context map being used to build a Subject instance, returns any previously
37      * remembered principals for the subject for automatic identity association (aka 'Remember Me').
38      * <p/>
39      * The context map is usually populated by a {@link Subject.Builder} implementation.
40      * See the {@link SubjectFactory} class constants for Shiro's known map keys.
41      *
42      * @param subjectContext the contextual data, usually provided by a {@link Subject.Builder} implementation, that
43      *                       is being used to construct a {@link Subject} instance.
44      * @return he remembered principals or {@code null} if none could be acquired.
45      */
46     PrincipalCollection getRememberedPrincipals(SubjectContext subjectContext);
47 
48     /**
49      * Forgets any remembered identity corresponding to the subject context map being used to build a subject instance.
50      * <p/>
51      * The context map is usually populated by a {@link Subject.Builder} implementation.
52      * See the {@link SubjectFactory} class constants for Shiro's known map keys.
53      *
54      * @param subjectContext the contextual data, usually provided by a {@link Subject.Builder} implementation, that
55      *                       is being used to construct a {@link Subject} instance.
56      */
57     void forgetIdentity(SubjectContext subjectContext);
58 
59     /**
60      * Reacts to a successful authentication attempt, typically saving the principals to be retrieved ('remembered')
61      * for future system access.
62      *
63      * @param subject the subject that executed a successful authentication attempt
64      * @param token   the authentication token submitted resulting in a successful authentication attempt
65      * @param info    the authenticationInfo returned as a result of the successful authentication attempt
66      */
67     void onSuccessfulLogin(Subject subject, AuthenticationToken token, AuthenticationInfo info);
68 
69     /**
70      * Reacts to a failed authentication attempt, typically by forgetting any previously remembered principals for the
71      * Subject.
72      *
73      * @param subject the subject that executed the failed authentication attempt
74      * @param token   the authentication token submitted resulting in the failed authentication attempt
75      * @param ae      the authentication exception thrown as a result of the failed authentication attempt
76      */
77     void onFailedLogin(Subject subject, AuthenticationToken token, AuthenticationException ae);
78 
79     /**
80      * Reacts to a Subject logging out of the application, typically by forgetting any previously remembered
81      * principals for the Subject.
82      *
83      * @param subject the subject logging out.
84      */
85     void onLogout(Subject subject);
86 }