From 18e0f227578b122e98c0b2f0c27996bb0479dcb7 Mon Sep 17 00:00:00 2001 From: Michael Yan Date: Thu, 30 May 2024 10:39:46 +0800 Subject: [PATCH] Update README --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 6ed257e..25529ea 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,48 @@ dependencies { } ``` + +### Creating a Policy + +In `app/controllers`, + +```groovy +class PostController { + + def show(Long id) { + def post = postService.get(id) + authorize post + // some + } + +} +``` + +In `app/policies`, create a `Policy` for `PostController`, + +```groovy +class PostPolicy { + + def show() { + record.status == 'PUBLISHED' || record.author.id == user.id || user.hasRole('ROLE_ADMIN') + } + +} +``` + +`policy` plugin provides `authorize(record, options)` for your `Controllers`, + +```groovy +// Without record (null) +authorize() + +// With post, use PostPolicy, actionName is the rule +authorize(post) + +// Use custom Policy and rule +authorize(post, [with: NewPostPolicy, to: 'manage']) +``` + ## Development ### Build from source @@ -38,6 +80,11 @@ cd grace-policy * Grace 2022.0.0+ * Grails 3.0+ +## Roadmap + +* Spring Security integration +* Support Grails Service + ## License This plugin is available as open source under the terms of the [APACHE LICENSE, VERSION 2.0](http://apache.org/Licenses/LICENSE-2.0)