Spring Security Core Plugin 三(配置Request Mappings)

方式一: @Secure

方式二: application.groovy

方式三: Requestmap 保存在数据库中.

悲观锁定

默认rejectNoRule = true,

那么所以没有配置的URL用户都不可访问

另外一个配置是fii.rejectPublicInvocations, 如果rejectNoRule是false,那么前者为true时,没有配置的URL访问会抛出IlleaglArgumentException,并显示error page.

在rejectNoRule=true或fii.rejectPublicInvocations=true时,可以使用下面配置.

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
   [pattern: '/',               access: ['permitAll']],
   [pattern: '/error',          access: ['permitAll']],
   [pattern: '/index',          access: ['permitAll']],
   [pattern: '/index.gsp',      access: ['permitAll']],
   [pattern: '/shutdown',       access: ['permitAll']],
   [pattern: '/assets/**',      access: ['permitAll']],
   [pattern: '/**/js/**',       access: ['permitAll']],
   [pattern: '/**/css/**',      access: ['permitAll']],
   [pattern: '/**/images/**',   access: ['permitAll']],
   [pattern: '/**/favicon.ico', access: ['permitAll']],

   [pattern: '/user/**',        access: 'ROLE_USER'],
   [pattern: '/admin/**',       access: ['ROLE_ADMIN', 'isFullyAuthenticated()']],
   [pattern: '/thing/register', access: 'isAuthenticated()', httpMethod: 'PUT']
]

URLs 和Authorities

(1)IS_AUTHENTICATED_ANONYMOUSLY

SpEL表达式permitAll同等于它

(2)IS_AUTHENTICATED_REMEMBERED

SpEL表达式isAuthenticated()或isRemeberMe()等同于它

(3)IS_AUTHENTICATED_FULLY

SpEL表达式isFullyAuthenticated()等同于它

在Requestmap和application.groovy的方法中,URLS必须是小写.

Static Map

需要指定

grails.plugin.springsecurity.securityConfigType = "InterceptUrlMap"

然后在application.groovy中定义一个map

grails.plugin.springsecurity.interceptUrlMap = [
   ...
   [pattern: '/secure/**',  access: ['ROLE_ADMIN']],
   [pattern: '/finance/**', access: ['ROLE_FINANCE', 'isFullyAuthenticated()']]
]
Traditional ConfigExpression

ROLE_ADMIN

hasRole('ROLE_ADMIN')

ROLE_USER,ROLE_ADMIN

hasAnyRole('ROLE_USER','ROLE_ADMIN')

ROLE_ADMIN,IS_AUTHENTICATED_FULLY

hasRole('ROLE_ADMIN') and isFullyAuthenticated()

IS_AUTHENTICATED_ANONYMOUSLY

permitAll

IS_AUTHENTICATED_REMEMBERED

isAuthenticated() or isRememberMe()

IS_AUTHENTICATED_FULLY

isFullyAuthenticated()

 

 

最后欢迎大家访问我的个人网站:1024s​​​​​​​

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值