Class SimpleAccount
java.lang.Object
org.apache.shiro.authc.SimpleAccount
- All Implemented Interfaces:
Serializable,Account,AuthenticationInfo,MergableAuthenticationInfo,SaltedAuthenticationInfo,AuthorizationInfo
public class SimpleAccount
extends Object
implements Account, MergableAuthenticationInfo, SaltedAuthenticationInfo, Serializable
Simple implementation of the
Account interface that
contains principal and credential and authorization information (roles and permissions) as instance variables and
exposes them via getters and setters using standard JavaBean notation.- Since:
- 0.1
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefault no-argument constructor.SimpleAccount(Object principal, Object credentials, String realmName) Constructs a SimpleAccount instance for the specified realm with the given principals and credentials.SimpleAccount(Object principal, Object credentials, String realmName, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance for the specified realm with the given principal and credentials, with the the assigned roles and permissions.SimpleAccount(Object principal, Object hashedCredentials, org.apache.shiro.lang.util.ByteSource credentialsSalt, String realmName) Constructs a SimpleAccount instance for the specified realm with the given principals, hashedCredentials and credentials salt used when hashing the credentials.SimpleAccount(Collection principals, Object credentials, String realmName) Constructs a SimpleAccount instance for the specified realm with the given principals and credentials.SimpleAccount(Collection principals, Object credentials, String realmName, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance for the specified realm with the given principals and credentials, with the the assigned roles and permissions.SimpleAccount(PrincipalCollection principals, Object credentials) Constructs a SimpleAccount instance for the specified principals and credentials.SimpleAccount(PrincipalCollection principals, Object credentials, Set<String> roles) Constructs a SimpleAccount instance for the specified principals and credentials, with the assigned roles.SimpleAccount(PrincipalCollection principals, Object credentials, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance from the given principals and credentials, with the the assigned roles and permissions.SimpleAccount(PrincipalCollection principals, Object hashedCredentials, org.apache.shiro.lang.util.ByteSource credentialsSalt) Constructs a SimpleAccount instance for the specified principals and credentials. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObjectPermission(Permission permission) Assigns an object-based permission directly to this Account (not any of its realms).voidaddObjectPermissions(Collection<Permission> permissions) Assigns one or more object-based permissions directly to this Account (not any of its realms).voidAdds a role to this Account's set of assigned roles.voidaddRole(Collection<String> roles) Adds one or more roles to this Account's set of assigned roles.voidaddStringPermission(String permission) Assigns a String-based permission directly to this Account (not to any of its realms).voidaddStringPermissions(Collection<String> permissions) Assigns one or more string-based permissions directly to this Account (not to any of its realms).booleanReturnstrueif the specified object is also aSimpleAccountand itsprincipalsare equal to this object'sprincipals,falseotherwise.Simply returnsthis.authcInfo.getCredentials.org.apache.shiro.lang.util.ByteSourceReturns the salt used to hash this Account's credentials (e.g.Returns all object-based permissions assigned directly to this Account (not any of its realms).Returns the principals, aka the identifying attributes (username, user id, first name, last name, etc.) of this Account.getRoles()Returnsthis.authzInfo.getRoles();Returns all String-based permissions assigned to this Account.inthashCode()If theprincipalsare not null, returnsprincipals.hashCode(), otherwise returns 0 (zero).booleanReturns whether or not the Account's credentials are expired.booleanisLocked()Returnstrueif this Account is locked and thus cannot be used to login,falseotherwise.voidmerge(AuthenticationInfo info) Merges the specifiedAuthenticationInfointo thisAccount.voidsetCredentials(Object credentials) Sets this Account's credentials that verify one or more of the Account'sprincipals, such as a password or private key.voidsetCredentialsExpired(boolean credentialsExpired) Sets whether or not the Account's credentials are expired.voidsetCredentialsSalt(org.apache.shiro.lang.util.ByteSource salt) Sets the salt to use to hash this Account's credentials (e.g.voidsetLocked(boolean locked) Sets whether or not the account is locked and can be used to login.voidsetObjectPermissions(Set<Permission> permissions) Set al.voidsetPrincipals(PrincipalCollection principals) Sets the principals, aka the identifying attributes (username, user id, first name, last name, etc.) of this Account.voidSets the Account's assigned roles.voidsetStringPermissions(Set<String> permissions) Sets the String-based permissions assigned to this Account.toString()Returnsprincipals.toString() if they are not null, otherwise prints out the string "empty"
-
Constructor Details
-
SimpleAccount
public SimpleAccount()Default no-argument constructor. -
SimpleAccount
Constructs a SimpleAccount instance for the specified realm with the given principals and credentials.- Parameters:
principal- the 'primary' identifying attribute of the account, for example, a user id or username.credentials- the credentials that verify identity for the accountrealmName- the name of the realm that accesses this account data
-
SimpleAccount
public SimpleAccount(Object principal, Object hashedCredentials, org.apache.shiro.lang.util.ByteSource credentialsSalt, String realmName) Constructs a SimpleAccount instance for the specified realm with the given principals, hashedCredentials and credentials salt used when hashing the credentials.- Parameters:
principal- the 'primary' identifying attribute of the account, for example, a user id or username.hashedCredentials- the credentials that verify identity for the accountcredentialsSalt- the salt used when hashing the credentialsrealmName- the name of the realm that accesses this account data- Since:
- 1.1
- See Also:
-
SimpleAccount
Constructs a SimpleAccount instance for the specified realm with the given principals and credentials.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.credentials- the credentials that verify identity for the accountrealmName- the name of the realm that accesses this account data
-
SimpleAccount
Constructs a SimpleAccount instance for the specified principals and credentials.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.credentials- the credentials that verify identity for the account
-
SimpleAccount
public SimpleAccount(PrincipalCollection principals, Object hashedCredentials, org.apache.shiro.lang.util.ByteSource credentialsSalt) Constructs a SimpleAccount instance for the specified principals and credentials.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.hashedCredentials- the hashed credentials that verify identity for the accountcredentialsSalt- the salt used when hashing the credentials- Since:
- 1.1
- See Also:
-
SimpleAccount
Constructs a SimpleAccount instance for the specified principals and credentials, with the assigned roles.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.credentials- the credentials that verify identity for the accountroles- the names of the roles assigned to this account.
-
SimpleAccount
public SimpleAccount(Object principal, Object credentials, String realmName, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance for the specified realm with the given principal and credentials, with the the assigned roles and permissions.- Parameters:
principal- the 'primary' identifying attributes of the account, for example, a user id or username.credentials- the credentials that verify identity for the accountrealmName- the name of the realm that accesses this account dataroleNames- the names of the roles assigned to this account.permissions- the permissions assigned to this account directly (not those assigned to any of the realms).
-
SimpleAccount
public SimpleAccount(Collection principals, Object credentials, String realmName, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance for the specified realm with the given principals and credentials, with the the assigned roles and permissions.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.credentials- the credentials that verify identity for the accountrealmName- the name of the realm that accesses this account dataroleNames- the names of the roles assigned to this account.permissions- the permissions assigned to this account directly (not those assigned to any of the realms).
-
SimpleAccount
public SimpleAccount(PrincipalCollection principals, Object credentials, Set<String> roleNames, Set<Permission> permissions) Constructs a SimpleAccount instance from the given principals and credentials, with the the assigned roles and permissions.- Parameters:
principals- the identifying attributes of the account, at least one of which should be considered the account's 'primary' identifying attribute, for example, a user id or username.credentials- the credentials that verify identity for the accountroleNames- the names of the roles assigned to this account.permissions- the permissions assigned to this account directly (not those assigned to any of the realms).
-
-
Method Details
-
getPrincipals
Returns the principals, aka the identifying attributes (username, user id, first name, last name, etc.) of this Account.- Specified by:
getPrincipalsin interfaceAuthenticationInfo- Returns:
- all the principals, aka the identifying attributes, of this Account.
-
setPrincipals
Sets the principals, aka the identifying attributes (username, user id, first name, last name, etc.) of this Account.- Parameters:
principals- all the principals, aka the identifying attributes, of this Account.- See Also:
-
getCredentials
Simply returnsthis.authcInfo.getCredentials. TheauthcInfoattribute is constructed via the constructors to wrap the input arguments.- Specified by:
getCredentialsin interfaceAuthenticationInfo- Returns:
- this Account's credentials.
-
setCredentials
Sets this Account's credentials that verify one or more of the Account'sprincipals, such as a password or private key.- Parameters:
credentials- the credentials associated with this Account that verify one or more of the Account principals.- See Also:
-
getCredentialsSalt
Returns the salt used to hash this Account's credentials (e.g. for password hashing), ornullif no salt was used or credentials were not hashed at all.- Specified by:
getCredentialsSaltin interfaceSaltedAuthenticationInfo- Returns:
- the salt used to hash this Account's credentials (e.g. for password hashing), or
nullif no salt was used or credentials were not hashed at all. - Since:
- 1.1
-
setCredentialsSalt
Sets the salt to use to hash this Account's credentials (e.g. for password hashing), ornullif no salt is used or credentials are not hashed at all.- Parameters:
salt- the salt to use to hash this Account's credentials (e.g. for password hashing), ornullif no salt is used or credentials are not hashed at all.- Since:
- 1.1
-
getRoles
Returnsthis.authzInfo.getRoles();- Specified by:
getRolesin interfaceAuthorizationInfo- Returns:
- the Account's assigned roles.
-
setRoles
-
addRole
-
addRole
Adds one or more roles to this Account's set of assigned roles. Simply delegates tothis.authzInfo.addRoles(roles).- Parameters:
roles- one or more roles to assign to this Account.
-
getStringPermissions
Returns all String-based permissions assigned to this Account. Simply delegates tothis.authzInfo.getStringPermissions().- Specified by:
getStringPermissionsin interfaceAuthorizationInfo- Returns:
- all String-based permissions assigned to this Account.
-
setStringPermissions
Sets the String-based permissions assigned to this Account. Simply delegates tothis.authzInfo.setStringPermissions(permissions).- Parameters:
permissions- all String-based permissions assigned to this Account.- See Also:
-
addStringPermission
Assigns a String-based permission directly to this Account (not to any of its realms).- Parameters:
permission- the String-based permission to assign.
-
addStringPermissions
Assigns one or more string-based permissions directly to this Account (not to any of its realms).- Parameters:
permissions- one or more String-based permissions to assign.
-
getObjectPermissions
Returns all object-based permissions assigned directly to this Account (not any of its realms).- Specified by:
getObjectPermissionsin interfaceAuthorizationInfo- Returns:
- all object-based permissions assigned directly to this Account (not any of its realms).
-
setObjectPermissions
Set al. object-based permissions assigned directly to this Account (not any of its realms).- Parameters:
permissions- the object-based permissions to assign directly to this Account.
-
addObjectPermission
Assigns an object-based permission directly to this Account (not any of its realms).- Parameters:
permission- the object-based permission to assign directly to this Account (not any of its realms).
-
addObjectPermissions
Assigns one or more object-based permissions directly to this Account (not any of its realms).- Parameters:
permissions- one or more object-based permissions to assign directly to this Account (not any of its realms).
-
isLocked
Returnstrueif this Account is locked and thus cannot be used to login,falseotherwise.- Returns:
trueif this Account is locked and thus cannot be used to login,falseotherwise.
-
setLocked
Sets whether or not the account is locked and can be used to login.- Parameters:
locked-trueif this Account is locked and thus cannot be used to login,falseotherwise.
-
isCredentialsExpired
Returns whether or not the Account's credentials are expired. This usually indicates that the Subject or an application administrator would need to change the credentials before the account could be used.- Returns:
- whether or not the Account's credentials are expired.
-
setCredentialsExpired
Sets whether or not the Account's credentials are expired. Atruevalue indicates that the Subject or application administrator would need to change their credentials before the account could be used.- Parameters:
credentialsExpired-trueif this Account's credentials are expired and need to be changed,falseotherwise.
-
merge
Merges the specifiedAuthenticationInfointo thisAccount. If the specified argument is also an instance ofSimpleAccount, theisLocked()andisCredentialsExpired()attributes are merged (set on this instance) as well (only if their values aretrue).- Specified by:
mergein interfaceMergableAuthenticationInfo- Parameters:
info- theAuthenticationInfoto merge into this account.
-
hashCode
If theprincipalsare not null, returnsprincipals.hashCode(), otherwise returns 0 (zero). -
equals
Returnstrueif the specified object is also aSimpleAccountand itsprincipalsare equal to this object'sprincipals,falseotherwise.- Overrides:
equalsin classObject- Parameters:
o- the object to test for equality.- Returns:
trueif the specified object is also aSimpleAccountand itsprincipalsare equal to this object'sprincipals,falseotherwise.
-
toString
Returnsprincipals.toString() if they are not null, otherwise prints out the string "empty"
-