Last active
March 4, 2018 12:46
-
-
Save mczachurski/5e0091d22a08364c1543b318f7201812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public class TaskOperationAuthorizationHandler : AuthorizationHandlerProtocol { | |
public var requirementType: AuthorizationRequirementProtocol.Type = OperationAuthorizationRequirement.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