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
020package org.apache.shiro.authc;
021
022import org.apache.shiro.subject.PrincipalCollection;
023
024import java.io.Serializable;
025
026/**
027 * <code>AuthenticationInfo</code> represents a Subject's (aka user's) stored account information relevant to the
028 * authentication/log-in process only.
029 * <p/>
030 * It is important to understand the difference between this interface and the
031 * {@link AuthenticationToken AuthenticationToken} interface.  <code>AuthenticationInfo</code> implementations
032 * represent already-verified and stored account data, whereas an <code>AuthenticationToken</code> represents data
033 * submitted for any given login attempt (which may or may not successfully match the verified and stored account
034 * <code>AuthenticationInfo</code>).
035 * <p/>
036 * Because the act of authentication (log-in) is orthogonal to authorization (access control), this interface is
037 * intended to represent only the account data needed by Shiro during an authentication attempt.  Shiro also
038 * has a parallel {@link org.apache.shiro.authz.AuthorizationInfo AuthorizationInfo} interface for use during the
039 * authorization process that references access control data such as roles and permissions.
040 * <p/>
041 * But because many if not most {@link org.apache.shiro.realm.Realm Realm}s store both sets of data for a Subject, it might be
042 * convenient for a <code>Realm</code> implementation to utilize an implementation of the {@link Account Account}
043 * interface instead, which is a convenience interface that combines both <code>AuthenticationInfo</code> and
044 * <code>AuthorizationInfo</code>.  Whether you choose to implement these two interfaces separately or implement the one
045 * <code>Account</code> interface for a given <code>Realm</code> is entirely based on your application's needs or your
046 * preferences.
047 * <p/>
048 * <p><b>Pleae note:</b>  Since Shiro sometimes logs authentication operations, please ensure your AuthenticationInfo's
049 * <code>toString()</code> implementation does <em>not</em> print out account credentials (password, etc), as these might be viewable to
050 * someone reading your logs.  This is good practice anyway, and account credentials should rarely (if ever) be printed
051 * out for any reason.  If you're using Shiro's default implementations of this interface, they only ever print the
052 * account {@link #getPrincipals() principals}, so you do not need to do anything additional.</p>
053 *
054 * @see org.apache.shiro.authz.AuthorizationInfo AuthorizationInfo
055 * @see Account
056 * @since 0.9
057 */
058public interface AuthenticationInfo extends Serializable {
059
060    /**
061     * Returns all principals associated with the corresponding Subject.  Each principal is an identifying piece of
062     * information useful to the application such as a username, or user id, a given name, etc - anything useful
063     * to the application to identify the current <code>Subject</code>.
064     * <p/>
065     * The returned PrincipalCollection should <em>not</em> contain any credentials used to verify principals, such
066     * as passwords, private keys, etc.  Those should be instead returned by {@link #getCredentials() getCredentials()}.
067     *
068     * @return all principals associated with the corresponding Subject.
069     */
070    PrincipalCollection getPrincipals();
071
072    /**
073     * Returns the credentials associated with the corresponding Subject.  A credential verifies one or more of the
074     * {@link #getPrincipals() principals} associated with the Subject, such as a password or private key.  Credentials
075     * are used by Shiro particularly during the authentication process to ensure that submitted credentials
076     * during a login attempt match exactly the credentials here in the <code>AuthenticationInfo</code> instance.
077     *
078     * @return the credentials associated with the corresponding Subject.
079     */
080    Object getCredentials();
081
082}