开发者

how to restrict user from accessing a perticular action of a controller?

HI. I have two user's for my app.one is admin n other visitors..i have two actions in my controller.i admin can act on both but i want visitors to be restricted from accessing 2nd action.how to achieve it?

Waiting for answer with adva开发者_StackOverflownce thanks,


The spring security plugin is the way to go. http://grails.org/plugin/spring-security-core

I would recommend using the annotation approach. There is a section on using annotations in the blog post http://blog.springsource.com/2010/08/11/simplified-spring-security-with-grails/

I would recommend reading the above blog post in its entirety

E.g. Controller action would be secured like....

//all users
@Secured(['IS_AUTHENTICATED_REMEMBERED'])
def firstAction = { ... }

//only admin
@Secured(['ROLE_ADMIN'])
def secondAction = { ... }

The plugin also offers a "remember me" option if you dont want to force your users to always login


I suggest to use the controllers interceptors http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.1 Controllers

or install the Spring Security Core plugin http://www.grails.org/plugin/spring-security-core.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜