oauth2提供程序未找到当前线程HibernateeException的会话

7lrncoxx  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(242)

我正在groovy grails项目中设置oauth2提供程序。我可以访问url,但我总是得到一个 401 Unauthorized 尝试向发送post请求时出错 /oauth/token 请求如下: http://localhost:8080/test/oauth/token?username=user&password=password&scope=read&grant_type=password&client_id=client-id 我遵循了grails文档来设置oauth提供程序。但是当我尝试执行post请求时,我的控制台中出现了一个错误no Session found for current thread 现在我不知道这是从哪里来的。错误。以下是休眠错误:

XNIO-1 task-3  2021-06-23 11:12:32,715 ERROR c.s.i.StandardInterceptor StandardInterceptor before: No Session found for current thread  org.hibernate.HibernateException: No Session found for current thread
    at org.grails.orm.hibernate.GrailsSessionContext.currentSession(GrailsSessionContext.java:112) ~[grails-datastore-gorm-hibernate5-7.0.4.RELEASE.jar:na]
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:475) ~[hibernate-core-5.4.21.Final.jar:5.4.21.Final]
...

我试过多种不同的过滤链。我已经将链接添加到我的url\u public,但它给了我一个 404 not found 所以我决定不把url_公开,我得到了这些过滤链:

grails.plugin.springsecurity.filterChain.chainMap = [
        [pattern: '/oauth/token',               filters: 'JOINED_FILTERS,-oauth2ProviderFilter,-securityContextPersistenceFilter,-logoutFilter,-authenticationProcessingFilter,-rememberMeAuthenticationFilter,-exceptionTranslationFilter'],
        [pattern: '/securedOAuth2Resources/**', filters: 'JOINED_FILTERS,-securityContextPersistenceFilter,-logoutFilter,-authenticationProcessingFilter,-rememberMeAuthenticationFilter,-oauth2BasicAuthenticationFilter,-exceptionTranslationFilter'],
        [pattern: '/**',                        filters: 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter,-statelessSecurityContextPersistenceFilter,-oauth2ProviderFilter,-clientCredentialsTokenEndpointFilter,-oauth2BasicAuthenticationFilter,-oauth2ExceptionTranslationFilter']
]

以下是我的规则:

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
        [pattern: '/oauth/authorize',           access: "(request.getMethod().equals('GET') or request.getMethod().equals('POST'))"],
        [pattern: '/oauth/token',               access: "request.getMethod().equals('POST')"],
]

此外,我还检查了数据库中是否有oauthclient表以及是否有条目(来自启动oauthclient的bootstrap.groovy文件,如下所示:)

new OAuthClient(
                clientId: 'client-id',
                authorizedGrantTypes: ['refresh_token', 'password', 'client_credentials'],
                authorities: ['ROLE_CLIENT'],
                scopes: ['read', 'write'],
        ).save(flush: true)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题