|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jsecurity.subject.DelegatingSubject
public class DelegatingSubject
Implementation of the Subject interface that delegates
method calls to an underlying SecurityManager instance for security checks.
It is essentially a SecurityManager proxy.
Subject
principals, such as usernames or user primary keys) for better performance in a stateless
architecture. It instead asks the underlying SecurityManager every time to perform
the authorization check.
A common misconception in using this implementation is that an EIS resource (RDBMS, etc) would
be "hit" every time a method is called. This is not necessarily the case and is
up to the implementation of the underlying SecurityManager instance. If caching of authorization
data is desired (to eliminate EIS round trips and therefore improve database performance), it is considered
much more elegant to let the underlying SecurityManager implementation or its delegate components
manage caching, not this class. A SecurityManager is considered a business-tier component,
where caching strategies are better suited.
Applications from large and clustered to simple and vm local all benefit from
stateless architectures. This implementation plays a part in the stateless programming
paradigm and should be used whenever possible.
| Field Summary | |
|---|---|
protected boolean |
authenticated
|
protected InetAddress |
inetAddress
|
protected PrincipalCollection |
principals
|
protected SecurityManager |
securityManager
|
protected Session |
session
|
| Constructor Summary | |
|---|---|
DelegatingSubject(PrincipalCollection principals,
boolean authenticated,
InetAddress inetAddress,
Session session,
SecurityManager securityManager)
|
|
DelegatingSubject(SecurityManager securityManager)
|
|
| Method Summary | |
|---|---|
protected void |
assertAuthzCheckPossible()
|
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 role)
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> roles)
Asserts this Subject has all of the specified roles by returning quietly if they do or throwing an AuthorizationException if they do not. |
InetAddress |
getInetAddress()
Returns the InetAddress associated with the client who created/is interacting with this Subject. |
protected static InetAddress |
getLocalHost()
|
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()
|
SecurityManager |
getSecurityManager()
|
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. |
protected boolean |
hasPrincipals()
|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected PrincipalCollection principals
protected boolean authenticated
protected InetAddress inetAddress
protected Session session
protected SecurityManager securityManager
| Constructor Detail |
|---|
public DelegatingSubject(SecurityManager securityManager)
public DelegatingSubject(PrincipalCollection principals,
boolean authenticated,
InetAddress inetAddress,
Session session,
SecurityManager securityManager)
| Method Detail |
|---|
protected static InetAddress getLocalHost()
public SecurityManager getSecurityManager()
protected boolean hasPrincipals()
public InetAddress getInetAddress()
public Object getPrincipal()
SubjectThe 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.
getPrincipal in interface SubjectSubject.getPrincipal()public PrincipalCollection getPrincipals()
getPrincipals in interface Subjectpublic boolean isPermitted(String permission)
SubjectThis 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.
isPermitted in interface Subjectpermission - the String representation of a Permission that is being checked.
Subject.isPermitted(Permission permission)public boolean isPermitted(Permission permission)
SubjectMore specifically, this method determines if any Permissions associated
with the subject imply the specified permission.
isPermitted in interface Subjectpermission - the permission that is being checked.
public boolean[] isPermitted(String... permissions)
SubjectThis 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.
isPermitted in interface Subjectpermissions - the String representations of the Permissions that are being checked.
public boolean[] isPermitted(List<Permission> permissions)
SubjectMore 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
Subject.isPermitted(java.lang.String) invocations over the wire in client/server systems.
isPermitted in interface Subjectpermissions - the permissions that are being checked.
public boolean isPermittedAll(String... permissions)
SubjectThis 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.
isPermittedAll in interface Subjectpermissions - the String representations of the Permissions that are being checked.
Subject.isPermittedAll(Collection)public boolean isPermittedAll(Collection<Permission> permissions)
SubjectMore specifically, this method determines if all of the given Permissions are
implied by permissions already associated with this Subject.
isPermittedAll in interface Subjectpermissions - the permissions to check.
protected void assertAuthzCheckPossible()
throws AuthorizationException
AuthorizationException
public void checkPermission(String permission)
throws AuthorizationException
SubjectIf 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.
checkPermission in interface Subjectpermission - the String representation of the Permission to check.
AuthorizationException - if the user does not have the permission.
public void checkPermission(Permission permission)
throws AuthorizationException
Subjectimplies the specified Permission.
If this subject's exisiting associated permissions do not imply
the given permission, an AuthorizationException will be thrown.
checkPermission in interface Subjectpermission - the Permission to check.
AuthorizationException - if this Subject does not have the permission.
public void checkPermissions(String... permissions)
throws AuthorizationException
Subjectimplies 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.
checkPermissions in interface Subjectpermissions - the string representations of Permissions to check.
AuthorizationException - if this Subject does not have all of the given permissions.
public void checkPermissions(Collection<Permission> permissions)
throws AuthorizationException
Subjectimplies 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.
checkPermissions in interface Subjectpermissions - the Permissions to check.
AuthorizationException - if this Subject does not have all of the given permissions.public boolean hasRole(String roleIdentifier)
Subject
hasRole in interface SubjectroleIdentifier - the application-specific role identifier (usually a role id or role name).
public boolean[] hasRoles(List<String> roleIdentifiers)
SubjectThis is primarily a performance-enhancing method to help reduce the number of
Subject.hasRole(java.lang.String) invocations over the wire in client/server systems.
hasRoles in interface SubjectroleIdentifiers - the application-specific role identifiers to check (usually role ids or role names).
public boolean hasAllRoles(Collection<String> roleIdentifiers)
Subject
hasAllRoles in interface SubjectroleIdentifiers - the application-specific role identifiers to check (usually role ids or role names).
public void checkRole(String role)
throws AuthorizationException
SubjectAuthorizationException if they do not.
checkRole in interface Subjectrole - the application-specific role identifier (usually a role id or role name ).
AuthorizationException - if this Subject does not have the role.
public void checkRoles(Collection<String> roles)
throws AuthorizationException
SubjectAuthorizationException if they do not.
checkRoles in interface Subjectroles - 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.
public void login(AuthenticationToken token)
throws AuthenticationException
SubjectAuthenticationException 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.
login in interface Subjecttoken - the token encapsulating the subject's principals and credentials to be passed to the
Authentication subsystem for verification.
AuthenticationException - if the authentication attempt fails.public boolean isAuthenticated()
SubjectNote 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.
isAuthenticated in interface Subjectpublic Session getSession()
Subject
getSession in interface SubjectSubject.getSession(boolean)public Session getSession(boolean create)
Subject
getSession in interface Subjectcreate - boolean argument determining if a new session should be created or not if there is no existing session.
public void logout()
SubjectSession and authorization data.
logout in interface Subject
|
JSecurity | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||