public class DefaultPrivilegeService extends Object implements PrivilegeService
Modifier and Type | Class and Description |
---|---|
static class |
DefaultPrivilegeService.PrivilegeHydrationResult
An intermediary data structure used internally by
PrivilegeService to hold all the
restrictions, flat permissions, restricted roles, and restricted permissions of a user entity and permissions from a server entity to prevent
querying the data multiple times. |
Constructor and Description |
---|
DefaultPrivilegeService(UserRoleService<UserRole> userRoleService,
UserRoleAncestryHydrationService roleAncestryHydrationService,
AuthorizationServerService<AuthorizationServer> serverService) |
Modifier and Type | Method and Description |
---|---|
protected void |
addRestrictionByExpandedPermissionNames(@NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName,
@NonNull Restriction restriction,
@NonNull String permissionName)
Add both ALL_* permissions and expanded CRUD_* permissions with the given restriction to the
map.
|
protected Set<String> |
getAllAuthorities(@NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
Gets all the authorities from the flat permissions, permissions from restricted roles, and
permissions from restricted permissions.
|
protected Set<UserPermissionRef> |
getAllFlatPermissions(@NonNull Collection<UserRole> roles)
Gets a set of all
UserRole.getPermissions() from the given roles |
protected Set<UserPermissionRef> |
getAllFlatPermissions(@NonNull User user,
@NonNull AuthorizationServer server,
@NonNull Collection<UserRole> userAndServerRolesWithAncestors)
Gets a set of all flat permissions from
User.getPermissions() ,
AuthorizationServer.getDefaultUserPermissions() , and permissions from the given
roles. |
protected DefaultPrivilegeService.PrivilegeHydrationResult |
getHydratedPrivileges(@NonNull User user,
@NonNull String serverId) |
protected Map<String,Set<String>> |
getMergedRestrictionTargetsByRestrictionType(@NonNull Map<String,Set<String>> restrictionTargetsByRestrictionType1,
@NonNull Map<String,Set<String>> restrictionTargetsByRestrictionType2)
Gets a Map that is a combination of the two given restrictions maps.
|
protected Map<String,Map<String,Set<String>>> |
getMergedRestrictionTypeAndTargetsByPermissionName(@NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName1,
@NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName2)
Gets a Map that is a combination of the two given restrictionTypeAndTargetsByPermissionName
maps.
|
protected Set<UserPermissionRef> |
getPermissionsFromRestrictedPrivileges(@NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
Gets all the permissions from restricted roles and their ancestors, and restricted
permissions.
|
Map<String,Set<String>> |
getRestrictionTargetsByRestrictionType(@NonNull Set<Restriction> restrictions)
Converts the Set of
Restriction to a Map with the structure of: {restrictionType:
[restrictionTargets]}. |
protected Map<String,Map<String,Set<String>>> |
getRestrictionTypeAndTargetsByPermissionName(@NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
Gets a consolidated map of restricted permissions with the combination of flat permissions
and restrictions, restricted roles, and restricted permissions from a
User . |
protected Map<String,Map<String,Set<String>>> |
getRestrictionTypeAndTargetsByPermissionName(@NonNull Set<UserPermissionRef> flatPermissions,
@NonNull Set<Restriction> restrictions)
Maps each
UserPermissionRef with all of Restriction . |
protected Map<String,Map<String,Set<String>>> |
getRestrictionTypeAndTargetsByPermissionNameForRestrictedPermissions(@NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
Converts the Set of
RestrictedPermission to a Map with the structure of: {
permissionName: { restrictionType: [restrictionTargets] } }. |
protected Map<String,Map<String,Set<String>>> |
getRestrictionTypeAndTargetsByPermissionNameForRestrictedRoles(@NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
|
protected UserRoleAncestryHydrationService |
getRoleAncestryHydrationService() |
protected Map<String,Collection<UserRole>> |
getRoleWithAncestorsByRoleId(@NonNull Set<String> roleIds)
Gets roles along with their ancestry roles mapped by given role id.
|
protected AuthorizationServerService<AuthorizationServer> |
getServerService() |
PrivilegeSummary |
getUserPrivilegeSummary(@NonNull User user,
@NonNull String serverId)
Gets a
PrivilegeSummary of user's consolidated authorities, restrictions, and
restricted authorities. |
protected UserRoleService<UserRole> |
getUserRoleService() |
public DefaultPrivilegeService(UserRoleService<UserRole> userRoleService, UserRoleAncestryHydrationService roleAncestryHydrationService, AuthorizationServerService<AuthorizationServer> serverService)
public PrivilegeSummary getUserPrivilegeSummary(@NonNull @NonNull User user, @NonNull @NonNull String serverId)
PrivilegeService
PrivilegeSummary
of user's consolidated authorities, restrictions, and
restricted authorities.getUserPrivilegeSummary
in interface PrivilegeService
user
- User
to get the PrivilegeSummary
forserverId
- id of the AuthorizationServer
PrivilegeSummary
of user's authorities, restrictions, and restricted
authoritiesPrivilegeSummary
protected DefaultPrivilegeService.PrivilegeHydrationResult getHydratedPrivileges(@NonNull @NonNull User user, @NonNull @NonNull String serverId)
protected Set<String> getAllAuthorities(@NonNull @NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
The expanded CRUD_* permissions from ALL_* permissions are also added into the authorities (on top of the ALL_* permissions).
privilegeHydrationResult
- DefaultPrivilegeService.PrivilegeHydrationResult
to get all the authorities
fromprotected Set<UserPermissionRef> getPermissionsFromRestrictedPrivileges(@NonNull @NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
privilegeHydrationResult
- DefaultPrivilegeService.PrivilegeHydrationResult
to get all the permissions
from restricted privilegesprotected Map<String,Map<String,Set<String>>> getRestrictionTypeAndTargetsByPermissionName(@NonNull @NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
User
. This also
includes the flat permissions from AuthorizationServer.getDefaultUserPermissions()
and those inherited from AuthorizationServer.getDefaultUserRoles()
and their
ancestors. Flat permissions and restrictions are converted into a map of equivalent
restricted permissions. Similarly, restricted roles are also converted into equivalent
restricted permissions.
For example, if an entity has READ_PRODUCT as flat permission (that came either from its direct flat permissions or from a flat role) with a flat vendor restriction on vendorA, it is then converted into a restricted permission as such: {READ_PRODUCT: {VENDOR: [vendorA]}}.
Likewise, if an entity has a role that has READ_PRODUCT permission assigned, and has the role added as restricted role on vendorA, it is then converted into a restricted permission as well: {READ_PRODUCT: {VENDOR: [vendorA]}}.
privilegeHydrationResult
- DefaultPrivilegeService.PrivilegeHydrationResult
to consolidate the
permissions, restrictions, restricted roles, and restricted permissions for a userUser
, along with flat
permissions from the AuthorizationServer
protected Map<String,Map<String,Set<String>>> getRestrictionTypeAndTargetsByPermissionName(@NonNull @NonNull Set<UserPermissionRef> flatPermissions, @NonNull @NonNull Set<Restriction> restrictions)
UserPermissionRef
with all of Restriction
. Doing this to convert
flat permissions and restrictions into the map structure of restricted permissions, which
helps the restricted authorities consolidation.
However, when there's no flat permissions, the restrictions are not added.
Note: The expanded CRUD_* permissions from ALL_* permissions are also added into the map (on top of the ALL_* permissions).
flatPermissions
- Set
of UserPermissionRef
restrictions
- Set
of Restriction
protected Map<String,Collection<UserRole>> getRoleWithAncestorsByRoleId(@NonNull @NonNull Set<String> roleIds)
roleIds
- role ids to get the roles and ancestry roles forprotected Set<UserPermissionRef> getAllFlatPermissions(@NonNull @NonNull User user, @NonNull @NonNull AuthorizationServer server, @NonNull @NonNull Collection<UserRole> userAndServerRolesWithAncestors)
User.getPermissions()
,
AuthorizationServer.getDefaultUserPermissions()
, and permissions from the given
roles.user
- User
to get the permissions forserver
- AuthorizationServer
to get the permissions foruserAndServerRolesWithAncestors
- Collection
of roles to get all the permissions
from. This is typically a collection of user's and server's roles along with their
ancestors to prevent the need of querying all ancestry roles every timeprotected Set<UserPermissionRef> getAllFlatPermissions(@NonNull @NonNull Collection<UserRole> roles)
UserRole.getPermissions()
from the given rolesroles
- Collection
of roles to get all the permissions fromprotected Map<String,Map<String,Set<String>>> getRestrictionTypeAndTargetsByPermissionNameForRestrictedRoles(@NonNull @NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
UserPermissionRef
from the RestrictedRole
with the corresponding
restriction
. Doing this to convert permissions
assigned to the restricted role and restricted role restrictions into the map structure of
restricted permissions, which helps the comparisons of restrictiveness.
The expanded CRUD_* permissions from ALL_* permissions are also added into the map with the same restrictions (on top of the ALL_* permissions).
privilegeHydrationResult
- DefaultPrivilegeService.PrivilegeHydrationResult
to get restricted roles fromprotected Map<String,Map<String,Set<String>>> getRestrictionTypeAndTargetsByPermissionNameForRestrictedPermissions(@NonNull @NonNull DefaultPrivilegeService.PrivilegeHydrationResult privilegeHydrationResult)
RestrictedPermission
to a Map with the structure of: {
permissionName: { restrictionType: [restrictionTargets] } }.
The expanded CRUD_* permissions from ALL_* permissions are also added into the map with the same restrictions (on top of the ALL_* permissions).
privilegeHydrationResult
- DefaultPrivilegeService.PrivilegeHydrationResult
to get restricted
permissions fromMap
protected Map<String,Map<String,Set<String>>> getMergedRestrictionTypeAndTargetsByPermissionName(@NonNull @NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName1, @NonNull @NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName2)
protected Map<String,Set<String>> getMergedRestrictionTargetsByRestrictionType(@NonNull @NonNull Map<String,Set<String>> restrictionTargetsByRestrictionType1, @NonNull @NonNull Map<String,Set<String>> restrictionTargetsByRestrictionType2)
public Map<String,Set<String>> getRestrictionTargetsByRestrictionType(@NonNull @NonNull Set<Restriction> restrictions)
PrivilegeService
Restriction
to a Map with the structure of: {restrictionType:
[restrictionTargets]}.getRestrictionTargetsByRestrictionType
in interface PrivilegeService
restrictions
- Set
of Restriction
protected void addRestrictionByExpandedPermissionNames(@NonNull @NonNull Map<String,Map<String,Set<String>>> restrictionTypeAndTargetsByPermissionName, @NonNull @NonNull Restriction restriction, @NonNull @NonNull String permissionName)
restrictionTypeAndTargetsByPermissionName
- the
restrictionTypeAndTargetsByPermissionName map to add the permission names with
restriction torestriction
- restriction to be added with the given permission namepermissionName
- permission name to add along with the given restrictionprotected UserRoleService<UserRole> getUserRoleService()
protected UserRoleAncestryHydrationService getRoleAncestryHydrationService()
protected AuthorizationServerService<AuthorizationServer> getServerService()
Copyright © 2021. All rights reserved.