Skip to content

Instantly share code, notes, and snippets.

@balteravishay
Last active November 7, 2021 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balteravishay/93c7d7e3e4b212d0a837d7bac8d63760 to your computer and use it in GitHub Desktop.
Save balteravishay/93c7d7e3e4b212d0a837d7bac8d63760 to your computer and use it in GitHub Desktop.
Owner Access
namespace PMVProxy.API.Middleware
{
using Hl7.Fhir.Model;
...
internal class OwnerAccess : IAccessByRole
{
...
public async System.Threading.Tasks.Task Access<TResource>(TResource resource,
string userFhirId, IFhirService fhirService) where TResource : Resource
{
var resourceSubject = GetResourceSubjectProperty(resource);
if (String.IsNullOrEmpty(resourceSubject))
{
_logger.LogWarning($"resource does not have a subject");
throw new UnprocessableInputException($"resource does not have a subject");
}
if (resourceSubject.ToString().Equals(userFhirId, System.StringComparison.OrdinalIgnoreCase))
{
_logger.LogInformation($"user {userFhirId} is the subject of resource {resource.Id}");
return;
}
else
{
_logger.LogWarning($"user {userFhirId} does not have access to {resource.Id}");
throw new AuthorizationException("you do not have access to this resource");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment