grails - spring-security-shiro org.apache.shiro.authc.AccountException:未登录或匿名

标签 grails shiro grails3

我正在将我的应用程序从grails 2.4.4迁移到grails 3.2.9。

我正在尝试迁移到

compile 'org.grails.plugins:spring-security-shiro:3.0.1' 

当我尝试与用户登录时,出现以下错误:
   org.apache.shiro.authc.AccountException: Not logged in or anonymous
            at grails.plugin.springsecurity.shiro.SpringSecurityRealm.getCurrentUser(SpringSecurityRealm.groovy:76)
            at grails.plugin.springsecurity.shiro.SpringSecurityRealm.doGetAuthenticationInfo(SpringSecurityRealm.groovy:95)
            at org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:568)
            at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:180)
            at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:267)
            at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
            at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
            at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
            at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
            at org.apache.shiro.subject.Subject$login.call(Unknown Source)

在我的申请规则中,我有:
[pattern: '/login/auth/**',      access: ['permitAll']],

在grails 2.4.4中,我将能够调试dbRealm.groovy文件,但是我不能使用新插件来调试。

我知道用户未登录,因为这是我要尝试的操作,但是为什么它会认为我的用户是匿名用户?

最佳答案

基于https://grails-plugins.github.io/grails-spring-security-shiro/v3/index.html#permissions

This will transitively install the Spring Security Core plugin, so you’ll need to configure that by running the s2-quickstart script.



所以看着https://grails-plugins.github.io/grails-spring-security-core/
https://grails-plugins.github.io/grails-spring-security-core/3.1.x/index.html(因为您使用的是Grails 3.2.x)

3.5. Anonymous authentication

In standard Spring Security and older versions of the plugin, there is support for an “anonymous” authentication. This is implemented by a filter that registers a simple Authentication in the SecurityContext to remove the need for null checks, since there will always be an Authentication available. This approach is still problematic though because the Principal of the anonymous authentication is a String, whereas it is a UserDetails instance when there is a non-anonymous authentication.

Since you still have to be careful to differentiate between anonymous and non-anonymous authentications, the plugin now creates an anonymous Authentication which will be an instance of grails.plugin.springsecurity.authentication.GrailsAnonymousAuthenticationToken with a standard org.springframework.security.core.userdetails.User instance as its Principal. The authentication will have a single granted role, ROLE_ANONYMOUS.





5.2. URLs and Authorities

In each approach you configure a mapping for a URL pattern to the role(s) that are required to access those URLs, for example, /admin/user/** requires ROLE_ADMIN. In addition, you can combine the role(s) with SpEL expressions and/or tokens such as IS_AUTHENTICATED_ANONYMOUSLY, IS_AUTHENTICATED_REMEMBERED, and IS_AUTHENTICATED_FULLY. One or more voters (Voters) will process any tokens and enforce a rule based on them:

IS_AUTHENTICATED_ANONYMOUSLY

    signifies that anyone can access this URL. By default the AnonymousAuthenticationFilter ensures an “anonymous” Authentication

with no roles so that every user has an authentication. The token accepts any authentication, even anonymous.

    The SpEL expression permitAll is equivalent to IS_AUTHENTICATED_ANONYMOUSLY and is typically more intuitive to use

关于grails - spring-security-shiro org.apache.shiro.authc.AccountException:未登录或匿名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48119257/

相关文章:

grails - 如何测试 grails Web 服务的 URL 映射

grails - 具有1:N关系的Grails GORM MissingMethodException

firefox - Geb Firefox 驱动程序 : why my test runs twice?

java - 如何在使用 Shiro 时在 OSGI E4 环境中加载类?

java - Apache shiro LDAP 多个 OU

grails3 - 遇到错误,Spring BeanCreationException:创建名称为'validateableConstraintsEvaluator'的bean时出错

gradle - Grails 3-Angular模板 Assets 管道不将转换后的js文件捆绑到application.js中

grails - 使用OS环境中的用户名和密码配置grails数据源

database - Apache Shiro 中每个用户的不同权限?

grails - 如何获得grails f:table工作(3.3.8)