|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Subject
A Subject represents state and security operations for a single application user. These operations include authentication (login/logout), authorization (access control), and session access. It is JSecurity's primary mechanism for single-user security functionality.
Note that there are many *Permission methods in this interface overloaded to accept String arguments instead of
Permission instances. They are a convenience allowing the caller to use a String representation of
a Permission if desired. The underlying Authorization subsystem implementations will usually
simply convert these String values to Permission instances and then just call the corresponding
type-safe method. (JSecurity's default implementations do String-to-Permission conversion for these methods using
PermissionResolvers.)
These overloaded *Permission methods do forego type-saftey for the benefit of convenience and simplicity, so you should choose which ones to use based on your preferences and needs.
| Method Summary | |
|---|---|
void |
checkPermission(Permission permission)
Ensures this Subject implies the specified Permission. |
void |
checkPermission(String permission)
Ensures this Subject implies the specified permission String. |
void |
checkPermissions(Collection<Permission> permissions)
Ensures this Subject implies all of the
specified permission strings. |
void |
checkPermissions(String... permissions)
Ensures this Subject implies all of the
specified permission strings. |
void |
checkRole(String roleIdentifier)
Asserts this Subject has the specified role by returning quietly if they do or throwing an AuthorizationException if they do not. |
void |
checkRoles(Collection<String> roleIdentifiers)
Asserts this Subject has all of the specified roles by returning quietly if they do or throwing an AuthorizationException if they do not. |
Object |
getPrincipal()
Returns this Subject's uniquely-identifying principal, or null if this Subject doesn't yet have account data associated with it (for example, if they haven't logged in). |
PrincipalCollection |
getPrincipals()
|
Session |
getSession()
Returns the application Session associated with this Subject. |
Session |
getSession(boolean create)
Returns the application Session associated with this Subject. |
boolean |
hasAllRoles(Collection<String> roleIdentifiers)
Returns true if this Subject has all of the specified roles, false otherwise. |
boolean |
hasRole(String roleIdentifier)
Returns true if this Subject has the specified role, false otherwise. |
boolean[] |
hasRoles(List<String> roleIdentifiers)
Checks if this Subject has the specified roles, returning a boolean array indicating which roles are associated. |
boolean |
isAuthenticated()
Returns true if this Subject/user has proven their identity during their current session by providing valid credentials matching those known to the system, false otherwise. |
boolean[] |
isPermitted(List<Permission> permissions)
Checks if this Subject implies the given Permissions and returns a boolean array indicating which permissions are implied. |
boolean |
isPermitted(Permission permission)
Returns true if this Subject is permitted to perform an action or access a resource summarized by the specified permission. |
boolean[] |
isPermitted(String... permissions)
Checks if this Subject implies the given permission strings and returns a boolean array indicating which permissions are implied. |
boolean |
isPermitted(String permission)
Returns true if this Subject is permitted to perform an action or access a resource summarized by the specified permission string. |
boolean |
isPermittedAll(Collection<Permission> permissions)
Returns true if this Subject implies all of the specified permissions, false otherwise. |
boolean |
isPermittedAll(String... permissions)
Returns true if this Subject implies all of the specified permission strings, false otherwise. |
void |
login(AuthenticationToken token)
Performs a login attempt for this Subject/user. |
void |
logout()
Logs out this Subject and invalidates and/or removes any associated entities (such as a Session and authorization data. |
| Method Detail |
|---|
Object getPrincipal()
The term principal is just a fancy security term for any identifying attribute(s) of an application user, such as a username, or user id, or public key, or anything else you might use in your application to identify a user. And although given names and family names (first/last) are technically principals as well, JSecurity expects the object(s) returned from this method to be uniquely identifying attibute(s) for your application. This implies that things like given names and family names are usually poor candidates as return values since they are rarely guaranteed to be unique.
Most single-Realm applications would return from this method a single unique principal as noted above (for example a String username or Long user id, etc, etc). Single-realm applications represent the large majority of JSecurity applications.
However, in multi-Realm configurations, which are fully supported by JSecurity as well, it is possible that the return value encapsulates more than one principal. Typically multi-realm applications need to retain the unique principals for each Realm so subsequent security checks against these Realms can utilize these multiple principals. In these cases, the object returned could be a Collection or any application-specific instance that encapsulates the principals.
PrincipalCollection getPrincipals()
boolean isPermitted(String permission)
This is an overloaded method for the corresponding type-safe Permission variant.
Please see the class-level JavaDoc for more information on these String-based permission methods.
permission - the String representation of a Permission that is being checked.
isPermitted(Permission permission)boolean isPermitted(Permission permission)
More specifically, this method determines if any Permissions associated
with the subject imply the specified permission.
permission - the permission that is being checked.
boolean[] isPermitted(String... permissions)
This is an overloaded method for the corresponding type-safe Permission variant.
Please see the class-level JavaDoc for more information on these String-based permission methods.
permissions - the String representations of the Permissions that are being checked.
boolean[] isPermitted(List<Permission> permissions)
More specifically, this method should determine if each Permission in
the array is implied by permissions
already associated with the subject.
This is primarily a performance-enhancing method to help reduce the number of
isPermitted(java.lang.String) invocations over the wire in client/server systems.
permissions - the permissions that are being checked.
boolean isPermittedAll(String... permissions)
This is an overloaded method for the corresponding type-safe Permission variant.
Please see the class-level JavaDoc for more information on these String-based permission methods.
permissions - the String representations of the Permissions that are being checked.
isPermittedAll(Collection)boolean isPermittedAll(Collection<Permission> permissions)
More specifically, this method determines if all of the given Permissions are
implied by permissions already associated with this Subject.
permissions - the permissions to check.
void checkPermission(String permission)
throws AuthorizationException
If this subject's existing associated permissions do not Permission.implies(Permission) imply}
the given permission, an AuthorizationException will be thrown.
This is an overloaded method for the corresponding type-safe Permission variant.
Please see the class-level JavaDoc for more information on these String-based permission methods.
permission - the String representation of the Permission to check.
AuthorizationException - if the user does not have the permission.
void checkPermission(Permission permission)
throws AuthorizationException
implies the specified Permission.
If this subject's exisiting associated permissions do not imply
the given permission, an AuthorizationException will be thrown.
permission - the Permission to check.
AuthorizationException - if this Subject does not have the permission.
void checkPermissions(String... permissions)
throws AuthorizationException
implies all of the
specified permission strings.
If this subject's exisiting associated permissions do not
imply all of the given permissions,
an AuthorizationException will be thrown.
This is an overloaded method for the corresponding type-safe Permission variant.
Please see the class-level JavaDoc for more information on these String-based permission methods.
permissions - the string representations of Permissions to check.
AuthorizationException - if this Subject does not have all of the given permissions.
void checkPermissions(Collection<Permission> permissions)
throws AuthorizationException
implies all of the
specified permission strings.
If this subject's exisiting associated permissions do not
imply all of the given permissions,
an AuthorizationException will be thrown.
permissions - the Permissions to check.
AuthorizationException - if this Subject does not have all of the given permissions.boolean hasRole(String roleIdentifier)
roleIdentifier - the application-specific role identifier (usually a role id or role name).
boolean[] hasRoles(List<String> roleIdentifiers)
This is primarily a performance-enhancing method to help reduce the number of
hasRole(java.lang.String) invocations over the wire in client/server systems.
roleIdentifiers - the application-specific role identifiers to check (usually role ids or role names).
boolean hasAllRoles(Collection<String> roleIdentifiers)
roleIdentifiers - the application-specific role identifiers to check (usually role ids or role names).
void checkRole(String roleIdentifier)
throws AuthorizationException
AuthorizationException if they do not.
roleIdentifier - the application-specific role identifier (usually a role id or role name ).
AuthorizationException - if this Subject does not have the role.
void checkRoles(Collection<String> roleIdentifiers)
throws AuthorizationException
AuthorizationException if they do not.
roleIdentifiers - the application-specific role identifiers to check (usually role ids or role names).
AuthorizationException - if this Subject does not have all of the specified roles.
void login(AuthenticationToken token)
throws AuthenticationException
AuthenticationException is thrown, the subclass of which identifies why the attempt failed.
If successful, the account data associated with the submitted principals/credentials will be
associated with this Subject and the method will return quietly.
Upon returninq quietly, this Subject instance can be considered
authenticated and getPrincipal() will be non-null and
isAuthenticated() will be true.
token - the token encapsulating the subject's principals and credentials to be passed to the
Authentication subsystem for verification.
AuthenticationException - if the authentication attempt fails.boolean isAuthenticated()
Note that even if this Subject's identity has been remembered via 'remember me' services, this method will
still return false unless the user has actually logged in with proper credentials during their
current session. See the
RememberMeAuthenticationToken class JavaDoc for why
this would occur.
Session getSession()
getSession(boolean)Session getSession(boolean create)
create - boolean argument determining if a new session should be created or not if there is no existing session.
void logout()
Session and authorization data.
|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||