Class DefaultSecurityService
java.lang.Object
com.broadleafcommerce.auth.security.service.DefaultSecurityService
- All Implemented Interfaces:
SecurityService
Methods for filtering scopes and permissions from what is accessible to what is requested or
relevant.
- Author:
- Nick Crum (ncrum), Cade Rea (cade-rea)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSecurityService
(PermissionRepository permissionRepository, ScopeRepository scopeRepository) -
Method Summary
Modifier and TypeMethodDescriptionfilterPermissionsRelevantToScopes
(Collection<String> candidatePermissions, Set<String> limitingScopes) Returns a sub-set from the givencandidatePermissions
of the permissions that belong to one of the givenlimitingScopes
.filterRelevantPermissions
(Collection<String> candidatePermissions, Set<String> permissionsForScopes) filterScopesByPermission
(Set<String> requestedScopes, Set<String> rootsFromPermissions) Deprecated.This incorrectly requires that all scopes/perms are 1-1 and ignores the permission root flag.filterScopesByPermission
(Set<String> requestedScopes, Set<String> permissionRoots, Set<String> accessiblePermissions) Filters scopes based on supplied permissions.filterScopesByPermissions
(Set<String> requestedScopes, Set<String> rootsFromPermissions) Deprecated.UsefilterScopesByPermission(Set, Set)
instead.filterToAccessibleScopes
(Set<String> requestedScopes, Set<String> accessiblePermissions) Returns the sub-set of requested scopes are accessible from the given permissions.findAllPermissionsForScopes
(Set<String> scopes) findOpenRequestedScopes
(Set<String> requestedScopes) Deprecated.UsefindOpenScopes(Set)
, which returns a Set instead of a Stream.findOpenScopes
(Set<String> requestedScopes) protected PermissionRepository
getRootsFromPermissions
(Set<String> collect) protected ScopeRepository
protected String
permissionToRoot
(String permission)
-
Constructor Details
-
DefaultSecurityService
public DefaultSecurityService(PermissionRepository permissionRepository, ScopeRepository scopeRepository)
-
-
Method Details
-
filterToAccessibleScopes
public Set<String> filterToAccessibleScopes(Set<String> requestedScopes, Set<String> accessiblePermissions) Description copied from interface:SecurityService
Returns the sub-set of requested scopes are accessible from the given permissions.Ensure that the requested scopes are accessible from the given permissions. If none of the requested scopes are accessible, this will return an empty set.
- Specified by:
filterToAccessibleScopes
in interfaceSecurityService
- Parameters:
requestedScopes
- The set of requested scopes.accessiblePermissions
- The set of BLC permissions that a user or client can access. Typically, these come from the authorities on the session token.- Returns:
- The sub-set of the requested scopes that are accessible from the given permissions.
-
filterPermissionsRelevantToScopes
public Set<String> filterPermissionsRelevantToScopes(@Nullable Collection<String> candidatePermissions, Set<String> limitingScopes) Description copied from interface:SecurityService
Returns a sub-set from the givencandidatePermissions
of the permissions that belong to one of the givenlimitingScopes
. This is useful for narrowing down granted authorities to those relevant for requested scopes.- Specified by:
filterPermissionsRelevantToScopes
in interfaceSecurityService
- Parameters:
candidatePermissions
- The permissions to filter from. This is just a collection of Broadleaf permission values.limitingScopes
- The specific scopes to filter the results to.- Returns:
- The permissions which are relevant for the given scopes, or an empty (never-null) set.
-
findOpenRequestedScopes
Deprecated.UsefindOpenScopes(Set)
, which returns a Set instead of a Stream. -
findOpenScopes
-
getRootsFromPermissions
-
filterScopesByPermissions
@Deprecated protected Stream<String> filterScopesByPermissions(Set<String> requestedScopes, Set<String> rootsFromPermissions) Deprecated.UsefilterScopesByPermission(Set, Set)
instead. -
filterScopesByPermission
protected Stream<String> filterScopesByPermission(Set<String> requestedScopes, Set<String> rootsFromPermissions) Deprecated.This incorrectly requires that all scopes/perms are 1-1 and ignores the permission root flag. UsefilterScopesByPermission(Set, Set, Set)
which correctly accounts for scopes that aren't related to permission roots. -
filterScopesByPermission
protected Set<String> filterScopesByPermission(Set<String> requestedScopes, Set<String> permissionRoots, Set<String> accessiblePermissions) Filters scopes based on supplied permissions. This will return any scopes that the user has permissions for.- Parameters:
requestedScopes
- The requested scopespermissionRoots
- The permission roots, determined fromaccessiblePermissions
- The permissions the user has.- Returns:
- A filtered list of scopes.
-
findAllPermissionsForScopes
-
filterRelevantPermissions
-
permissionToRoot
-
getPermissionRepository
-
getScopeRepository
-