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>Please 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.), 050 * as these might be viewable to someone reading your logs. 051 * This is good practice anyway, and account credentials should rarely (if ever) be printed 052 * out for any reason. If you're using Shiro's default implementations of this interface, they only ever print the 053 * account {@link #getPrincipals() principals}, so you do not need to do anything additional.</p> 054 * 055 * @see org.apache.shiro.authz.AuthorizationInfo AuthorizationInfo 056 * @see Account 057 * @since 0.9 058 */ 059public interface AuthenticationInfo extends Serializable { 060 061 /** 062 * Returns all principals associated with the corresponding Subject. Each principal is an identifying piece of 063 * information useful to the application such as a username, or user id, a given name, etc. - anything useful 064 * to the application to identify the current <code>Subject</code>. 065 * <p/> 066 * The returned PrincipalCollection should <em>not</em> contain any credentials used to verify principals, such 067 * as passwords, private keys, etc. Those should be instead returned by {@link #getCredentials() getCredentials()}. 068 * 069 * @return all principals associated with the corresponding Subject. 070 */ 071 PrincipalCollection getPrincipals(); 072 073 /** 074 * Returns the credentials associated with the corresponding Subject. A credential verifies one or more of the 075 * {@link #getPrincipals() principals} associated with the Subject, such as a password or private key. Credentials 076 * are used by Shiro particularly during the authentication process to ensure that submitted credentials 077 * during a login attempt match exactly the credentials here in the <code>AuthenticationInfo</code> instance. 078 * 079 * @return the credentials associated with the corresponding Subject. 080 */ 081 Object getCredentials(); 082 083}