在Grails中使用Spring安全性的AccessDeniedException

时间:2014-10-14 16:43:49

标签: spring grails spring-security

对于控制器中的方法,我有以下内容:

  @Secured(['ROLE_ADMIN'])
  def signup ( SignupCommand cmd)

我还在Config-core-sec.groovy中添加了

grails.plugins.springsecurity.controllerAnnotations.staticRules = [
  '/signupApi/**' : ['ROLE_ADMIN']
]
grails.plugins.springsecurity.useBasicAuth = true
grails.plugins.springsecurity.filterChain.chainMap = [
   '/signupApi/**': 'JOINED_FILTERS,-exceptionTranslationFilter,-basicAuthenticationFilter
]

当我发出CURL Post请求来测试我的API时,我在日志中收到了拒绝访问的异常。

CURL:

curl --include \
     --request POST \
     --header "Content-Type: application/json" \
     --header "Accept: application/json" -u "moo@moo.com:12345" \
     --data-binary '{

堆栈跟踪:

[ERROR] 2014-10-14 19:31:28,672 [default] Servlet.service() for servlet [default] in context with path [] threw exception
org.springframework.security.access.AccessDeniedException: Access is denied
    at org.codehaus.groovy.grails.plugins.springsecurity.AuthenticatedVetoableDecisionManager.deny(AuthenticatedVetoableDecisionManager.java:111)
    at org.codehaus.groovy.grails.plugins.springsecurity.AuthenticatedVetoableDecisionManager.checkOtherVoters(AuthenticatedVetoableDecisionManager.java:103)
    at org.codehaus.groovy.grails.plugins.springsecurity.AuthenticatedVetoableDecisionManager.decide(AuthenticatedVetoableDecisionManager.java:44)
    at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:204)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:106)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:112)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    at org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:40)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

我在我的数据库中尝试过用户帐户和密码,我想知道我做错了什么......

更新

我对Config.groovy进行了更改,但没有太大变化。但是,我做了以下更改,似乎已经做了一些事情。

  1. grails.plugins.springsecurity.controllerAnnotations.staticRules删除了条目。
  2. 将chainMap中的修改条目改为:

    grails.plugins.springsecurity.filterChain.chainMap = [ '/signupApi/**': 'JOINED_FILTERS,-exceptionTranslationFilter', '/**': 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter' ]

  3. 从浏览器访问时,我得到一个基本的身份验证登录对话框“需要身份验证... Grails Realm”。

    1. 如果我点击取消或输入错误的密码,我会HTTP Status 401 - Bad credentials
    2. 如果我输入正确的用户名和密码,我会收到HTTP Status 403 - Access is denied
    3. 根据您的评论,我也感觉ROLE正在发生一些事情。

0 个答案:

没有答案