public class ContentRestrictionServiceImpl extends Object implements ContentRestrictionService
| Modifier and Type | Class and Description |
|---|---|
static class |
ContentRestrictionServiceImpl.MergeMode
Defines how pre-existing and passed
ContentRestrictions are getting merged during mutative operations |
ContentRestrictionService.ValidatorDEFAULT_BY_OPERATION_EXPANSIONS, DEFAULT_FOR_OPERATION_AND_CONTENT_EXPANSIONS, DEFAULT_FOR_OPERATION_EXPANSIONS| Constructor and Description |
|---|
ContentRestrictionServiceImpl(ContentEntityManagerInternal contentEntityManager,
ContentPermissionManager contentPermissionManager,
ContentRestrictionFactory contentRestrictionFactory,
UserAccessorInternal userAccessor,
NavigationService navigationService,
ContentRestrictionService.Validator contentRestrictionServiceValidator) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDirectRestrictionForSubject(ContentId contentId,
OperationKey operationKey,
Subject subject)
Adds singular direct
ContentRestriction for operationKey and subject to the content identified by contentId parameter. |
ContentRestrictionsPageResponse |
addRestrictions(ContentId target,
Collection<? extends ContentRestriction> contentRestrictions,
Expansion... expansions)
Attempts to add all the restrictions specified to a piece of content identified by
contentId. |
ContentRestrictionsPageResponse |
deleteAllDirectRestrictions(ContentId target,
Expansion... expansions)
Attempts to delete all the restrictions specified directly on a piece of content identified by
contentId. |
void |
deleteDirectRestrictionForSubject(ContentId contentId,
OperationKey operationKey,
Subject subject)
Deletes singular direct
ContentRestriction for operationKey and subject from the content identified by contentId parameter. |
protected @NonNull Map<String,Collection<ContentPermission>> |
getMergedContentPermissions(@NonNull ContentEntityObject ceo,
@NonNull Collection<? extends ContentRestriction> givenContentRestrictions,
@NonNull ContentRestrictionServiceImpl.MergeMode mergeMode)
Builds a Map of
ContentPermissions mapped to their PermissionType from givenContentRestrictions provided and the ones already existing on ContentEntityObject |
protected @NonNull Optional<ContentPermission> |
getPreExistingContentPermissionForGroup(@Nullable ContentEntityObject ceo,
@Nullable String permissionType,
@Nullable Group group)
Gets pre-existing
ContentPermission (singular, optional) for the Group and OperationKey (as String permissionType) specified. |
protected @NonNull Optional<ContentPermission> |
getPreExistingContentPermissionForSubject(@Nullable ContentEntityObject ceo,
@Nullable String permissionType,
@Nullable Subject subject)
Gets pre-existing
ContentPermission (singular, optional) for the Subject and OperationKey (as String permissionType) specified. |
protected @NonNull Optional<ContentPermission> |
getPreExistingContentPermissionForUser(@Nullable ContentEntityObject ceo,
@Nullable String permissionType,
@NonNull User user)
Gets pre-existing
ContentPermission (singular, optional) for the User and OperationKey (as String permissionType) specified. |
protected @NonNull Set<ContentPermission> |
getPreExistingContentPermissions(@Nullable ContentEntityObject ceo,
@Nullable String permissionType)
Gets Set of all the distinct
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed. |
protected @NonNull Set<ContentPermission> |
getPreExistingContentPermissions(@Nullable ContentEntityObject ceo,
@Nullable String permissionType,
@Nullable Predicate<ContentPermission> filterBy)
Gets Set of all the distinct
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed. |
protected @NonNull Set<ContentPermission> |
getPreExistingContentPermissionsForSubjectType(@Nullable ContentEntityObject ceo,
@Nullable String permissionType,
@Nullable SubjectType subjectType)
Gets pre-existing
ContentPermissions (plural) for the SubjectType and OperationKey (as String permissionType) specified. |
ContentRestrictionsPageResponse |
getRestrictions(ContentId target,
PageRequest pageRequest,
Expansion... allExpansions)
Retrieves all the restrictions for all the operations on a given Content.
|
ContentRestriction |
getRestrictionsForOperation(ContentId target,
OperationKey operationKey,
PageRequest pageRequest,
Expansion... allExpansions)
Retrieves all restrictions for given operation key on given content.
|
Map<OperationKey,ContentRestriction> |
getRestrictionsGroupByOperation(ContentId target,
Expansion... allExpansions)
List all restrictions that exist directly on the given content.
|
boolean |
hasDirectRestrictionForSubject(ContentId contentId,
OperationKey operationKey,
Subject subject)
Returns
true if the User or Group specified by the subject parameter has restriction(s) for the operationKey operation
which are specified directly on the Content identified by contentId parameter. |
protected @NonNull NotImplementedServiceException |
throwableUnsupportedSubjectType(@Nullable Object something)
Returns throwable to indicate that certain
SubjectType is not supported for ContentRestrictions operations. |
ContentRestrictionsPageResponse |
updateRestrictions(ContentId target,
Collection<? extends ContentRestriction> contentRestrictions,
Expansion... expansions)
Sets all the restrictions specified to a piece of content identified by
contentId, replacing any existing permissions. |
protected @NonNull ValidationResult |
validateSelfAccessRetained(@NonNull Map<String,Collection<ContentPermission>> contentPermissionByPermissionTypeMap)
Validates that currently logged in user will have direct specific ContentPermission specified for self
in case when provided
contentPermissionByPermissionTypeMap will become the actual ContentPermissions. |
ContentRestrictionService.Validator |
validator() |
public ContentRestrictionServiceImpl(ContentEntityManagerInternal contentEntityManager, ContentPermissionManager contentPermissionManager, ContentRestrictionFactory contentRestrictionFactory, UserAccessorInternal userAccessor, NavigationService navigationService, ContentRestrictionService.Validator contentRestrictionServiceValidator)
public ContentRestrictionService.Validator validator()
validator in interface ContentRestrictionServiceContentRestrictionService.Validatorpublic Map<OperationKey,ContentRestriction> getRestrictionsGroupByOperation(ContentId target, Expansion... allExpansions) throws ServiceException
ContentRestrictionServiceContentRestrictionService.getRestrictionsForOperation(com.atlassian.confluence.api.model.content.id.ContentId, com.atlassian.confluence.api.model.permissions.OperationKey, com.atlassian.confluence.api.model.pagination.PageRequest, com.atlassian.confluence.api.model.Expansion...) method.getRestrictionsGroupByOperation in interface ContentRestrictionServicetarget - the id of the content to look up permissions forallExpansions - the expansions to apply to the returned data. These expansions start from the operation itself.NotFoundException - if given content id does not exist, or is not viewable by userServiceExceptionpublic ContentRestriction getRestrictionsForOperation(ContentId target, OperationKey operationKey, PageRequest pageRequest, Expansion... allExpansions) throws ServiceException
ContentRestrictionServicegetRestrictionsForOperation in interface ContentRestrictionServicetarget - the id of the content to look up permissions foroperationKey - the operation key to look up restrictions forpageRequest - pagination through the subjects contained within the ContentRestrictionallExpansions - the expansions to the ContentRestriction.NotFoundException - if given content id does not exist, or is not viewable by user, or if the given operation key is not recognised for the content.ServiceExceptionpublic ContentRestrictionsPageResponse getRestrictions(ContentId target, PageRequest pageRequest, Expansion... allExpansions) throws ServiceException
ContentRestrictionServicegetRestrictions in interface ContentRestrictionServicetarget - the id of the content to look up permissions forpageRequest - pagination through the list of all the ContentRestrictions returnedallExpansions - the expansions to the ContentRestrictionNotFoundException - if given content id does not exist, or is not viewable by userServiceExceptionpublic ContentRestrictionsPageResponse updateRestrictions(ContentId target, Collection<? extends ContentRestriction> contentRestrictions, Expansion... expansions) throws ServiceException
ContentRestrictionServicecontentId, replacing any existing permissions.
Setting per-content restrictions is currently allowed for Pages or BlogPosts only.
Rules of applying restrictions via this method:
ContentRestrictions is allowed to have only 1 (ONE) ContentRestriction object for each operation.updateRestrictions in interface ContentRestrictionServicetarget - the id of the content to assign restrictions tocontentRestrictions - Collection of ContentRestrictions to apply to the Content specifiedexpansions - the expansions to the ContentRestriction. To be expanded on response.ContentRestrictionsPageResponse describing the new state of the content identified by contentId (same as ContentRestrictionService.getRestrictions(ContentId, PageRequest, Expansion...) would return)ServiceException - or one of it subtypes.NotFoundException - in case there's no Content with ID provided or user does not have enough rights to view itPermissionException - in case user is not allowed to alter restrictions on the content specifiedBadRequestException - in case when data supplied is not enough/corrupt, etc... many reasons. Exception generally would have message which explains what's wrong.public ContentRestrictionsPageResponse addRestrictions(ContentId target, Collection<? extends ContentRestriction> contentRestrictions, Expansion... expansions) throws ServiceException
ContentRestrictionServicecontentId.
Does not replace/remove/alter any pre-existing ContentRestrictions.
Provided ContentRestrictions will be added, i.e. "merged with" any pre-existing restrictions on the Content under the corresponding operations.
Changing per-content restrictions is currently allowed for Pages or BlogPosts only.
Rules of applying restrictions via this method:
ContentRestrictions is allowed to have only 1 (ONE) ContentRestriction object for each operation.addRestrictions in interface ContentRestrictionServicetarget - the id of the content to add restrictions tocontentRestrictions - Collection of ContentRestrictions to apply to the Content specifiedexpansions - the expansions to the ContentRestriction. To be expanded on response.ContentRestrictionsPageResponse describing the new state of the content identified by contentId (same as ContentRestrictionService.getRestrictions(ContentId, PageRequest, Expansion...) would return)ServiceException - or one of it subtypes.NotFoundException - in case there's no Content with ID provided or user does not have enough rights to view itPermissionException - in case user is not allowed to alter restrictions on the content specifiedBadRequestException - in case when data supplied is not enough/corrupt, etc... many reasons. Exception generally would have message which explains what's wrong.public ContentRestrictionsPageResponse deleteAllDirectRestrictions(ContentId target, Expansion... expansions) throws ServiceException
ContentRestrictionServicecontentId.
"specified directly" means that deleting restrictions on some content won't affect any restrictions inherited from its parents.
Changing per-content restrictions is currently allowed for Pages, Blog Posts and other add-on provided Content Types that support direct content restrictions.deleteAllDirectRestrictions in interface ContentRestrictionServicetarget - the id of the content to remove all directly specified restrictions fromexpansions - the expansions to the ContentRestriction. To be expanded on response.ContentRestrictionsPageResponse describing the new state of the content identified by contentId (same as ContentRestrictionService.getRestrictions(ContentId, PageRequest, Expansion...) would return)ServiceException - or one of it subtypes.NotFoundException - in case there's no Content with ID provided or user does not have enough rights to view itPermissionException - in case user is not allowed to alter restrictions on the content specifiedpublic boolean hasDirectRestrictionForSubject(ContentId contentId, OperationKey operationKey, Subject subject) throws ServiceException
ContentRestrictionServicetrue if the User or Group specified by the subject parameter has restriction(s) for the operationKey operation
which are specified directly on the Content identified by contentId parameter.
Returns false otherwise.
Can throw BadRequestException or PermissionException and other various subtypes of ServiceException in case of bad IDs, parameters, permission problems, etc.
hasDirectRestrictionForSubject in interface ContentRestrictionServicecontentId - the id of the content which the check will be performed onoperationKey - the operation key to check restrictions againstsubject - either User or Group who's restriction is in questiontrue or false depending on whether user/group specified have any direct restrictions on a content specifiedServiceException - or one of it subtypes.NotFoundException - in case there's no Content with ID provided or user does not have enough rights to view itpublic void deleteDirectRestrictionForSubject(ContentId contentId, OperationKey operationKey, Subject subject) throws ServiceException
ContentRestrictionServiceContentRestriction for operationKey and subject from the content identified by contentId parameter.
Throws subclasses of ServiceException in case of various problems (cannot find content, restrictions to be deleted does not exist, etc...)deleteDirectRestrictionForSubject in interface ContentRestrictionServicecontentId - the id of the content which the restriction to be removed fromoperationKey - the operation to remove restriction forsubject - either User or Group who's restriction is to be deletedServiceExceptionpublic void addDirectRestrictionForSubject(ContentId contentId, OperationKey operationKey, Subject subject) throws ServiceException
ContentRestrictionServiceContentRestriction for operationKey and subject to the content identified by contentId parameter.
Throws subclasses of ServiceException in case of various problems (cannot find content, wrong operationKey, restricting self, etc...)addDirectRestrictionForSubject in interface ContentRestrictionServicecontentId - the id of the content which the restriction to be added tooperationKey - the operation to remove restriction forsubject - either User or Group who's restriction is to be addedServiceExceptionprotected @NonNull Map<String,Collection<ContentPermission>> getMergedContentPermissions(@NonNull ContentEntityObject ceo, @NonNull Collection<? extends ContentRestriction> givenContentRestrictions, @NonNull ContentRestrictionServiceImpl.MergeMode mergeMode)
ContentPermissions mapped to their PermissionType from givenContentRestrictions provided and the ones already existing on ContentEntityObject
Result depends on mergeMode passed.
MergeMode.ADD.equals(mergeMode)==true will try to add all the ContentRestrictions provided to the ones already existing on the ContentEntityObjectMergeMode.REPLACE.equals(mergeMode)==true will try to replace all the ContentRestrictions already existing on the ContentEntityObject with the ones provided (users and groups separately)MergeMode.SUBTRACT.equals(mergeMode)==true will try to subtract all the ContentRestrictions provided from the ones already existing on the ContentEntityObject
In case when MergeMode.REPLACE.equals(mergeMode)==true only those ContentRestrictions will be replaced, for which there's a mapping in the givenContentRestrictions provided.
I.e. if there's no mappings for say "group" in the givenContentRestrictions, it means restrictions for groups will not be affected as the result of calling this method.
ceo - ContentEntityObject to figure out merged ContentPermissions forgivenContentRestrictions - Collection of ContentRestrictions objects containing restrictions which should be merged with existing ones depending on the mergeModemergeMode - ContentRestrictionServiceImpl.MergeMode for applying givenContentRestrictions (one of "ADD", "REPLACE", "SUBTRACT").Map of ContentPermissions mapped by their PermissionTypes representing a MERGE result between what was on ceo before + what's specified by userprotected @NonNull NotImplementedServiceException throwableUnsupportedSubjectType(@Nullable Object something)
SubjectType is not supported for ContentRestrictions operations.something - - whatever were passed as the wrong Subject or SubjectType.NotImplementedServiceException explaining what happened.protected @NonNull Set<ContentPermission> getPreExistingContentPermissions(@Nullable ContentEntityObject ceo, @Nullable String permissionType, @Nullable Predicate<ContentPermission> filterBy)
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed. Results are optionally filtered by the filterBy
Never returns null, returns empty Set in case nothing found or cannot be calculated.
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed, optionally filtered by the predicate provided. Never null.protected @NonNull Set<ContentPermission> getPreExistingContentPermissions(@Nullable ContentEntityObject ceo, @Nullable String permissionType)
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed.
For the filtered options see getPreExistingContentPermissions(ContentEntityObject, String, Predicate)
Never returns null, returns empty Set in case nothing found or cannot be calculated.
ContentPermissions of the specified permissionType
pre-existing on the ContentEntityObject passed. Never null.getPreExistingContentPermissions(ContentEntityObject, String, Predicate)protected @NonNull Set<ContentPermission> getPreExistingContentPermissionsForSubjectType(@Nullable ContentEntityObject ceo, @Nullable String permissionType, @Nullable SubjectType subjectType)
ContentPermissions (plural) for the SubjectType and OperationKey (as String permissionType) specified.protected @NonNull Optional<ContentPermission> getPreExistingContentPermissionForSubject(@Nullable ContentEntityObject ceo, @Nullable String permissionType, @Nullable Subject subject)
ContentPermission (singular, optional) for the Subject and OperationKey (as String permissionType) specified.protected @NonNull Optional<ContentPermission> getPreExistingContentPermissionForUser(@Nullable ContentEntityObject ceo, @Nullable String permissionType, @NonNull User user)
ContentPermission (singular, optional) for the User and OperationKey (as String permissionType) specified.protected @NonNull Optional<ContentPermission> getPreExistingContentPermissionForGroup(@Nullable ContentEntityObject ceo, @Nullable String permissionType, @Nullable Group group)
ContentPermission (singular, optional) for the Group and OperationKey (as String permissionType) specified.protected @NonNull ValidationResult validateSelfAccessRetained(@NonNull Map<String,Collection<ContentPermission>> contentPermissionByPermissionTypeMap)
contentPermissionByPermissionTypeMap will become the actual ContentPermissions.contentPermissionByPermissionTypeMap - Copyright © 2003–2021 Atlassian. All rights reserved.