Package org.apache.shiro.authc
Class SimpleAuthenticationInfo
- java.lang.Object
-
- org.apache.shiro.authc.SimpleAuthenticationInfo
-
- All Implemented Interfaces:
Serializable,AuthenticationInfo,MergableAuthenticationInfo,SaltedAuthenticationInfo
public class SimpleAuthenticationInfo extends Object implements MergableAuthenticationInfo, SaltedAuthenticationInfo
Simple implementation of theMergableAuthenticationInfointerface that holds the principals and credentials.- Since:
- 0.9
- See Also:
AuthenticatingRealm, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ObjectcredentialsThe credentials verifying the account principals.protected org.apache.shiro.util.ByteSourcecredentialsSaltAny salt used in hashing the credentials.protected PrincipalCollectionprincipalsThe principals identifying the account associated with this AuthenticationInfo instance.
-
Constructor Summary
Constructors Constructor Description SimpleAuthenticationInfo()Default no-argument constructor.SimpleAuthenticationInfo(Object principal, Object credentials, String realmName)Constructor that takes in a single 'primary' principal of the account and its corresponding credentials, associated with the specified realm.SimpleAuthenticationInfo(Object principal, Object hashedCredentials, org.apache.shiro.util.ByteSource credentialsSalt, String realmName)Constructor that takes in a single 'primary' principal of the account, its corresponding hashed credentials, the salt used to hash the credentials, and the name of the realm to associate with the principals.SimpleAuthenticationInfo(PrincipalCollection principals, Object credentials)Constructor that takes in an account's identifying principal(s) and its corresponding credentials that verify the principals.SimpleAuthenticationInfo(PrincipalCollection principals, Object hashedCredentials, org.apache.shiro.util.ByteSource credentialsSalt)Constructor that takes in an account's identifying principal(s), hashed credentials used to verify the principals, and the salt used when hashing the credentials.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Returnstrueif the Object argument is aninstanceof SimpleAuthenticationInfoand itsprincipalsare equal to this instance's principals,falseotherwise.ObjectgetCredentials()Returns the credentials associated with the corresponding Subject.org.apache.shiro.util.ByteSourcegetCredentialsSalt()Returns the salt used to hash the credentials, ornullif no salt was used or credentials were not hashed at all.PrincipalCollectiongetPrincipals()Returns all principals associated with the corresponding Subject.inthashCode()Returns the hashcode of the internalprincipalsinstance.voidmerge(AuthenticationInfo info)Takes the specifiedinfoargument and adds its principals and credentials into this instance.voidsetCredentials(Object credentials)Sets the credentials that verify the principals/identity of the associated Realm account.voidsetCredentialsSalt(org.apache.shiro.util.ByteSource salt)Sets the salt used to hash the credentials, ornullif no salt was used or credentials were not hashed at all.voidsetPrincipals(PrincipalCollection principals)Sets the identifying principal(s) represented by this instance.StringtoString()Simple implementation that merely returnsprincipals.toString()
-
-
-
Field Detail
-
principals
protected PrincipalCollection principals
The principals identifying the account associated with this AuthenticationInfo instance.
-
credentials
protected Object credentials
The credentials verifying the account principals.
-
credentialsSalt
protected org.apache.shiro.util.ByteSource credentialsSalt
Any salt used in hashing the credentials.- Since:
- 1.1
-
-
Constructor Detail
-
SimpleAuthenticationInfo
public SimpleAuthenticationInfo()
Default no-argument constructor.
-
SimpleAuthenticationInfo
public SimpleAuthenticationInfo(Object principal, Object credentials, String realmName)
Constructor that takes in a single 'primary' principal of the account and its corresponding credentials, associated with the specified realm. This is a convenience constructor and will construct aPrincipalCollectionbased on theprincipalandrealmNameargument.- Parameters:
principal- the 'primary' principal associated with the specified realm.credentials- the credentials that verify the given principal.realmName- the realm from where the principal and credentials were acquired.
-
SimpleAuthenticationInfo
public SimpleAuthenticationInfo(Object principal, Object hashedCredentials, org.apache.shiro.util.ByteSource credentialsSalt, String realmName)
Constructor that takes in a single 'primary' principal of the account, its corresponding hashed credentials, the salt used to hash the credentials, and the name of the realm to associate with the principals. This is a convenience constructor and will construct aPrincipalCollectionbased on theprincipalandrealmNameargument.- Parameters:
principal- the 'primary' principal associated with the specified realm.hashedCredentials- the hashed credentials that verify the given principal.credentialsSalt- the salt used when hashing the given hashedCredentialsrealmName- the realm from where the principal and credentials were acquired.- Since:
- 1.1
- See Also:
HashedCredentialsMatcher
-
SimpleAuthenticationInfo
public SimpleAuthenticationInfo(PrincipalCollection principals, Object credentials)
Constructor that takes in an account's identifying principal(s) and its corresponding credentials that verify the principals.- Parameters:
principals- a Realm's account's identifying principal(s)credentials- the accounts corresponding principals that verify the principals.
-
SimpleAuthenticationInfo
public SimpleAuthenticationInfo(PrincipalCollection principals, Object hashedCredentials, org.apache.shiro.util.ByteSource credentialsSalt)
Constructor that takes in an account's identifying principal(s), hashed credentials used to verify the principals, and the salt used when hashing the credentials.- Parameters:
principals- a Realm's account's identifying principal(s)hashedCredentials- the hashed credentials that verify the principals.credentialsSalt- the salt used when hashing the hashedCredentials.- Since:
- 1.1
- See Also:
HashedCredentialsMatcher
-
-
Method Detail
-
getPrincipals
public PrincipalCollection getPrincipals()
Description copied from interface:AuthenticationInfoReturns all principals associated with the corresponding Subject. Each principal is an identifying piece of information useful to the application such as a username, or user id, a given name, etc - anything useful to the application to identify the currentSubject. The returned PrincipalCollection should not contain any credentials used to verify principals, such as passwords, private keys, etc. Those should be instead returned bygetCredentials().- Specified by:
getPrincipalsin interfaceAuthenticationInfo- Returns:
- all principals associated with the corresponding Subject.
-
setPrincipals
public void setPrincipals(PrincipalCollection principals)
Sets the identifying principal(s) represented by this instance.- Parameters:
principals- the indentifying attributes of the corresponding Realm account.
-
getCredentials
public Object getCredentials()
Description copied from interface:AuthenticationInfoReturns the credentials associated with the corresponding Subject. A credential verifies one or more of theprincipalsassociated with the Subject, such as a password or private key. Credentials are used by Shiro particularly during the authentication process to ensure that submitted credentials during a login attempt match exactly the credentials here in theAuthenticationInfoinstance.- Specified by:
getCredentialsin interfaceAuthenticationInfo- Returns:
- the credentials associated with the corresponding Subject.
-
setCredentials
public void setCredentials(Object credentials)
Sets the credentials that verify the principals/identity of the associated Realm account.- Parameters:
credentials- attribute(s) that verify the account's identity/principals, such as a password or private key.
-
getCredentialsSalt
public org.apache.shiro.util.ByteSource getCredentialsSalt()
Returns the salt used to hash the credentials, ornullif no salt was used or credentials were not hashed at all. Note that this attribute is NOT handled in themergemethod - a hash salt is only useful within a single realm (as each realm will perform it's own Credentials Matching logic), and once finished in that realm, Shiro has no further use for salts. Therefore it doesn't make sense to 'merge' salts in a multi-realm scenario.- Specified by:
getCredentialsSaltin interfaceSaltedAuthenticationInfo- Returns:
- the salt used to hash the credentials, or
nullif no salt was used or credentials were not hashed at all. - Since:
- 1.1
-
setCredentialsSalt
public void setCredentialsSalt(org.apache.shiro.util.ByteSource salt)
Sets the salt used to hash the credentials, ornullif no salt was used or credentials were not hashed at all. Note that this attribute is NOT handled in themergemethod - a hash salt is only useful within a single realm (as each realm will perform it's own Credentials Matching logic), and once finished in that realm, Shiro has no further use for salts. Therefore it doesn't make sense to 'merge' salts in a multi-realm scenario.- Parameters:
salt- the salt used to hash the credentials, ornullif no salt was used or credentials were not hashed at all.- Since:
- 1.1
-
merge
public void merge(AuthenticationInfo info)
Takes the specifiedinfoargument and adds its principals and credentials into this instance.- Specified by:
mergein interfaceMergableAuthenticationInfo- Parameters:
info- theAuthenticationInfoto add into this instance.
-
equals
public boolean equals(Object o)
Returnstrueif the Object argument is aninstanceof SimpleAuthenticationInfoand itsprincipalsare equal to this instance's principals,falseotherwise.- Overrides:
equalsin classObject- Parameters:
o- the object to compare for equality.- Returns:
trueif the Object argument is aninstanceof SimpleAuthenticationInfoand itsprincipalsare equal to this instance's principals,falseotherwise.
-
hashCode
public int hashCode()
Returns the hashcode of the internalprincipalsinstance.- Overrides:
hashCodein classObject- Returns:
- the hashcode of the internal
principalsinstance.
-
toString
public String toString()
Simple implementation that merely returnsprincipals.toString()- Overrides:
toStringin classObject- Returns:
principals.toString()
-
-