Package org.apache.shiro.authc
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 theAccount
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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SimpleAccount()
Default 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.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.util.ByteSource credentialsSalt)
Constructs a SimpleAccount instance for the specified principals and credentials.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObjectPermission(Permission permission)
Assigns an object-based permission directly to this Account (not any of its realms).void
addObjectPermissions(Collection<Permission> permissions)
Assigns one or more object-based permissions directly to this Account (not any of its realms).void
addRole(String role)
Adds a role to this Account's set of assigned roles.void
addRole(Collection<String> roles)
Adds one or more roles to this Account's set of assigned roles.void
addStringPermission(String permission)
Assigns a String-based permission directly to this Account (not to any of its realms).void
addStringPermissions(Collection<String> permissions)
Assigns one or more string-based permissions directly to this Account (not to any of its realms).boolean
equals(Object o)
Returnstrue
if the specified object is also aSimpleAccount
and itsprincipals
are equal to this object'sprincipals
,false
otherwise.Object
getCredentials()
Simply returnsthis.authcInfo.getCredentials
.org.apache.shiro.util.ByteSource
getCredentialsSalt()
Returns the salt used to hash this Account's credentials (eg for password hashing), ornull
if no salt was used or credentials were not hashed at all.Collection<Permission>
getObjectPermissions()
Returns all object-based permissions assigned directly to this Account (not any of its realms).PrincipalCollection
getPrincipals()
Returns the principals, aka the identifying attributes (username, user id, first name, last name, etc) of this Account.Collection<String>
getRoles()
Returnsthis.authzInfo.getRoles();
Collection<String>
getStringPermissions()
Returns all String-based permissions assigned to this Account.int
hashCode()
If theprincipals
are not null, returnsprincipals.hashCode()
, otherwise returns 0 (zero).boolean
isCredentialsExpired()
Returns whether or not the Account's credentials are expired.boolean
isLocked()
Returnstrue
if this Account is locked and thus cannot be used to login,false
otherwise.void
merge(AuthenticationInfo info)
Merges the specifiedAuthenticationInfo
into thisAccount
.void
setCredentials(Object credentials)
Sets this Account's credentials that verify one or more of the Account'sprincipals
, such as a password or private key.void
setCredentialsExpired(boolean credentialsExpired)
Sets whether or not the Account's credentials are expired.void
setCredentialsSalt(org.apache.shiro.util.ByteSource salt)
Sets the salt to use to hash this Account's credentials (eg for password hashing), ornull
if no salt is used or credentials are not hashed at all.void
setLocked(boolean locked)
Sets whether or not the account is locked and can be used to login.void
setObjectPermissions(Set<Permission> permissions)
Sets all object-based permissions assigned directly to this Account (not any of its realms).void
setPrincipals(PrincipalCollection principals)
Sets the principals, aka the identifying attributes (username, user id, first name, last name, etc) of this Account.void
setRoles(Set<String> roles)
Sets the Account's assigned roles.void
setStringPermissions(Set<String> permissions)
Sets the String-based permissions assigned to this Account.String
toString()
Returnsprincipals
.toString() if they are not null, otherwise prints out the string "empty"
-
-
-
Constructor Detail
-
SimpleAccount
public SimpleAccount()
Default no-argument constructor.
-
SimpleAccount
public SimpleAccount(Object principal, Object credentials, String realmName)
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.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:
HashedCredentialsMatcher
-
SimpleAccount
public SimpleAccount(Collection principals, Object credentials, String realmName)
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
public SimpleAccount(PrincipalCollection principals, Object credentials)
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.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:
HashedCredentialsMatcher
-
SimpleAccount
public SimpleAccount(PrincipalCollection principals, Object credentials, Set<String> roles)
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 Detail
-
getPrincipals
public PrincipalCollection getPrincipals()
Returns the principals, aka the identifying attributes (username, user id, first name, last name, etc) of this Account.- Specified by:
getPrincipals
in interfaceAuthenticationInfo
- Returns:
- all the principals, aka the identifying attributes, of this Account.
-
setPrincipals
public void setPrincipals(PrincipalCollection principals)
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:
AuthenticationInfo.getPrincipals()
-
getCredentials
public Object getCredentials()
Simply returnsthis.authcInfo.getCredentials
. TheauthcInfo
attribute is constructed via the constructors to wrap the input arguments.- Specified by:
getCredentials
in interfaceAuthenticationInfo
- Returns:
- this Account's credentials.
-
setCredentials
public void setCredentials(Object credentials)
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:
AuthenticationInfo.getCredentials()
-
getCredentialsSalt
public org.apache.shiro.util.ByteSource getCredentialsSalt()
Returns the salt used to hash this Account's credentials (eg for password hashing), ornull
if no salt was used or credentials were not hashed at all.- Specified by:
getCredentialsSalt
in interfaceSaltedAuthenticationInfo
- Returns:
- the salt used to hash this Account's credentials (eg for password hashing), or
null
if 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 to use to hash this Account's credentials (eg for password hashing), ornull
if no salt is used or credentials are not hashed at all.- Parameters:
salt
- the salt to use to hash this Account's credentials (eg for password hashing), ornull
if no salt is used or credentials are not hashed at all.- Since:
- 1.1
-
getRoles
public Collection<String> getRoles()
Returnsthis.authzInfo.getRoles();
- Specified by:
getRoles
in interfaceAuthorizationInfo
- Returns:
- the Account's assigned roles.
-
setRoles
public void setRoles(Set<String> roles)
Sets the Account's assigned roles. Simply callsthis.authzInfo.setRoles(roles)
.- Parameters:
roles
- the Account's assigned roles.- See Also:
AuthorizationInfo.getRoles()
-
addRole
public void addRole(String role)
Adds a role to this Account's set of assigned roles. Simply delegates tothis.authzInfo.addRole(role)
.- Parameters:
role
- a role to assign to this Account.
-
addRole
public void addRole(Collection<String> roles)
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
public Collection<String> getStringPermissions()
Returns all String-based permissions assigned to this Account. Simply delegates tothis.authzInfo.getStringPermissions()
.- Specified by:
getStringPermissions
in interfaceAuthorizationInfo
- Returns:
- all String-based permissions assigned to this Account.
-
setStringPermissions
public void setStringPermissions(Set<String> permissions)
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:
AuthorizationInfo.getStringPermissions()
-
addStringPermission
public void addStringPermission(String permission)
Assigns a String-based permission directly to this Account (not to any of its realms).- Parameters:
permission
- the String-based permission to assign.
-
addStringPermissions
public void addStringPermissions(Collection<String> permissions)
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
public Collection<Permission> getObjectPermissions()
Returns all object-based permissions assigned directly to this Account (not any of its realms).- Specified by:
getObjectPermissions
in interfaceAuthorizationInfo
- Returns:
- all object-based permissions assigned directly to this Account (not any of its realms).
-
setObjectPermissions
public void setObjectPermissions(Set<Permission> permissions)
Sets all 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
public void addObjectPermission(Permission permission)
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
public void addObjectPermissions(Collection<Permission> permissions)
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
public boolean isLocked()
Returnstrue
if this Account is locked and thus cannot be used to login,false
otherwise.- Returns:
true
if this Account is locked and thus cannot be used to login,false
otherwise.
-
setLocked
public void setLocked(boolean locked)
Sets whether or not the account is locked and can be used to login.- Parameters:
locked
-true
if this Account is locked and thus cannot be used to login,false
otherwise.
-
isCredentialsExpired
public boolean 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
public void setCredentialsExpired(boolean credentialsExpired)
Sets whether or not the Account's credentials are expired. Atrue
value indicates that the Subject or application administrator would need to change their credentials before the account could be used.- Parameters:
credentialsExpired
-true
if this Account's credentials are expired and need to be changed,false
otherwise.
-
merge
public void merge(AuthenticationInfo info)
Merges the specifiedAuthenticationInfo
into 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:
merge
in interfaceMergableAuthenticationInfo
- Parameters:
info
- theAuthenticationInfo
to merge into this account.
-
hashCode
public int hashCode()
If theprincipals
are not null, returnsprincipals.hashCode()
, otherwise returns 0 (zero).
-
equals
public boolean equals(Object o)
Returnstrue
if the specified object is also aSimpleAccount
and itsprincipals
are equal to this object'sprincipals
,false
otherwise.- Overrides:
equals
in classObject
- Parameters:
o
- the object to test for equality.- Returns:
true
if the specified object is also aSimpleAccount
and itsprincipals
are equal to this object'sprincipals
,false
otherwise.
-
toString
public String toString()
Returnsprincipals
.toString() if they are not null, otherwise prints out the string "empty"
-
-