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 */
019 package org.apache.shiro.mgt;
020
021 import org.apache.shiro.authc.AuthenticationException;
022 import org.apache.shiro.authc.AuthenticationInfo;
023 import org.apache.shiro.authc.AuthenticationToken;
024 import org.apache.shiro.subject.PrincipalCollection;
025 import org.apache.shiro.subject.Subject;
026 import org.apache.shiro.subject.SubjectContext;
027
028 /**
029 * A RememberMeManager is responsible for remembering a Subject's identity across that Subject's sessions with
030 * the application.
031 *
032 * @author Les Hazlewood
033 * @since 0.9
034 */
035 public interface RememberMeManager {
036
037 /**
038 * Based on the specified subject context map being used to build a Subject instance, returns any previously
039 * remembered principals for the subject for automatic identity association (aka 'Remember Me').
040 * <p/>
041 * The context map is usually populated by a {@link Subject.Builder} implementation.
042 * See the {@link SubjectFactory} class constants for Shiro's known map keys.
043 *
044 * @param subjectContext the contextual data, usually provided by a {@link Subject.Builder} implementation, that
045 * is being used to construct a {@link Subject} instance.
046 * @return he remembered principals or {@code null} if none could be acquired.
047 * @since 1.0
048 */
049 PrincipalCollection getRememberedPrincipals(SubjectContext subjectContext);
050
051 /**
052 * Forgets any remembered identity corresponding to the subject context map being used to build a subject instance.
053 * <p/>
054 * The context map is usually populated by a {@link Subject.Builder} implementation.
055 * See the {@link SubjectFactory} class constants for Shiro's known map keys.
056 *
057 * @param subjectContext the contextual data, usually provided by a {@link Subject.Builder} implementation, that
058 * is being used to construct a {@link Subject} instance.
059 * @since 1.0
060 */
061 void forgetIdentity(SubjectContext subjectContext);
062
063 /**
064 * Reacts to a successful authentication attempt, typically saving the principals to be retrieved ('remembered')
065 * for future system access.
066 *
067 * @param subject the subject that executed a successful authentication attempt
068 * @param token the authentication token submitted resulting in a successful authentication attempt
069 * @param info the authenticationInfo returned as a result of the successful authentication attempt
070 * @since 1.0
071 */
072 void onSuccessfulLogin(Subject subject, AuthenticationToken token, AuthenticationInfo info);
073
074 /**
075 * Reacts to a failed authentication attempt, typically by forgetting any previously remembered principals for the
076 * Subject.
077 *
078 * @param subject the subject that executed the failed authentication attempt
079 * @param token the authentication token submitted resulting in the failed authentication attempt
080 * @param ae the authentication exception thrown as a result of the failed authentication attempt
081 * @since 1.0
082 */
083 void onFailedLogin(Subject subject, AuthenticationToken token, AuthenticationException ae);
084
085 /**
086 * Reacts to a Subject logging out of the application, typically by forgetting any previously remembered
087 * principals for the Subject.
088 *
089 * @param subject the subject logging out.
090 * @since 1.0
091 */
092 void onLogout(Subject subject);
093 }