Skip to content

Instantly share code, notes, and snippets.

@mczachurski
Last active March 4, 2018 08:15
Show Gist options
  • Save mczachurski/41c2c5ab82ced8b93deb56710d2664d2 to your computer and use it in GitHub Desktop.
Save mczachurski/41c2c5ab82ced8b93deb56710d2664d2 to your computer and use it in GitHub Desktop.
import Foundation
public class TaskAuthorizationHandler : AuthorizationHandlerProtocol {
public var requirementType: AuthorizationRequirementProtocol.Type = SameAuthorRequirement.self
public var resourceType: EntityProtocol.Type = Task.self
public func handle(user: UserCredentials,
resource: EntityProtocol,
requirement: AuthorizationRequirementProtocol) throws -> Bool {
guard let task = resource as? Task else {
throw AuthorizationTypeMismatchError()
}
if task.userId == user.id {
return true
}
return false
}
public required init() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment