com.atlassian.confluence.security
Class CachingSpacePermissionManager

java.lang.Object
  extended by com.atlassian.confluence.security.AbstractSpacePermissionManager
      extended by com.atlassian.confluence.security.DefaultSpacePermissionManager
          extended by com.atlassian.confluence.security.CachingSpacePermissionManager
All Implemented Interfaces:
SpacePermissionManager, SpacePermissionSaver

@Internal
public class CachingSpacePermissionManager
extends DefaultSpacePermissionManager

Implementation of SpacePermissionManager that implements caching before a SpacePermission is requested, saved or removed from the SpacePermissionDao. This is designed to increase performance and reduce the amount of hits on the database.


Field Summary
static String CACHE_KEY
           
 
Fields inherited from class com.atlassian.confluence.security.AbstractSpacePermissionManager
spacePermissionDao
 
Constructor Summary
CachingSpacePermissionManager(SpacePermissionDao spacePermissionDao, PermissionCheckExemptions permissionCheckExemptions, SpacePermissionDefaultsStoreFactory spacePermissionDefaultsStoreFactory, com.atlassian.cache.CacheFactory cacheFactory)
           
 
Method Summary
protected  boolean canUseConfluence(com.atlassian.user.User remoteUser, String permissionCheck)
           
 void flushCaches()
           
protected  Set<String> getGroupNamesWithPermission(Space targetSpace, String permissionType)
           
 boolean hasPermission(String permissionType, Space space, com.atlassian.user.User remoteUser)
          Determines if remoteUser has the given permission in space Unless you're writing code that is part of the permission checking implementation, or you're changing space permissions, you should be using PermissionManager instead.
 boolean isLookAheadEnabled()
           
 boolean permissionExists(SpacePermission permission)
          Looks up permission in the cache instance.
 void removeAllPermissions(Space space)
          Removes all permissions belonging to space
 void removeAllPermissionsForGroup(String group)
           
 void removePermission(SpacePermission spacePermission)
          Removes the specified permission.
protected  void removePermissionFromDao(SpacePermission spacePermission)
          Removes realPermission from the DAO.
protected  void savePermissionToDao(SpacePermission spacePermission)
          Saves permission to the DAO.
 void setLookAheadEnabled(boolean lookAheadEnabled)
           
 
Methods inherited from class com.atlassian.confluence.security.DefaultSpacePermissionManager
createDefaultSpacePermissions, createInitialSpacePermissions, createPrivateSpacePermissions, getAllPermissionsForGroup, getAllPermissionsForUser, getGlobalPermissions, getGlobalPermissions, getGroupsForPermissionType, getGroupsWithPermissions, getUsersForPermissionType, getUsersWithPermissions, groupHasPermission, hasAllPermissions, hasPermission, removeAllUserPermissions, removeAllUserPermissions, removeGlobalPermissionForUser, removePermissions, savePermission
 
Methods inherited from class com.atlassian.confluence.security.AbstractSpacePermissionManager
getDefaultGlobalPermissions, getUserAccessor, hasPermissionForSpace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_KEY

public static final String CACHE_KEY
Constructor Detail

CachingSpacePermissionManager

public CachingSpacePermissionManager(SpacePermissionDao spacePermissionDao,
                                     PermissionCheckExemptions permissionCheckExemptions,
                                     SpacePermissionDefaultsStoreFactory spacePermissionDefaultsStoreFactory,
                                     com.atlassian.cache.CacheFactory cacheFactory)
Method Detail

permissionExists

public boolean permissionExists(SpacePermission permission)
Looks up permission in the cache instance. If it is not found, then it is looked up by the DAO and the result (true or false) is also recorded.

If permission belongs to a space, it is looked up in the Space's own permissions list.

In addition, when lookAheadEnabled is true, #doLookAheadCache will be called and the results cached, provided permission does not belong to a space.

Specified by:
permissionExists in interface SpacePermissionManager
Overrides:
permissionExists in class DefaultSpacePermissionManager
Parameters:
permission - the SpacePermission to look up
Returns:
true if the permission exists, false otherwise

savePermissionToDao

protected void savePermissionToDao(SpacePermission spacePermission)
Saves permission to the DAO. In addition, this method removes the permission from the cache, to prevent corruption of the cache when there is a transaction rollback (since the cache isn't transactional)

Overrides:
savePermissionToDao in class DefaultSpacePermissionManager
Parameters:
spacePermission - the SpacePermission to save

removePermissionFromDao

protected void removePermissionFromDao(SpacePermission spacePermission)
Removes realPermission from the DAO. In addition, the permission is also removed from the cache.

Overrides:
removePermissionFromDao in class DefaultSpacePermissionManager
Parameters:
spacePermission - the SpacePermission to remove

removeAllPermissions

public void removeAllPermissions(Space space)
Description copied from interface: SpacePermissionManager
Removes all permissions belonging to space

Specified by:
removeAllPermissions in interface SpacePermissionManager
Overrides:
removeAllPermissions in class DefaultSpacePermissionManager
Parameters:
space - The space to remove the permissions for

flushCaches

public void flushCaches()
Specified by:
flushCaches in interface SpacePermissionManager
Overrides:
flushCaches in class DefaultSpacePermissionManager

isLookAheadEnabled

public boolean isLookAheadEnabled()

setLookAheadEnabled

public void setLookAheadEnabled(boolean lookAheadEnabled)

hasPermission

public boolean hasPermission(String permissionType,
                             Space space,
                             com.atlassian.user.User remoteUser)
Description copied from interface: SpacePermissionManager
Determines if remoteUser has the given permission in space Unless you're writing code that is part of the permission checking implementation, or you're changing space permissions, you should be using PermissionManager instead.

Specified by:
hasPermission in interface SpacePermissionManager
Overrides:
hasPermission in class DefaultSpacePermissionManager
Parameters:
permissionType - The permission type to look up
space - The space the permission applies to (can be null for global permissions)
remoteUser - The user to look up (can be null for the anonymous user)
Returns:
true if remoteUser has the permission, false otherwise

canUseConfluence

protected boolean canUseConfluence(com.atlassian.user.User remoteUser,
                                   String permissionCheck)
Overrides:
canUseConfluence in class DefaultSpacePermissionManager

getGroupNamesWithPermission

protected Set<String> getGroupNamesWithPermission(Space targetSpace,
                                                  String permissionType)
Overrides:
getGroupNamesWithPermission in class DefaultSpacePermissionManager

removePermission

public void removePermission(SpacePermission spacePermission)
Description copied from class: DefaultSpacePermissionManager
Removes the specified permission.

Specified by:
removePermission in interface SpacePermissionManager
Overrides:
removePermission in class DefaultSpacePermissionManager

removeAllPermissionsForGroup

public void removeAllPermissionsForGroup(String group)
Specified by:
removeAllPermissionsForGroup in interface SpacePermissionManager
Overrides:
removeAllPermissionsForGroup in class DefaultSpacePermissionManager


Copyright © 2003–2015 Atlassian. All rights reserved.