Package org.wicketstuff.security.hive
Class BasicHive
- java.lang.Object
-
- org.wicketstuff.security.hive.BasicHive
-
- All Implemented Interfaces:
Hive
- Direct Known Subclasses:
SimpleCachingHive
public class BasicHive extends Object implements Hive
Basic implementation of a Hive. It contains basic add methods to facilitate factories. It also might be locked after which no changes can be made to the hive.- Author:
- marrink
-
-
Constructor Summary
Constructors Constructor Description BasicHive()Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPermission(Principal principal, Permission permission)Adds a new permission to a principal.voidaddPrincipal(Principal principal, Collection<Permission> permissions)Adds a new Principal to the hive.protected BooleancacheLookUp(Subject subject, Permission permission)Allows subclasses to retrieve previously cached results and thus speed up the check.protected voidcacheResult(Subject subject, Permission permission, boolean result)Allows subclasses to cache the result of a check and thus speed up this check the next time.booleancontainsPermission(Permission permission)Checks if this hive contains exactly the permission.booleancontainsPrincipal(Principal principal)Checks if this hive contains an exact match for this principal.Set<Permission>getPermissions(Principal principal)Returns a set ofPermissions, contained within the principal.Set<Principal>getPrincipals(Permission permission)Returns a set ofPrincipals, each containing this permission.booleanhasPermission(Subject subject, Permission permission)Checks if the subject has the exact permission, or if the permission is implied by any of the subjects principals.booleanisLocked()Check if the hive is locked.voidlock()Locks this hive.
-
-
-
Method Detail
-
lock
public final void lock()
Locks this hive. No changes are allowed anymore. After thisisLocked()will return true;
-
isLocked
public final boolean isLocked()
Check if the hive is locked. If the hive is locked no changes can be made.- Returns:
- true if the hive is locked, false otherwise.
-
addPrincipal
public final void addPrincipal(Principal principal, Collection<Permission> permissions)
Adds a new Principal to the hive.- Parameters:
principal- the principalpermissions- a required collection of granted permissions for the principal- Throws:
IllegalStateException- if the hive is lockedIllegalArgumentException- if either parameter is null
-
addPermission
public final void addPermission(Principal principal, Permission permission)
Adds a new permission to a principal.- Parameters:
principal- the principalpermission- the permission granted- Throws:
IllegalStateException- if the hive is lockedIllegalArgumentException- if either parameter is null
-
containsPrincipal
public final boolean containsPrincipal(Principal principal)
Description copied from interface:HiveChecks if this hive contains an exact match for this principal.- Specified by:
containsPrincipalin interfaceHive- Returns:
- true if the hive contains the principal, false otherwise.
- See Also:
Hive.containsPrincipal(org.wicketstuff.security.hive.authorization.Principal)
-
cacheLookUp
protected Boolean cacheLookUp(Subject subject, Permission permission)
Allows subclasses to retrieve previously cached results and thus speed up the check. By default null is returned, meaning no cached value- Parameters:
subject- (optional) subjectpermission- the permission to check- Returns:
- null if there is no cached value, true if the permission is granted, false if the permission is denied
-
cacheResult
protected void cacheResult(Subject subject, Permission permission, boolean result)
Allows subclasses to cache the result of a check and thus speed up this check the next time. By default this method does not have an implementation.- Parameters:
subject- (optional) subjectpermission- the permission to checkresult- the result of the permission
-
hasPermission
public final boolean hasPermission(Subject subject, Permission permission)
Description copied from interface:HiveChecks if the subject has the exact permission, or if the permission is implied by any of the subjects principals.- Specified by:
hasPermissionin interfaceHive- Parameters:
subject- the (optional) subjectpermission- the permission to check.- Returns:
- true if the subject has or implies the permission, false otherwise.
- See Also:
Hive.hasPermission(org.wicketstuff.security.hive.authentication.Subject, org.wicketstuff.security.hive.authorization.Permission)
-
containsPermission
public final boolean containsPermission(Permission permission)
Description copied from interface:HiveChecks if this hive contains exactly the permission.- Specified by:
containsPermissionin interfaceHive- Returns:
- true if the hive contains the permission.
- See Also:
Hive.containsPermission(org.wicketstuff.security.hive.authorization.Permission)
-
getPermissions
public final Set<Permission> getPermissions(Principal principal)
Description copied from interface:HiveReturns a set ofPermissions, contained within the principal. Implementors must not allow modifications to the set change the internal state of the hive.- Specified by:
getPermissionsin interfaceHive- Returns:
- set, never null
- See Also:
Hive.getPermissions(org.wicketstuff.security.hive.authorization.Principal)
-
getPrincipals
public final Set<Principal> getPrincipals(Permission permission)
Description copied from interface:HiveReturns a set ofPrincipals, each containing this permission. Implementors must not allow modifications to the set change the internal state of the hive.- Specified by:
getPrincipalsin interfaceHive- Returns:
- set, never null
- See Also:
Hive.getPrincipals(org.wicketstuff.security.hive.authorization.Permission)
-
-