This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3, feature: Initial version of security template
- Loading branch information
1 parent
8dd6e60
commit 673a890
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
compiler/src/main/resources/play_scala_controller_security.mustache
This file contains 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
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}} |