public class DefaultAuthorizationManager extends java.lang.Object implements AuthorizationManager
Default implementation for AuthorizationManager
See the checkPermission(Session, Permission) and hasRoleOrPrincipal(Session, Principal) methods for more
information on the authorization logic.
AuthenticationManagerDEFAULT_AUTHORIZER, DEFAULT_POLICY, POLICY, PROP_AUTHORIZER| Constructor and Description |
|---|
DefaultAuthorizationManager()
Constructs a new DefaultAuthorizationManager instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addWikiEventListener(WikiEventListener listener)
Registers a WikiEventListener with this instance.
|
boolean |
allowedByLocalPolicy(java.security.Principal[] principals,
java.security.Permission permission)
Checks to see if the local security policy allows a particular static Permission.
|
boolean |
checkPermission(Session session,
java.security.Permission permission)
Returns
true or false, depending on whether a Permission is allowed for the Subject associated with
a supplied Session. |
boolean |
checkStaticPermission(Session session,
java.security.Permission permission)
Determines whether a Subject possesses a given "static" Permission as defined in the security policy file.
|
Authorizer |
getAuthorizer()
Returns the current external
Authorizer in use. |
boolean |
hasAccess(Context context,
javax.servlet.http.HttpServletResponse response,
boolean redirect)
Checks whether the current user has access to the wiki context (and
optionally redirects if not), by obtaining the required Permission (
Command.requiredPermission())
and delegating the access check to AuthorizationManager.checkPermission(Session, Permission). |
boolean |
hasRoleOrPrincipal(Session session,
java.security.Principal principal)
Determines if the Subject associated with a supplied Session contains a desired user Principal or built-in Role principal,
OR is a member a Group or external Role.
|
void |
initialize(Engine engine,
java.util.Properties properties)
Expects to find property 'jspwiki.authorizer' with a valid Authorizer implementation name to take care of role lookup operations.
|
void |
removeWikiEventListener(WikiEventListener listener)
Un-registers a WikiEventListener with this instance.
|
java.security.Principal |
resolvePrincipal(java.lang.String name)
Given a supplied string representing a Principal's name from an Acl, this method resolves the correct type of Principal (role,
group, or user).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitfireEvent, hasAccess, isUserInRolepublic DefaultAuthorizationManager()
public boolean checkPermission(Session session, java.security.Permission permission)
true or false, depending on whether a Permission is allowed for the Subject associated with
a supplied Session. The access control algorithm works this way:
Acl for the page is obtainedSession is obtainedUnresolvedPrincipals (see below). Then iterate through the Subject's Principal set and determine
whether the user (Subject) possesses any one of these specified Roles or Principals.
Note that when iterating through the Acl's list of authorized Principals, it is possible that one or more of the Acl's Principal
entries are of type UnresolvedPrincipal. This means that the last time the ACL was read, the Principal (user, built-in
Role, authorizer Role, or wiki Group) could not be resolved: the Role was not valid, the user wasn't found in the UserDatabase, or
the Group wasn't known to (e.g., cached) in the GroupManager. If an UnresolvedPrincipal is encountered, this method
will attempt to resolve it first before checking to see if the Subject possesses this principal, by calling
AuthorizationManager.resolvePrincipal(String). If the (re-)resolution does not succeed, the access check for the principal will fail by
definition (the Subject should never contain UnresolvedPrincipals).
If security not set to JAAS, will return true.
checkPermission in interface AuthorizationManagersession - the current wiki sessionpermission - the Permission being checkedpublic Authorizer getAuthorizer() throws WikiSecurityException
Authorizer in use. This method is guaranteed to return a properly-initialized Authorizer, unless
it could not be initialized. In that case, this method throws a WikiSecurityException.getAuthorizer in interface AuthorizationManagerWikiSecurityException - if the Authorizer could not be initializedpublic boolean hasRoleOrPrincipal(Session session, java.security.Principal principal)
Determines if the Subject associated with a supplied Session contains a desired user Principal or built-in Role principal, OR is a member a Group or external Role. The rules are as follows:
AuthorizationManager.isUserInRole(Session, Principal) and
return the result.Note: if the Principal parameter is a user principal, the session must be authenticated in order for the user to "possess it". Anonymous or asserted sessions will never posseess a named user principal.
hasRoleOrPrincipal in interface AuthorizationManagersession - the current wiki session, which must be non-null. If null, the result of this method always returns falseprincipal - the Principal (role, group, or user principal) to look for, which must be non-null. If null, the result of this
method always returns falsetrue if the Subject supplied with the WikiContext posesses the Role, GroupPrincipal or desired
user Principal, false otherwisepublic boolean hasAccess(Context context, javax.servlet.http.HttpServletResponse response, boolean redirect) throws java.io.IOException
Command.requiredPermission())
and delegating the access check to AuthorizationManager.checkPermission(Session, Permission).
If the user is allowed, this method returns true;
false otherwise. Also, the wiki context will be added to the request as attribute
with the key name Context.ATTR_CONTEXT.hasAccess in interface AuthorizationManagercontext - wiki context to check if it is accesibleresponse - The servlet response objectredirect - If true, makes an automatic redirect to the responsejava.io.IOException - If something goes wrongpublic void initialize(Engine engine, java.util.Properties properties) throws WikiException
initialize in interface InitializableWikiExceptionpublic boolean allowedByLocalPolicy(java.security.Principal[] principals, java.security.Permission permission)
AuthorizationManager.checkPermission(Session, Permission) instead.allowedByLocalPolicy in interface AuthorizationManagerprincipals - the Principals to checkpermission - the Permissionpublic boolean checkStaticPermission(Session session, java.security.Permission permission)
codeBase is effectively this
class, not that of the caller. Therefore, this method will work best when what matters in the policy is who makes the
permission check, not what the caller's code source is. Internally, this method works by executing Subject.doAsPrivileged
with a privileged action that simply calls AccessController.checkPermission(Permission).checkStaticPermission in interface AuthorizationManagersession - the Session whose permission status is being queriedpermission - the Permission the Subject must possesstrue if the Subject possesses the permission, false otherwise. A caught exception (or lack thereof) determines whether the
privilege is absent (or present).public java.security.Principal resolvePrincipal(java.lang.String name)
Given a supplied string representing a Principal's name from an Acl, this method resolves the correct type of Principal (role, group, or user). This method is guaranteed to always return a Principal. The algorithm is straightforward:
Role names, return that built-in RoleAuthorizer, return that RoleGroupManager, return that GroupUserDatabase,
find the first user who matches the supplied name by calling UserDatabase.find(String).UnresolvedPrincipalresolvePrincipal in interface AuthorizationManagername - the name of the Principal to resolvepublic void addWikiEventListener(WikiEventListener listener)
addWikiEventListener in interface AuthorizationManagerlistener - the event listenerpublic void removeWikiEventListener(WikiEventListener listener)
removeWikiEventListener in interface AuthorizationManagerlistener - the event listenerCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.