public async Task <string> Execute(ShareResourceParameter shareResourceParameter) { if (shareResourceParameter == null) { throw new ArgumentNullException(nameof(shareResourceParameter)); } if (string.IsNullOrWhiteSpace(shareResourceParameter.ResourceId)) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheResourceIdMustBeSpecified); } if (shareResourceParameter.Scopes == null) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheScopesMustBeSpecified); } var resource = await _resourceSetRepository.Get(shareResourceParameter.ResourceId).ConfigureAwait(false); if (resource == null) { throw new UmaResourceNotFoundException(); } if (!shareResourceParameter.Scopes.All(s => resource.Scopes.Contains(s))) { throw new BaseUmaException(Errors.ErrorCodes.InvalidRequestCode, Errors.ErrorDescriptions.TheScopeAreNotValid); } if (resource.Owner != shareResourceParameter.Owner) { throw new UmaNotAuthorizedException(); } var sharedLink = new SharedLink { ConfirmationCode = Guid.NewGuid().ToString(), ResourceId = resource.Id, Scopes = shareResourceParameter.Scopes }; if (!await _sharedLinkRepository.Insert(sharedLink)) { throw new BaseUmaException(Errors.ErrorCodes.InternalError, Errors.ErrorDescriptions.TheSharedLinkCannotBeInserted); } return(sharedLink.ConfirmationCode); }
public Task <string> ShareResource(ShareResourceParameter shareResourceParameter) { return(_shareResourceAction.Execute(shareResourceParameter)); }