Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Commit

Permalink
#3, feature: Initial version of security template
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaschmidt committed Mar 5, 2016
1 parent 8dd6e60 commit 673a890
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package {{main_package}}

import play.api.mvc._
import Security.AuthenticatedBuilder
{{for import in imports}}
import {{import.name}}
{{/for}}

{{for controller in controllers}}

trait {{controller.security}} {
{{for m in controller.methods}}
{{if m.needs_security}}
val {{m.secure_checks}} = Seq({{for security_check in m.security_checks}}{{security_check.name}} _{{if security_check.isNotLast}}, {{/if}}{{/for}})

object {{m.secure_checks}} extends AuthenticatedBuilder(
req => {
val individualChecks = {{m.secure_checks}}.map(_.apply(req))
individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten))
},
onUnauthorized({{m.secure_content}})
)
{{/if}}
{{/for}}

private def onUnauthorized(content: AnyContent): RequestHeader => Result = _ => Results.Unauthorized(content)
}
{{/for}}

0 comments on commit 673a890

Please sign in to comment.